PackageFinder   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 21
c 2
b 0
f 0
dl 0
loc 57
ccs 22
cts 22
cp 1
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A searchPackageFiles() 0 3 1
A getAllPackageFiles() 0 3 1
A getAllPackages() 0 7 2
A __construct() 0 14 4
1
<?php
2
3
namespace SSpkS\Package;
4
5
use \SSpkS\Package\Package;
0 ignored issues
show
Bug introduced by
The type \SSpkS\Package\Package was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
This use statement conflicts with another class in this namespace, SSpkS\Package\Package. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
7
/**
8
 * SPK PackageFinder class
9
 */
10
class PackageFinder
11
{
12
    private $config;
13
    private $fileGlob;
14
    private $baseFolder;
15
    private $fileList;
16
17
    /**
18
     * @param \SSpkS\Config $config Config object
19
     * @throws \Exception if $folder is not a folder.
20
     */
21 9
    public function __construct(\SSpkS\Config $config)
22
    {
23 9
        $this->config = $config;
24 9
        $folder = $this->config->paths['packages'];
25 9
        $glob = $this->config->packages['file_mask'];
26 9
        if (!file_exists($folder) || !is_dir($folder)) {
27 2
            throw new \Exception($folder . ' is not a folder!');
28
        }
29 7
        if (substr($folder, -1) != '/') {
30 2
            $folder .= '/';
31
        }
32 7
        $this->baseFolder = $folder;
33 7
        $this->fileGlob   = $glob;
34 7
        $this->searchPackageFiles();
35 7
    }
36
37
    /**
38
     * Searches the currently set folder with the set glob for package files.
39
     */
40 7
    private function searchPackageFiles()
41
    {
42 7
        $this->fileList = glob($this->baseFolder . $this->fileGlob);
43 7
    }
44
45
    /**
46
     * Returns all found package files.
47
     *
48
     * @return array List of package files.
49
     */
50 1
    public function getAllPackageFiles()
51
    {
52 1
        return $this->fileList;
53
    }
54
55
    /**
56
     * Returns all found packages as objects.
57
     *
58
     * @return \SSpkS\Package\Package[] List of packages as objects.
59
     */
60 6
    public function getAllPackages()
61
    {
62 6
        $packages = array();
63 6
        foreach ($this->fileList as $file) {
64 6
            $packages[] = new Package($this->config, $file);
65
        }
66 6
        return $packages;
67
    }
68
}
69