Conditions | 1 |
Paths | 1 |
Total Lines | 160 |
Code Lines | 107 |
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 |
||
57 | public function fileListQueryDataProvider() |
||
58 | { |
||
59 | return [ |
||
60 | // tests for filesystem item type |
||
61 | 'files' => [ |
||
62 | '$expectedItems' => [ |
||
63 | 'CONTRIBUTE', |
||
64 | 'LICENSE', |
||
65 | 'README', |
||
66 | 'src/Acme/Combinator.php', |
||
67 | 'src/Acme/Comparator.php', |
||
68 | 'src/Acme/config.yml', |
||
69 | 'test/Acme/AcmeTest.php', |
||
70 | 'test/Acme/data.dml', |
||
71 | ], |
||
72 | '$itemsProvider' => function () { |
||
73 | return Change\FullChangeSet::get()->files()->toArray(); |
||
74 | }, |
||
75 | ], |
||
76 | 'directories' => [ |
||
77 | '$expectedItems' => [ |
||
78 | 'src', |
||
79 | 'src/Acme', |
||
80 | 'test', |
||
81 | 'test/Acme', |
||
82 | ], |
||
83 | '$itemsProvider' => function () { |
||
84 | return Change\FullChangeSet::get()->directories()->toArray(); |
||
85 | }, |
||
86 | ], |
||
87 | |||
88 | // tests for file name / path patterns |
||
89 | 'php files' => [ |
||
90 | '$expectedItems' => [ |
||
91 | 'src/Acme/Combinator.php', |
||
92 | 'src/Acme/Comparator.php', |
||
93 | 'test/Acme/AcmeTest.php', |
||
94 | ], |
||
95 | '$itemsProvider' => function () { |
||
96 | return Change\FullChangeSet::get()->name('*.php')->toArray(); |
||
97 | }, |
||
98 | ], |
||
99 | 'all items in src (3 files + 1 dir)' => [ |
||
100 | '$expectedItems' => [ |
||
101 | 'src/Acme', |
||
102 | 'src/Acme/Combinator.php', |
||
103 | 'src/Acme/Comparator.php', |
||
104 | 'src/Acme/config.yml', |
||
105 | ], |
||
106 | '$itemsProvider' => function () { |
||
107 | return Change\FullChangeSet::get()->path('src/')->toArray(); |
||
108 | }, |
||
109 | ], |
||
110 | 'all items with Acme in their pathname' => [ |
||
111 | '$expectedItems' => [ |
||
112 | 'src/Acme', |
||
113 | 'test/Acme', |
||
114 | ], |
||
115 | '$itemsProvider' => function () { |
||
116 | return Change\FullChangeSet::get()->name('Acme')->toArray(); |
||
117 | }, |
||
118 | ], |
||
119 | 'all php files not in src/' => [ |
||
120 | '$expectedItems' => [ |
||
121 | 'test/Acme/AcmeTest.php', |
||
122 | ], |
||
123 | '$itemsProvider' => function () { |
||
124 | return Change\FullChangeSet::get()->notPath('src/')->name('*.php')->toArray(); |
||
125 | }, |
||
126 | ], |
||
127 | |||
128 | // tests for file contents |
||
129 | 'files containing "class"' => [ |
||
130 | '$expectedItems' => [ |
||
131 | 'src/Acme/Combinator.php', |
||
132 | 'src/Acme/Comparator.php', |
||
133 | 'test/Acme/AcmeTest.php', |
||
134 | ], |
||
135 | '$itemsProvider' => function () { |
||
136 | return Change\FullChangeSet::get()->contains('class')->toArray(); |
||
137 | }, |
||
138 | ], |
||
139 | 'base classes' => [ |
||
140 | '$expectedItems' => [ |
||
141 | 'src/Acme/Combinator.php', |
||
142 | 'src/Acme/Comparator.php', |
||
143 | ], |
||
144 | '$itemsProvider' => function () { |
||
145 | return Change\FullChangeSet::get() |
||
146 | ->name('*.php') |
||
147 | ->notContains('/extends\\s+([\\w_\\\\]+)\\s*\\{/') |
||
148 | ->toArray(); |
||
149 | }, |
||
150 | ], |
||
151 | 'phpunit test classes' => [ |
||
152 | '$expectedItems' => [ |
||
153 | 'test/Acme/AcmeTest.php', |
||
154 | ], |
||
155 | '$itemsProvider' => function () { |
||
156 | return Change\FullChangeSet::get() |
||
157 | ->name('*.php') |
||
158 | ->contains('/class\\s+([\\w_]+)\\s+extends\\s\\\\?PHPUnit_Framework_TestCase\\s*{/') |
||
159 | ->toArray(); |
||
160 | }, |
||
161 | ], |
||
162 | |||
163 | // tests for custom filter |
||
164 | 'filter for some files' => [ |
||
165 | '$expectedItems' => [ |
||
166 | 'CONTRIBUTE', |
||
167 | 'LICENSE', |
||
168 | 'README', |
||
169 | ], |
||
170 | '$itemsProvider' => function () { |
||
171 | return Change\FullChangeSet::get() |
||
172 | ->filter( |
||
173 | function (\SplFileInfo $file) { |
||
174 | return in_array($file->getFilename(), ['README', 'LICENSE', 'CONTRIBUTE']); |
||
175 | } |
||
176 | ) |
||
177 | ->toArray(); |
||
178 | }, |
||
179 | ], |
||
180 | |||
181 | // tests for path depth |
||
182 | 'top level files' => [ |
||
183 | '$expectedItems' => [ |
||
184 | 'CONTRIBUTE', |
||
185 | 'LICENSE', |
||
186 | 'README', |
||
187 | ], |
||
188 | '$itemsProvider' => function () { |
||
189 | return Change\FullChangeSet::get()->files()->depth('< 2')->toArray(); |
||
190 | }, |
||
191 | ], |
||
192 | 'top level directories' => [ |
||
193 | '$expectedItems' => [ |
||
194 | 'src', |
||
195 | 'src/Acme', |
||
196 | 'test', |
||
197 | 'test/Acme', |
||
198 | ], |
||
199 | '$itemsProvider' => function () { |
||
200 | return Change\FullChangeSet::get()->directories()->depth('< 2')->toArray(); |
||
201 | }, |
||
202 | ], |
||
203 | 'deep items' => [ |
||
204 | '$expectedItems' => [ |
||
205 | 'src/Acme/Combinator.php', |
||
206 | 'src/Acme/Comparator.php', |
||
207 | 'src/Acme/config.yml', |
||
208 | 'test/Acme/AcmeTest.php', |
||
209 | 'test/Acme/data.dml', |
||
210 | ], |
||
211 | '$itemsProvider' => function () { |
||
212 | return Change\FullChangeSet::get()->depth('> 1')->toArray(); |
||
213 | }, |
||
214 | ], |
||
215 | ]; |
||
216 | } |
||
217 | } |
||
218 |