Conditions | 10 |
Paths | 14 |
Total Lines | 35 |
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 |
||
29 | public function run($request) { |
||
30 | $buckets = Config::inst()->get('CloudAssets', 'map'); |
||
31 | $start = (int)$request->requestVar('start'); |
||
32 | $limit = (int)$request->requestVar('limit'); |
||
33 | $path = $request->requestVar('path'); |
||
34 | |||
35 | foreach ($buckets as $basePath => $cfg) { |
||
|
|||
36 | if (!empty($path) && $basePath != $path) continue; |
||
37 | echo "Processing $basePath...\n"; |
||
38 | $baseQuery = File::get()->filter('Filename:StartsWith', ltrim($basePath, '/')); |
||
39 | $total = $baseQuery->count(); |
||
40 | if ($start && !$limit) $limit = $total; |
||
41 | if ($limit) $baseQuery = $baseQuery->limit($limit, $start); |
||
42 | $query = $baseQuery->dataQuery()->query()->execute(); |
||
43 | foreach ($query as $i => $row) { |
||
44 | $class = $row['ClassName']; |
||
45 | $file = new $class($row); |
||
46 | echo ($i+$start) . "/$total: " . $file->Filename; |
||
47 | |||
48 | $this->processFile($file); |
||
49 | |||
50 | if ($file instanceof CloudImage) { |
||
51 | foreach ($file->DerivedImages() as $thumbStore) { |
||
52 | $thumb = $thumbStore->getCloudImageCached(); |
||
53 | echo "\n DERIVED: " . $thumb->Filename; |
||
54 | $this->processFile($thumb); |
||
55 | } |
||
56 | } |
||
57 | |||
58 | echo "\n"; |
||
59 | } |
||
60 | } |
||
61 | |||
62 | echo "done\n\n"; |
||
63 | } |
||
64 | |||
120 | } |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.