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