PhpCsFixer::getVersion()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * PHP-CS-Fixer plugin for HiDev
4
 *
5
 * @link      https://github.com/hiqdev/hidev-php-cs-fixer
6
 * @package   hidev-php-cs-fixer
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hidev\phpcsfixer\components;
12
13
/**
14
 * php-cs-fixer.
15
 */
16
class PhpCsFixer extends \hidev\base\Component
17
{
18
    protected $_version;
19
20
    public function getConfiguration()
21
    {
22
        return $this->take('.php_cs');
23
    }
24
25
    public function setVersion($value)
26
    {
27
        $this->_version = $value;
28
    }
29
30
    public function getVersion()
31
    {
32
        if ($this->_version === null) {
33
            $this->_version = $this->determineVersion();
34
        }
35
36
        return $this->_version;
37
    }
38
39
    public function determineVersion()
40
    {
41
        $str = reset($this->exec('php-cs-fixer', ['--version']));
0 ignored issues
show
Bug introduced by
$this->exec('php-cs-fixer', array('--version')) cannot be passed to reset() as the parameter $array expects a reference.
Loading history...
42
        if (preg_match('/PHP CS Fixer (\S+) /', $str, $matches)) {
43
            return $matches[1];
44
        }
45
46
        return '1.x';
47
    }
48
}
49