Conditions | 12 |
Paths | 6 |
Total Lines | 47 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
42 | public function refactor(Node $node): ?Node |
||
43 | { |
||
44 | Assert::isInstanceOf($node, New_::class); |
||
45 | |||
46 | if (!$node->class === null) { |
||
47 | return null; |
||
48 | } |
||
49 | |||
50 | |||
51 | if (!$node->class instanceof Name) { |
||
52 | return null; |
||
53 | } |
||
54 | |||
55 | |||
56 | if ($node->class->parts !== ['DaveLiddament', 'StaticAnalysisResultsBaseliner', 'Domain', 'Common', 'ProjectRoot']) |
||
57 | { |
||
58 | return null; |
||
59 | } |
||
60 | |||
61 | $args = $node->args; |
||
62 | |||
63 | if ( |
||
64 | ($args[0]->value instanceof Node\Scalar\String_) && |
||
65 | ($args[1]->value instanceof Node\Scalar\String_) && |
||
66 | ($args[0]->value->value === $args[1]->value->value) |
||
67 | ) { |
||
68 | |||
69 | return new StaticCall(new Name\FullyQualified(ProjectRoot::class), 'fromCurrentWorkingDirectory', [$args[0]]); |
||
70 | } |
||
71 | |||
72 | |||
73 | |||
74 | if ( |
||
75 | ($args[0]->value instanceof Node\Expr\ClassConstFetch) && |
||
76 | ($args[1]->value instanceof Node\Expr\ClassConstFetch) && |
||
77 | ($args[0]->value->name instanceof Node\Identifier) && |
||
78 | ($args[1]->value->name instanceof Node\Identifier) && |
||
79 | ($args[0]->value->name->name === $args[1]->value->name->name) |
||
80 | |||
81 | ) { |
||
82 | |||
83 | return new StaticCall(new Name\FullyQualified(ProjectRoot::class), 'fromCurrentWorkingDirectory', [$args[0]]); |
||
84 | } |
||
85 | |||
86 | |||
87 | |||
88 | return new StaticCall(new Name\FullyQualified(ProjectRoot::class), 'fromProjectRoot', $args); |
||
89 | |||
92 |