| Conditions | 12 |
| Paths | 44 |
| Total Lines | 61 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 23 | public function fileDataProvider() |
||
| 24 | { |
||
| 25 | $caseDir = realpath($this->getDataDirectory()); |
||
| 26 | $caseNames = $this->getCaseFileNames(); |
||
| 27 | $caseExt = $caseNames ? '.json' : ''; |
||
| 28 | $caseNames = $caseNames ?: array_diff(scandir($caseDir), ['..', '.']);; |
||
| 29 | $tests = []; |
||
| 30 | |||
| 31 | foreach ($caseNames as $caseName) { |
||
| 32 | $caseFile = "{$caseDir}/{$caseName}{$caseExt}"; |
||
| 33 | $case = $this->loadJsonFromFile($caseFile); |
||
| 34 | |||
| 35 | foreach ($case->tests as $test) { |
||
| 36 | if (!isset($test->valid) && !isset($test->invalid)) { |
||
| 37 | throw new \Exception(sprintf( |
||
| 38 | 'Test case "%s %s" has neither "valid" or "invalid" data (file: %s)', |
||
| 39 | $case->title, |
||
| 40 | $test->title, |
||
| 41 | $caseFile |
||
| 42 | )); |
||
| 43 | } |
||
| 44 | |||
| 45 | if (isset($test->valid)) { |
||
| 46 | foreach ($test->valid as $i => $instance) { |
||
| 47 | $tests[] = [ |
||
| 48 | $caseFile, |
||
| 49 | "{$case->title} {$test->title}, valid instance #{$i}", |
||
| 50 | $instance, |
||
| 51 | $test->schema, |
||
| 52 | true, |
||
| 53 | [], |
||
| 54 | ]; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | if (isset($test->invalid)) { |
||
| 59 | foreach ($test->invalid as $i => $set) { |
||
| 60 | if (!isset($set->violations)) { |
||
| 61 | throw new \Exception(sprintf( |
||
| 62 | 'Invalid test must have a "violations" property in %s', |
||
| 63 | $caseFile |
||
| 64 | )); |
||
| 65 | } |
||
| 66 | |||
| 67 | $tests[] = [ |
||
| 68 | $caseFile, |
||
| 69 | "{$case->title} {$test->title}, invalid instance #{$i}", |
||
| 70 | $set->instance, |
||
| 71 | $test->schema, |
||
| 72 | false, |
||
| 73 | array_map(function ($violation) { |
||
| 74 | return (array) $violation; |
||
| 75 | }, $set->violations), |
||
| 76 | ]; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | return $tests; |
||
| 83 | } |
||
| 84 | |||
| 101 |