Issues (35)

src/Api/FilesSimilarToMe.php (2 issues)

1
<?php
2
3
namespace Sunnysideup\AssetsOverview\Api;
4
5
class FilesSimilarToMe
6
{
7
    public $filesAsArrayList;
8
9
    protected function workOutSimilarity()
10
    {
11
        set_time_limit(240);
12
        $engine = new CompareImages();
13
        $this->setFilesAsArrayList();
0 ignored issues
show
The method setFilesAsArrayList() does not exist on Sunnysideup\AssetsOverview\Api\FilesSimilarToMe. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

13
        $this->/** @scrutinizer ignore-call */ 
14
               setFilesAsArrayList();

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.

Loading history...
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');
0 ignored issues
show
The method setFilesAsSortedArrayList() does not exist on Sunnysideup\AssetsOverview\Api\FilesSimilarToMe. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
        $this->/** @scrutinizer ignore-call */ 
69
               setFilesAsSortedArrayList('MostSimilarTo', 'MostSimilarTo');

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.

Loading history...
69
    }
70
}
71