Conditions | 12 |
Paths | 38 |
Total Lines | 56 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
53 | public function performAction() |
||
54 | { |
||
55 | $originalJson = file_get_contents($this->originalPath); |
||
56 | if (!$originalJson) { |
||
57 | $this->response->error('Unable to read ' . $this->originalPath); |
||
58 | return; |
||
59 | } |
||
60 | |||
61 | $newJson = file_get_contents($this->newPath); |
||
62 | if (!$newJson) { |
||
63 | $this->response->error('Unable to read ' . $this->newPath); |
||
64 | return; |
||
65 | } |
||
66 | |||
67 | $p = new JsonDiff(json_decode($originalJson), json_decode($newJson)); |
||
68 | |||
69 | $out = ''; |
||
70 | $paths = false; |
||
71 | |||
72 | switch ($this->action) { |
||
73 | case self::ACTION_REARRANGE: |
||
74 | $out = $p->getRearranged(); |
||
75 | break; |
||
76 | case self::ACTION_REMOVALS: |
||
77 | $out = $p->getRemoved(); |
||
78 | $paths = $p->getRemovedPaths(); |
||
79 | break; |
||
80 | case self::ACTION_ADDITIONS: |
||
81 | $out = $p->getAdded(); |
||
82 | $paths = $p->getAddedPaths(); |
||
83 | break; |
||
84 | case self::ACTION_MODIFICATIONS: |
||
85 | $out = array('modifiedOriginal' => $p->getModifiedOriginal(), 'modifiedNew' => $p->getModifiedNew()); |
||
86 | $paths = $p->getModifiedPaths(); |
||
87 | break; |
||
88 | case self::ACTION_CHANGES: |
||
89 | $out = array( |
||
90 | 'removals' => $p->getRemoved(), |
||
91 | 'additions' => $p->getAdded(), |
||
92 | 'modifiedOriginal' => $p->getModifiedOriginal(), |
||
93 | 'modifiedNew' => $p->getModifiedNew() |
||
94 | ); |
||
95 | $paths = array_merge($p->getRemovedPaths(), $p->getAddedPaths(), $p->getModifiedPaths()); |
||
96 | break; |
||
97 | } |
||
98 | |||
99 | if ($paths && $this->showPaths) { |
||
100 | echo implode("\n", $paths), "\n"; |
||
101 | } |
||
102 | |||
103 | $outJson = json_encode($out, JSON_PRETTY_PRINT + JSON_UNESCAPED_SLASHES); |
||
104 | if ($this->out) { |
||
105 | file_put_contents($this->out, $outJson); |
||
106 | } else { |
||
107 | if ($this->showJson) { |
||
108 | echo $outJson, "\n"; |
||
109 | } |
||
112 | } |