-
-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathConditionAndResult.php
More file actions
64 lines (50 loc) · 1.36 KB
/
ConditionAndResult.php
File metadata and controls
64 lines (50 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
namespace Rector\CodingStyle\ValueObject;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\Variable;
use Webmozart\Assert\Assert;
final readonly class ConditionAndResult
{
public function __construct(
private Expr $conditionExpr,
private Expr $resultExpr
) {
}
public function getConditionExpr(): Expr
{
return $this->conditionExpr;
}
public function isIdenticalCompare(): bool
{
return $this->conditionExpr instanceof Identical;
}
public function getIdenticalVariableName(): ?string
{
$identical = $this->getConditionIdentical();
if (! $identical->left instanceof Variable) {
return null;
}
$variable = $identical->left;
if ($variable->name instanceof Expr) {
return null;
}
return $variable->name;
}
public function getResultExpr(): Expr
{
return $this->resultExpr;
}
public function getIdenticalExpr(): Expr
{
/** @var Identical $identical */
$identical = $this->conditionExpr;
return $identical->right;
}
private function getConditionIdentical(): Identical
{
Assert::isInstanceOf($this->conditionExpr, Identical::class);
return $this->conditionExpr;
}
}