AddonVersion   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 2
dl 0
loc 123
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A DisplayVersion() 0 4 1
A DisplayRequireVersion() 0 4 1
A DisplayHomepage() 0 12 2
A getRequires() 0 4 1
A getRequiresDev() 0 4 1
A getSuggests() 0 4 1
A getProvides() 0 4 1
A getConflicts() 0 4 1
A getReplaces() 0 4 1
A InstallLink() 0 4 1
A onBeforeDelete() 0 13 2
1
<?php
2
/**
3
 * A version of an add-on package.
4
 */
5
class AddonVersion extends DataObject
6
{
7
8
    public static $db = array(
9
        'Name' => 'Varchar(255)',
10
        'Description' => 'Text',
11
        'Type' => 'Varchar(100)',
12
        'Released' => 'SS_Datetime',
13
        'Extra' => 'MultiValueField',
14
        'Homepage' => 'Varchar(255)',
15
        'Version' => 'Varchar(100)',
16
        'PrettyVersion' => 'Varchar(100)',
17
        'Development' => 'Boolean',
18
        'License' => 'MultiValueField',
19
        'SourceType' => 'Varchar(100)',
20
        'SourceUrl' => 'Varchar(255)',
21
        'SourceReference' => 'Varchar(40)',
22
        'DistType' => 'Varchar(100)',
23
        'DistUrl' => 'Varchar(255)',
24
        'DistReference' => 'Varchar(100)',
25
        'DistChecksum' => 'Varchar(40)',
26
        'Dist' => 'MultiValueField',
27
        'Support' => 'MultiValueField'
28
    );
29
30
    public static $has_one = array(
31
        'Addon' => 'Addon'
32
    );
33
34
    public static $has_many = array(
35
        'Links' => 'AddonLink'
36
    );
37
38
    public static $many_many = array(
39
        'Authors' => 'AddonAuthor',
40
        'Keywords' => 'AddonKeyword',
41
        'CompatibleVersions' => 'SilverStripeVersion'
42
    );
43
44
    public static $default_sort = array(
45
        'ID' => 'DESC'
46
    );
47
48
    private static $summary_fields = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
49
        'PrettyVersion' => 'Version',
50
        'Description' => 'Description'
51
    );
52
53
    public function DisplayVersion()
54
    {
55
        return $this->PrettyVersion;
0 ignored issues
show
Documentation introduced by
The property PrettyVersion does not exist on object<AddonVersion>. 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...
56
    }
57
58
    public function DisplayRequireVersion()
59
    {
60
        return str_replace('.x-dev', '.*@dev', $this->DisplayVersion());
61
    }
62
63
    /**
64
     * Fallback to SourceUrl with normalized github links.
65
     */
66
    public function DisplayHomepage()
67
    {
68
        if ($this->Homepage) {
0 ignored issues
show
Documentation introduced by
The property Homepage does not exist on object<AddonVersion>. 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...
69
            return $this->Homepage;
0 ignored issues
show
Documentation introduced by
The property Homepage does not exist on object<AddonVersion>. 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...
70
        } else {
71
            return str_replace(
72
                array('git://github.com', '[email protected]'),
73
                'https://github.com',
74
                $this->SourceUrl
0 ignored issues
show
Documentation introduced by
The property SourceUrl does not exist on object<AddonVersion>. 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...
75
            );
76
        }
77
    }
78
79
    public function getRequires()
80
    {
81
        return $this->Links()->filter('Type', 'require');
0 ignored issues
show
Documentation Bug introduced by
The method Links does not exist on object<AddonVersion>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
82
    }
83
84
    public function getRequiresDev()
85
    {
86
        return $this->Links()->filter('Type', 'require-dev');
0 ignored issues
show
Documentation Bug introduced by
The method Links does not exist on object<AddonVersion>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
87
    }
88
89
    public function getSuggests()
90
    {
91
        return $this->Links()->filter('Type', 'suggest');
0 ignored issues
show
Documentation Bug introduced by
The method Links does not exist on object<AddonVersion>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
92
    }
93
94
    public function getProvides()
95
    {
96
        return $this->Links()->filter('Type', 'provide');
0 ignored issues
show
Documentation Bug introduced by
The method Links does not exist on object<AddonVersion>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
97
    }
98
99
    public function getConflicts()
100
    {
101
        return $this->Links()->filter('Type', 'conflict');
0 ignored issues
show
Documentation Bug introduced by
The method Links does not exist on object<AddonVersion>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
102
    }
103
104
    public function getReplaces()
105
    {
106
        return $this->Links()->filter('Type', 'replace');
0 ignored issues
show
Documentation Bug introduced by
The method Links does not exist on object<AddonVersion>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
107
    }
108
109
    public function InstallLink()
110
    {
111
        return Controller::join_links($this->Addon()->Link(), 'install', $this->ID);
0 ignored issues
show
Documentation Bug introduced by
The method Addon does not exist on object<AddonVersion>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
112
    }
113
114
    public function onBeforeDelete()
115
    {
116
        parent::onBeforeDelete();
117
118
        // Remove our relations but leave the related objects for objects
119
        // that may be used by other objects.
120
        foreach ($this->Links() as $link) {
0 ignored issues
show
Documentation Bug introduced by
The method Links does not exist on object<AddonVersion>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
121
            $link->delete();
122
        }
123
        $this->Authors()->removeAll();
0 ignored issues
show
Documentation Bug introduced by
The method Authors does not exist on object<AddonVersion>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
124
        $this->Keywords()->removeAll();
0 ignored issues
show
Documentation Bug introduced by
The method Keywords does not exist on object<AddonVersion>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
125
        $this->CompatibleVersions()->removeAll();
0 ignored issues
show
Documentation Bug introduced by
The method CompatibleVersions does not exist on object<AddonVersion>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
126
    }
127
}
128