Conditions | 1 |
Paths | 1 |
Total Lines | 70 |
Code Lines | 46 |
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 |
||
67 | public function dataSkipCollectOnMatchIgnoreReferences(): iterable |
||
68 | { |
||
69 | $httpStreamBefore = function (string $url) { |
||
70 | }; |
||
71 | $httpStreamOperation = 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 (string $url, array $collected) { |
||
90 | $this->assertArrayHasKey('read', $collected); |
||
91 | $this->assertIsArray($collected['read']); |
||
92 | $this->assertCount(1, $collected['read']); |
||
93 | |||
94 | $readItem = $collected['read'][0]; |
||
95 | $this->assertSame($url, $readItem['uri']); |
||
96 | $this->assertArrayHasKey('args', $readItem); |
||
97 | |||
98 | $readItemArgs = $readItem['args']; |
||
99 | $this->assertCount(3, $readItemArgs); |
||
100 | |||
101 | $this->assertSame('GET', $readItemArgs['method']); |
||
102 | $this->assertIsArray($readItemArgs['response_headers']); |
||
103 | $this->assertNotEmpty($readItemArgs['response_headers']); |
||
104 | $this->assertIsArray($readItemArgs['request_headers']); |
||
105 | $this->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 |