Completed
Push — master ( 152da3...9039c2 )
by Andrii
03:32
created

PackageController::getVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\controllers;
13
14
use hidev\helpers\Helper;
15
16
/**
17
 * Package part of the config.
18
 */
19
class PackageController extends CommonController
20
{
21
    use \hiqdev\yii2\collection\ObjectTrait;
22
23
    public function getYears()
24
    {
25
        $cur = (integer) date('Y');
26
        $old = (integer) $this->year;
0 ignored issues
show
Documentation introduced by
The property year does not exist on object<hidev\controllers\PackageController>. 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...
27
28
        return ($old && $old < $cur ? $this->year . '-' : '') . $cur;
0 ignored issues
show
Documentation introduced by
The property year does not exist on object<hidev\controllers\PackageController>. 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...
29
    }
30
31
    public function getYear()
32
    {
33
        return $this->getItem('year') ?: $this->takeVcs()->getYear();
34
    }
35
36
    public function getLicense()
37
    {
38
        return $this->getItem('license') ?: $this->takeVendor()->license ?: 'No license';
39
    }
40
41
    public function getIssues()
42
    {
43
        return $this->getItem('issues') ?: ($this->source . '/issues');
0 ignored issues
show
Documentation introduced by
The property source does not exist on object<hidev\controllers\PackageController>. 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...
44
    }
45
46
    public function getWiki()
47
    {
48
        return $this->getItem('wiki') ?: ($this->source . '/wiki');
0 ignored issues
show
Documentation introduced by
The property source does not exist on object<hidev\controllers\PackageController>. 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...
49
    }
50
51
    public function getKeywords()
52
    {
53
        return Helper::csplit($this->getItem('keywords'));
54
    }
55
56
    public function getFullName()
57
    {
58
        return $this->getItem('fullName') ?: ($this->takeVendor()->name . '/' . $this->name);
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<hidev\controllers\PackageController>. 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...
59
    }
60
61
    public function getSource()
62
    {
63
        return $this->getItem('source') ?: ('https://github.com/' . $this->takeGoal('github')->name);
64
    }
65
66
    public function getVersion()
67
    {
68
        return $this->takeGoal('version')->version;
69
    }
70
71
    public function getNamespace()
72
    {
73
        return $this->getItem('namespace') ?: $this->getPackageManager()->namespace ?: self::defaultNamespace($this->takeVendor()->name, $this->name);
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<hidev\controllers\PackageController>. 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...
74
    }
75
76
    public static function defaultNamespace($vendor, $package)
77
    {
78
        return preg_replace('/[^a-zA-Z0-9\\\\]+/', '', $vendor . strtr("-$package", '-', '\\'));
79
    }
80
81
    public function getSrc()
82
    {
83
        $src = $this->rawItem('src');
84
85
        return isset($src) ? $src : 'src';
86
    }
87
88
    public function getHomepage()
89
    {
90
        return $this->getItem('homepage') ?: $this->getSource();
91
    }
92
93
    public function getForum()
94
    {
95
        return $this->getItem('forum') ?: $this->takeVendor()->forum;
96
    }
97
98
    public function getLabel()
99
    {
100
        return $this->getItem('label') ?: $this->getHeadline() ?: Helper::id2camel($this->name);
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<hidev\controllers\PackageController>. 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...
101
    }
102
103
    public function getTitle()
104
    {
105
        return $this->getItem('title') ?: Helper::titleize($this->name);
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<hidev\controllers\PackageController>. 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...
106
    }
107
108
    public function getHeadline()
109
    {
110
        return $this->getItem('headline');
111
    }
112
113
    public function getDescription()
114
    {
115
        return $this->getItem('description');
116
    }
117
118
    public function getRepositoryUrl($file)
119
    {
120
        return 'https://github.com/' . $this->getFullName() . '/blob/master/' . $file;
121
    }
122
    public function getAuthors()
123
    {
124
        return $this->getItem('authors') ?: $this->takeVendor()->authors;
125
    }
126
127
    /**
128
     * Composer for the moment.
129
     * To be changed to get actual Package Manager.
130
     */
131
    public function getPackageManager()
132
    {
133
        return $this->takeGoal('composer');
134
    }
135
136
    public function hasRequireAny($package)
137
    {
138
        return $this->hasRequire($package) || $this->hasRequireDev($package);
139
    }
140
141
    public function hasRequire($package)
142
    {
143
        $pman = $this->getPackageManager();
144
145
        return $pman && array_key_exists($package, $pman->getConfiguration()->getRequire());
146
    }
147
148
    public function hasRequireDev($package)
149
    {
150
        $pman = $this->getPackageManager();
151
152
        return $pman && array_key_exists($package, $pman->getConfiguration()->getRequireDev());
153
    }
154
}
155