Failed Conditions
Push — master ( c57d1c...658c98 )
by Steve
03:51
created

VersionController::getInfo()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 8.8571
cc 6
eloc 11
nc 4
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\Version;
16
17
use MageScan\Check\AbstractCheck;
18
use MageScan\Check\Version;
19
use Mvi\Check;
20
21
/**
22
 * Magento 2 has a controller that tells you the version
23
 *
24
 * @category  MageScan
25
 * @package   MageScan
26
 * @author    Steve Robbins <[email protected]>
27
 * @copyright 2015 Steve Robbins
28
 * @license   http://creativecommons.org/licenses/by/4.0/ CC BY 4.0
29
 * @link      https://github.com/steverobbins/magescan
30
 */
31
class VersionController extends AbstractCheck
32
{
33
    /**
34
     * Check for version controller
35
     *
36
     * @return array|boolean
37
     */
38
    public function getInfo()
39
    {
40
        $response = $this->getRequest()->get('magento_version');
41
        if ($response->getStatusCode() == 200) {
42
            preg_match("/Magento\/([0-9]\.[0-9\.]+) \(([a-zA-Z]+)\)/", $response->getBody(), $matches);
43
            if (isset($matches[1]) && isset($matches[2])) {
44
                $edition = $matches[2];
45
                $version = $matches[1];
46
                // An early versions of EE 2.0 would say it's 1.0
47
                if ($edition == 'Enterprise' && $version == '1.0') {
48
                    $version = '2.0';
49
                }
50
                return [$edition, $version];
51
            }
52
        }
53
        return false;
54
    }
55
}
56