Completed
Push — master ( 4d839d...7b168e )
by Andrii
02:18
created

PhpCsFixerController::actionStopFix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * PHP-CS-Fixer plugin for HiDev
5
 *
6
 * @link      https://github.com/hiqdev/hidev-php-cs-fixer
7
 * @package   hidev-php-cs-fixer
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\phpcsfixer\console;
13
14
/**
15
 * Goal to run php-cs-fixer.
16
 */
17
class PhpCsFixerController extends \hidev\controllers\FileController
18
{
19
    protected $_before = ['.php_cs'];
20
21
    protected $_version;
22
23
    public function setVersion($value)
24
    {
25
        $this->_version = $value;
26
    }
27
28
    public function getVersion()
29
    {
30
        if ($this->_version === null) {
31
            $this->_version = $this->determineVersion();
32
        }
33
34
        return $this->_version;
35
    }
36
37
    public function determineVersion()
38
    {
39
        $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...
Documentation introduced by
array('--version') is of type array<integer,string,{"0":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
40
        if (preg_match('/ version (\S+) /', $str, $m)) {
41
            return $m[1];
42
        }
43
44
        return '1.x';
45
    }
46
47
    public function getCasedLevel()
48
    {
49
        $level = strtolower($this->level);
0 ignored issues
show
Documentation introduced by
The property level does not exist on object<hidev\phpcsfixer\...e\PhpCsFixerController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
50
51
        return $level === 'symfony' ? 'Symfony' : strtoupper($level);
52
    }
53
54
    public function actionMake()
55
    {
56
        return $this->runAction('fix');
57
    }
58
59
    public function actionFix()
60
    {
61
        $this->runAction('stop-fix');
62
    }
63
64
    public function actionStopFix()
65
    {
66
        return $this->passthru('php-cs-fixer', ['fix', '.']);
67
    }
68
69
    public function actionCheck()
70
    {
71
        return $this->passthru('php-cs-fixer', ['fix', '.', '--dry-run']);
72
    }
73
}
74