We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 10 |
Paths | 16 |
Total Lines | 39 |
Code Lines | 22 |
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 |
||
70 | public function uploadRepeatableFiles($files, $previousRepeatableValues, $entry = null) |
||
71 | { |
||
72 | $fileOrder = $this->getFileOrderFromRequest(); |
||
73 | |||
74 | foreach ($files as $row => $files) { |
||
75 | foreach ($files ?? [] as $file) { |
||
76 | if ($file && is_file($file)) { |
||
77 | $fileName = $this->getFileName($file); |
||
78 | $file->storeAs($this->getPath(), $fileName, $this->getDisk()); |
||
79 | $fileOrder[$row][] = $this->getPath().$fileName; |
||
80 | } |
||
81 | } |
||
82 | } |
||
83 | // create a temporary variable that we can unset keys |
||
84 | // everytime one is found. That way we avoid iterating |
||
85 | // already handled keys (notice we do a deep array copy) |
||
86 | $tempFileOrder = array_map(function ($item) { |
||
87 | return $item; |
||
88 | }, $fileOrder); |
||
89 | |||
90 | foreach ($previousRepeatableValues as $previousRow => $previousFiles) { |
||
91 | foreach ($previousFiles ?? [] as $key => $file) { |
||
92 | $previousFileInArray = array_filter($tempFileOrder, function ($items, $key) use ($file, $tempFileOrder) { |
||
93 | $found = array_search($file, $items ?? [], true); |
||
94 | if ($found !== false) { |
||
95 | Arr::forget($tempFileOrder, $key.'.'.$found); |
||
96 | |||
97 | return true; |
||
98 | } |
||
99 | |||
100 | return false; |
||
101 | }, ARRAY_FILTER_USE_BOTH); |
||
102 | if ($file && ! $previousFileInArray) { |
||
103 | Storage::disk($this->getDisk())->delete($file); |
||
104 | } |
||
105 | } |
||
106 | } |
||
107 | |||
108 | return $fileOrder; |
||
109 | } |
||
128 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.