Test Failed
Push — php7 ( aecc74...44796e )
by Pascal
02:24
created

PackageFinder   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 95.45%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 21
c 2
b 0
f 0
dl 0
loc 57
ccs 21
cts 22
cp 0.9545
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;
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 6
    public function __construct(\SSpkS\Config $config)
22
    {
23 6
        $this->config = $config;
24 6
        $folder = $this->config->paths['packages'];
25 6
        $glob = $this->config->packages['file_mask'];
26 6
        if (!file_exists($folder) || !is_dir($folder)) {
27
            throw new \Exception($folder . ' is not a folder!');
28
        }
29 6
        if (substr($folder, -1) != '/') {
30 2
            $folder .= '/';
31
        }
32 6
        $this->baseFolder = $folder;
33 6
        $this->fileGlob   = $glob;
34 6
        $this->searchPackageFiles();
35 6
    }
36
37
    /**
38
     * Searches the currently set folder with the set glob for package files.
39
     */
40 6
    private function searchPackageFiles()
41
    {
42 6
        $this->fileList = glob($this->baseFolder . $this->fileGlob);
43 6
    }
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 5
    public function getAllPackages()
61
    {
62 5
        $packages = array();
63 5
        foreach ($this->fileList as $file) {
64 5
            $packages[] = new Package($this->config, $file);
65
        }
66 5
        return $packages;
67
    }
68
}
69