Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
8 / 8 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
VariableGenerationHelper | |
100.00% |
8 / 8 |
|
100.00% |
8 / 8 |
8 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
assignThisVarToVar | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
assignThisVarToThisVar | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
new | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
assignVarToVar | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
assign | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
var | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
thisVar | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace quintenmbusiness\PhpAstCodeGenerationHelper\GeneratorHelpers; |
6 | |
7 | use PhpParser\Node\Expr; |
8 | use PhpParser\Node\Name; |
9 | use PhpParser\BuilderFactory; |
10 | use PhpParser\Node\Expr\New_; |
11 | use PhpParser\Node\Expr\Assign; |
12 | use PhpParser\Node\Expr\Variable; |
13 | use PhpParser\Node\Expr\PropertyFetch; |
14 | |
15 | class VariableGenerationHelper extends BasicGenerationHelper |
16 | { |
17 | /** |
18 | * @param BuilderFactory $factory |
19 | */ |
20 | public function __construct(BuilderFactory $factory) |
21 | { |
22 | parent::__construct($factory); |
23 | } |
24 | |
25 | /** |
26 | * @param string $thisVar |
27 | * @param string $var |
28 | * @return Assign |
29 | */ |
30 | public function assignThisVarToVar(string $thisVar, string $var): Assign |
31 | { |
32 | return $this->assign($this->thisVar($thisVar), $this->var($var)); |
33 | } |
34 | |
35 | /** |
36 | * @param string $thisVarToBeAssigned |
37 | * @param string $thisVarToBeAssignedTo |
38 | * @return Assign |
39 | */ |
40 | public function assignThisVarToThisVar(string $thisVarToBeAssigned, string $thisVarToBeAssignedTo): Assign |
41 | { |
42 | return $this->assign($this->thisVar($thisVarToBeAssigned), $this->thisVar($thisVarToBeAssignedTo)); |
43 | } |
44 | |
45 | /** |
46 | * @param string $name |
47 | * @return New_ |
48 | */ |
49 | public function new(string $name): New_ |
50 | { |
51 | return new New_(new Name($name)); |
52 | } |
53 | |
54 | /** |
55 | * @param string $thisVar |
56 | * @param string $var |
57 | * @return Assign |
58 | */ |
59 | public function assignVarToVar(string $thisVar, string $var): Assign |
60 | { |
61 | return $this->assign($this->var($thisVar), $this->var($var)); |
62 | } |
63 | |
64 | /** |
65 | * @param Expr $target |
66 | * @param Expr $newValue |
67 | * @return Assign |
68 | */ |
69 | public function assign(Expr $target, Expr $newValue): Assign |
70 | { |
71 | return new Assign($target, $newValue); |
72 | } |
73 | |
74 | /** |
75 | * @param string $name |
76 | * @return Variable |
77 | */ |
78 | public function var(string $name): Variable |
79 | { |
80 | return new Variable($name); |
81 | } |
82 | |
83 | /** |
84 | * @param string $property |
85 | * @return PropertyFetch |
86 | */ |
87 | public function thisVar(string $property): PropertyFetch |
88 | { |
89 | return new PropertyFetch(new Variable('this'), $property); |
90 | } |
91 | } |