Conditions | 10 |
Paths | 6 |
Total Lines | 36 |
Code Lines | 21 |
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 |
||
75 | public function matchOnPath() |
||
76 | { |
||
77 | if (!\is_string($this->operand) || !$this->jsonText->isValidJson($this->operand)) { |
||
78 | $msg = 'Invalid JSON passed as operand on RHS.'; |
||
79 | throw new JSONTextInvalidArgsException($msg); |
||
80 | } |
||
81 | |||
82 | $operandAsArray = $this->jsonText->toArray($this->operand); |
||
83 | |||
84 | if (!\count($operandAsArray)) { |
||
85 | return []; |
||
86 | } |
||
87 | |||
88 | $keys = \array_keys($operandAsArray); |
||
89 | $vals = \array_values($operandAsArray); |
||
90 | |||
91 | if (\count($keys) > 1 || \count($vals) > 1) { |
||
92 | $msg = 'Sorry. I can\'t handle complex operands.'; |
||
93 | throw new JSONTextInvalidArgsException($msg); |
||
94 | } |
||
95 | |||
96 | $source = $this->jsonText->getStoreAsArray(); |
||
97 | $sourceAsIterator = new \RecursiveIteratorIterator( |
||
98 | new \RecursiveArrayIterator($source), |
||
99 | \RecursiveIteratorIterator::SELF_FIRST |
||
100 | ); |
||
101 | |||
102 | $data = []; |
||
103 | foreach ($sourceAsIterator as $sourceKey => $sourceVal) { |
||
104 | if ($keys[0] === $sourceKey && is_array($sourceVal) && !empty($sourceVal[$vals[0]])) { |
||
105 | $data[] = $sourceVal[$vals[0]]; |
||
106 | } |
||
107 | } |
||
108 | |||
109 | return $data; |
||
110 | } |
||
111 | |||
113 |
This check marks private properties in classes that are never used. Those properties can be removed.