File   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 48
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A getJson() 0 9 2
1
<?php
2
/**
3
 * Mage Scan
4
 *
5
 * PHP version 5
6
 *
7
 * @category  MageScan
8
 * @package   MageScan
9
 * @author    Steve Robbins <[email protected]>
10
 * @copyright 2015 Steve Robbins
11
 * @license   http://creativecommons.org/licenses/by/4.0/ CC BY 4.0
12
 * @link      https://github.com/steverobbins/magescan
13
 */
14
15
namespace MageScan;
16
17
/**
18
 * Access the file system
19
 *
20
 * @category  MageScan
21
 * @package   MageScan
22
 * @author    Steve Robbins <[email protected]>
23
 * @copyright 2015 Steve Robbins
24
 * @license   http://creativecommons.org/licenses/by/4.0/ CC BY 4.0
25
 * @link      https://github.com/steverobbins/magescan
26
 */
27
class File
28
{
29
    /**
30
     * Root directory of app
31
     *
32
     * @var string
33
     */
34
    private $root;
35
36
    /**
37
     * This file's locations
38
     *
39
     * @var array
40
     */
41
    private $paths = [];
42
43
    /**
44
     * Initialize the root dir and set the path
45
     *
46
     * @param string $filename
47
     */
48
    public function __construct($filename)
49
    {
50
        $this->root = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR;
51
        $this->paths[] = $this->root . 'src' . DIRECTORY_SEPARATOR . 'MageScan'
52
            . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $filename;
53
        $homePath = getenv('HOME') . DIRECTORY_SEPARATOR . '.magescan' . DIRECTORY_SEPARATOR
54
            . 'config' . DIRECTORY_SEPARATOR . $filename;
55
        if (file_exists($homePath)) {
56
            $this->paths[] = $homePath;
57
        }
58
    }
59
60
    /**
61
     * Returns the json file contents as an array
62
     *
63
     * @return array
64
     */
65
    public function getJson()
66
    {
67
        $return = [];
68
        foreach ($this->paths as $path) {
69
            $pathData = json_decode(file_get_contents($path), true);
70
            $return = array_merge($return, $pathData);
71
        }
72
        return $return;
73
    }
74
}
75