Module::checkForModules()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4222
c 0
b 0
f 0
cc 5
nc 3
nop 0
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\Check;
16
17
use MageScan\File;
18
19
/**
20
 * Check for installed modules
21
 *
22
 * @category  MageScan
23
 * @package   MageScan
24
 * @author    Steve Robbins <[email protected]>
25
 * @copyright 2015 Steve Robbins
26
 * @license   http://creativecommons.org/licenses/by/4.0/ CC BY 4.0
27
 * @link      https://github.com/steverobbins/magescan
28
 */
29
class Module extends AbstractCheck
30
{
31
32
    /**
33
     * Check for module files that exist in a url
34
     *
35
     * @return array
36
     */
37
    public function checkForModules()
38
    {
39
        $modules = [];
40
        $files = $this->getFiles();
41
        $responses = $this->getRequest()->headMany(array_keys($files));
42
        foreach ($responses as $path => $response) {
43
            $name = $files[$path];
44
            if ($response->getStatusCode() == 200 && (!isset($modules[$name]) || $modules[$name] === false)) {
45
                $modules[$name] = true;
46
            } else {
47
                $modules[$name] = false;
48
            }
49
        }
50
        ksort($modules);
51
        return $modules;
52
    }
53
54
    /**
55
     * Check for a module file that exist in a url
56
     *
57
     * @param string $file
58
     *
59
     * @return boolean
60
     */
61
    public function checkForModule($file)
62
    {
63
        $response = $this->getRequest()->head($file);
64
        return $response->getStatusCode() == 200;
65
    }
66
67
    /**
68
     * Get modules files as array
69
     *
70
     * @return array
71
     */
72
    public function getFiles()
73
    {
74
        $file = new File('module.json');
75
        return $file->getJson();
76
    }
77
}
78