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

TravisYamlController   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 12
c 4
b 0
f 0
lcom 1
cbo 1
dl 0
loc 73
ccs 0
cts 30
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getBin() 0 8 2
A detectBin() 0 11 3
A getBeforeInstall() 0 14 3
A actionSave() 0 22 3
A getTravis() 0 4 1
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
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
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