Completed
Push — master ( a5ecda...2f43c7 )
by Andrii
98:59 queued 41:11
created

TravisYamlController::getBeforeInstall()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 14
ccs 0
cts 7
cp 0
rs 9.4285
cc 3
eloc 9
nc 4
nop 0
crap 12
1
<?php
2
3
/*
4
 * Travis CI plugin for HiDev
5
 *
6
 * @link      https://github.com/hiqdev/hidev-travis
7
 * @package   hidev-travis
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\travis\controllers;
13
14
/**
15
 * Goal for .travis.yml config file.
16
 */
17
class TravisYamlController extends \hidev\controllers\FileController
18
{
19
    protected $_file = '.travis.yml';
20
21
    protected $_bin;
22
23
    public function getBin()
24
    {
25
        if ($this->_bin === null) {
26
            $this->_bin = $this->detectBin();
27
        }
28
29
        return $this->_bin;
30
    }
31
32
    public function detectBin()
33
    {
34
        if ($this->takePackage()->fullName === 'hiqdev/hidev') {
35
            return './bin/hidev';
36
        }
37
        if ($this->takePackage()->hasRequireAny('hiqdev/hidev')) {
38
            return './vendor/bin/hidev';
39
        }
40
41
        return './hidev.phar';
42
    }
43
44
    public function getBeforeInstall()
45
    {
46
        $commands = array_values(array_unique($this->get('before_install')));
47
        if ($this->bin === './hidev.phar') {
0 ignored issues
show
Documentation introduced by Andrii Vasyliev
The property bin does not exist on object<hidev\travis\cont...s\TravisYamlController>. 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...
48
            $commands[] = 'wget http://hiqdev.com/hidev/hidev.phar -O hidev.phar && chmod a+x hidev.phar';
49
        }
50
        if ($this->bin === './bin/hidev') {
0 ignored issues
show
Documentation introduced by Andrii Vasyliev
The property bin does not exist on object<hidev\travis\cont...s\TravisYamlController>. 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...
51
            $commands[] = 'travis_retry composer install --no-interaction';
52
        }
53
        $commands[] = $this->getBin() . ' --version';
54
        $commands[] = $this->getBin() . ' travis/before_install';
55
56
        return $commands;
57
    }
58
59
    /**
60
     * Reorders config elements.
61
     */
62
    public function actionSave()
63
    {
64
        $add_items = [
65
            'sudo'           => false,
66
            'before_install' => $this->getBeforeInstall(),
67
        ];
68
        foreach (['install', 'before_script', 'script', 'after_success', 'after_failure', 'after_script'] as $event) {
69
            if ($this->getTravis()->{$event}) {
70
                $add_items[$event] = [$this->getBin() . ' travis/' . $event];
71
            }
72
        }
73
        $this->setItems($add_items);
74
        $items = $this->_items;
75
        $lang = $items['language'];
76
        $lops = $items[$lang];
77
        unset($items['language'], $items[$lang]);
78
        $this->_items = [
79
            'language' => $lang,
80
            $lang      => $lops,
81
        ] + $items;
82
        return parent::actionSave();
83
    }
84
85
    public function getTravis()
86
    {
87
        return $this->takeGoal('travis');
88
    }
89
}
90