SilverStripeVersion   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 4 1
A getConstraintValidity() 0 7 2
1
<?php
2
3
use Composer\Semver\Constraint\ConstraintInterface;
4
use Composer\Semver\Semver;
5
6
/**
7
 * A SilverStripe version which an add-on can be compatible with.
8
 */
9
class SilverStripeVersion extends DataObject
10
{
11
    public static $db = array(
12
        'Name' => 'Varchar(10)',
13
        'Major' => 'Int',
14
        'Minor' => 'Int'
15
    );
16
17
    public static $default_sort = array(
18
        'Major' => 'DESC',
19
        'Minor' => 'DESC'
20
    );
21
22
    /**
23
     * Returns a generic version contraint for this version
24
     *
25
     * @return string
26
     */
27
    public function __toString()
28
    {
29
        return $this->Major . '.' . $this->Minor . '.0';
0 ignored issues
show
Documentation introduced by
The property Major does not exist on object<SilverStripeVersion>. 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...
Documentation introduced by
The property Minor does not exist on object<SilverStripeVersion>. 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
    /**
33
     * Check whether a given module's composer version constraint will apply to this version
34
     *
35
     * @param  string|ConstraintInterface $constraint
36
     * @return bool
37
     */
38
    public function getConstraintValidity($constraint)
39
    {
40
        if ($constraint instanceof ConstraintInterface) {
41
            $constraint = $constraint->getPrettyString();
42
        }
43
        return Semver::satisfies((string) $this, $constraint);
44
    }
45
}
46