Conditions | 11 |
Paths | 193 |
Total Lines | 39 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
59 | protected function doTest($case) |
||
60 | { |
||
61 | $case = clone $case; |
||
62 | |||
63 | if (isset($case->disabled) && $case->disabled) { |
||
64 | $this->markTestSkipped('test is disabled'); |
||
65 | return; |
||
66 | } |
||
67 | |||
68 | if (!is_object($case->doc)) { |
||
69 | $doc = $case->doc; |
||
70 | } else { |
||
71 | $doc = clone $case->doc; |
||
72 | } |
||
73 | $patch = $case->patch; |
||
74 | $hasExpected = array_key_exists('expected', (array)$case); |
||
75 | $expected = isset($case->expected) ? $case->expected : null; |
||
76 | $error = isset($case->error) ? $case->error : null; |
||
77 | $jsonOptions = JSON_UNESCAPED_SLASHES + JSON_PRETTY_PRINT; |
||
78 | |||
79 | try { |
||
80 | $patch = JsonPatch::import($patch); |
||
81 | $patch->apply($doc); |
||
82 | if ($error !== null) { |
||
83 | $this->fail('Error expected: ' . $error |
||
84 | . "\n" . json_encode($case, $jsonOptions)); |
||
85 | } |
||
86 | if ($hasExpected) { |
||
87 | $this->assertEquals($expected, $doc, json_encode($case, $jsonOptions) |
||
88 | . "\n" . json_encode($doc, $jsonOptions)); |
||
89 | } |
||
90 | } catch (Exception $e) { |
||
91 | if ($e->getCode() === Exception::EMPTY_PROPERTY_NAME_UNSUPPORTED) { |
||
92 | $this->markTestSkipped('Empty property name unsupported in PHP <7.1'); |
||
93 | } |
||
94 | |||
95 | if ($error === null) { |
||
96 | $this->fail($e->getMessage() |
||
97 | . "\n" . json_encode($case, $jsonOptions)); |
||
98 | } |
||
102 | } |