Completed
Push — master ( 826e4e...164599 )
by Andrii
02:35
created

GitHubGoal   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 11
c 2
b 1
f 1
lcom 1
cbo 1
dl 0
loc 40
ccs 0
cts 26
cp 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setName() 0 7 3
A getName() 0 4 2
A getPackage() 0 4 2
A getVendor() 0 4 2
A actionCreate() 0 3 1
A actionClone() 0 4 1
1
<?php
2
3
/*
4
 * Task runner, code generator and build tool for easier continuos integration
5
 *
6
 * @link      https://github.com/hiqdev/hidev
7
 * @package   hidev
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2014-2015, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\goals;
13
14
/**
15
 * Goal for GitHub.
16
 */
17
class GitHubGoal extends DefaultGoal
18
{
19
    public function setName($value)
20
    {
21
        list($vendor, $package) = explode('/', $value, 2);
22
        $this->setItem('name',    $value);
23
        $this->setItem('vendor',  $vendor ?: $package);
24
        $this->setItem('package', $package ?: $vendor);
25
    }
26
27
    public function getName()
28
    {
29
        return $this->getItem('name') ?: $this->config->package->fullName;
0 ignored issues
show
Documentation introduced by
The property config does not exist on object<hidev\goals\GitHubGoal>. 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...
30
    }
31
32
    public function getPackage()
33
    {
34
        return $this->getItem('package') ?: $this->config->package->name;
0 ignored issues
show
Documentation introduced by
The property config does not exist on object<hidev\goals\GitHubGoal>. 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...
35
    }
36
37
    public function getVendor()
38
    {
39
        return $this->getItem('vendor') ?: $this->config->vendor->name;
0 ignored issues
show
Documentation introduced by
The property config does not exist on object<hidev\goals\GitHubGoal>. 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...
40
    }
41
42
    public function actionCreate()
43
    {
44
    }
45
46
    /**
47
     * Clone repo from github.
48
     * TODO to work need to redo HiDev to run this action without normal initilization.
49
     * @param string $repo full name vendor/package
50
     * @return int exit code
51
     */
52
    public function actionClone($repo)
53
    {
54
        return $this->passthru('git', ['clone', '[email protected]:' . $repo]);
0 ignored issues
show
Documentation introduced by
array('clone', '[email protected]:' . $repo) is of type array<integer,string,{"0":"string","1":"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...
55
    }
56
}
57