Conditions | 18 |
Paths | 184 |
Total Lines | 60 |
Code Lines | 42 |
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 |
||
9 | protected function workOutSimilarity() |
||
10 | { |
||
11 | set_time_limit(240); |
||
12 | $engine = new CompareImages(); |
||
13 | $this->setFilesAsArrayList(); |
||
|
|||
14 | $a = clone $this->filesAsArrayList; |
||
15 | $b = clone $this->filesAsArrayList; |
||
16 | $c = clone $this->filesAsArrayList; |
||
17 | $alreadyDone = []; |
||
18 | foreach ($a as $file) { |
||
19 | $nameOne = $file->Path; |
||
20 | $nameOneFromAssets = $file->PathFromAssetsFolder; |
||
21 | if (! in_array($nameOne, $alreadyDone, true)) { |
||
22 | $easyFind = false; |
||
23 | $sortArray = []; |
||
24 | foreach ($b as $compareImage) { |
||
25 | $nameTwo = $compareImage->Path; |
||
26 | if ($nameOne !== $nameTwo) { |
||
27 | $fileNameTest = $file->FileName && $file->FileName === $compareImage->FileName; |
||
28 | $fileSizeTest = $file->FileSize > 0 && $file->FileSize === $compareImage->FileSize; |
||
29 | if ($fileNameTest || $fileSizeTest) { |
||
30 | $easyFind = true; |
||
31 | $alreadyDone[$nameOne] = $nameOneFromAssets; |
||
32 | $alreadyDone[$compareImage->Path] = $nameOneFromAssets; |
||
33 | } elseif (false === $easyFind && $file->IsImage) { |
||
34 | if ($file->ImageRatio === $compareImage->ImageRatio && $file->ImageRatio > 0) { |
||
35 | $score = $engine->compare($nameOne, $nameTwo); |
||
36 | $sortArray[$nameTwo] = $score; |
||
37 | |||
38 | break; |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 | } |
||
43 | |||
44 | if (false === $easyFind) { |
||
45 | if ([] !== $sortArray) { |
||
46 | asort($sortArray); |
||
47 | reset($sortArray); |
||
48 | $mostSimilarKey = key($sortArray); |
||
49 | foreach ($c as $findImage) { |
||
50 | if ($findImage->Path === $mostSimilarKey) { |
||
51 | $alreadyDone[$nameOne] = $nameOneFromAssets; |
||
52 | $alreadyDone[$findImage->Path] = $nameOneFromAssets; |
||
53 | |||
54 | break; |
||
55 | } |
||
56 | } |
||
57 | } else { |
||
58 | $alreadyDone[$file->Path] = '[N/A]'; |
||
59 | } |
||
60 | } |
||
61 | } |
||
62 | } |
||
63 | |||
64 | foreach ($this->filesAsArrayList as $file) { |
||
65 | $file->MostSimilarTo = $alreadyDone[$file->Path] ?? '[N/A]'; |
||
66 | } |
||
67 | |||
68 | $this->setFilesAsSortedArrayList('MostSimilarTo', 'MostSimilarTo'); |
||
69 | } |
||
71 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.