| Conditions | 1 |
| Paths | 1 |
| Total Lines | 70 |
| Code Lines | 46 |
| 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 |
||
| 67 | public static function dataSkipCollectOnMatchIgnoreReferences(): iterable |
||
| 68 | { |
||
| 69 | $httpStreamBefore = function (string $url) { |
||
| 70 | }; |
||
| 71 | $httpStreamOperation = static function (string $url) { |
||
| 72 | $stream = fopen($url, 'r'); |
||
| 73 | fread($stream, 4); |
||
| 74 | ftell($stream); |
||
| 75 | feof($stream); |
||
| 76 | fstat($stream); |
||
| 77 | fclose($stream); |
||
| 78 | }; |
||
| 79 | $httpStreamAfter = $httpStreamBefore; |
||
| 80 | |||
| 81 | yield 'file stream matched' => [ |
||
| 82 | $url = 'http://example.com', |
||
| 83 | $httpStreamBefore, |
||
| 84 | [], |
||
| 85 | [], |
||
| 86 | [], |
||
| 87 | $httpStreamOperation, |
||
| 88 | $httpStreamAfter, |
||
| 89 | function (TestCase $testCase, string $url, array $collected) { |
||
| 90 | $testCase->assertArrayHasKey('read', $collected); |
||
| 91 | $testCase->assertIsArray($collected['read']); |
||
| 92 | $testCase->assertCount(1, $collected['read']); |
||
| 93 | |||
| 94 | $readItem = $collected['read'][0]; |
||
| 95 | $testCase->assertSame($url, $readItem['uri']); |
||
| 96 | $testCase->assertArrayHasKey('args', $readItem); |
||
| 97 | |||
| 98 | $readItemArgs = $readItem['args']; |
||
| 99 | $testCase->assertCount(3, $readItemArgs); |
||
| 100 | |||
| 101 | $testCase->assertSame('GET', $readItemArgs['method']); |
||
| 102 | $testCase->assertIsArray($readItemArgs['response_headers']); |
||
| 103 | $testCase->assertNotEmpty($readItemArgs['response_headers']); |
||
| 104 | $testCase->assertIsArray($readItemArgs['request_headers']); |
||
| 105 | $testCase->assertEmpty($readItemArgs['request_headers']); |
||
| 106 | }, |
||
| 107 | ]; |
||
| 108 | yield 'file stream ignored by path' => [ |
||
| 109 | $url, |
||
| 110 | $httpStreamBefore, |
||
| 111 | [basename(__FILE__, '.php')], |
||
| 112 | [], |
||
| 113 | [], |
||
| 114 | $httpStreamOperation, |
||
| 115 | $httpStreamAfter, |
||
| 116 | [], |
||
| 117 | ]; |
||
| 118 | yield 'file stream ignored by class' => [ |
||
| 119 | $url, |
||
| 120 | $httpStreamBefore, |
||
| 121 | [], |
||
| 122 | [self::class], |
||
| 123 | [], |
||
| 124 | $httpStreamOperation, |
||
| 125 | $httpStreamAfter, |
||
| 126 | [], |
||
| 127 | ]; |
||
| 128 | yield 'file stream ignored by url' => [ |
||
| 129 | $url, |
||
| 130 | $httpStreamBefore, |
||
| 131 | [], |
||
| 132 | [], |
||
| 133 | ['example'], |
||
| 134 | $httpStreamOperation, |
||
| 135 | $httpStreamAfter, |
||
| 136 | [], |
||
| 137 | ]; |
||
| 165 |