Completed
Push — feature/ss4-upgrade ( f41a3f )
by
unknown
10:12
created

AddonVersion   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

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
namespace SilverStripe\Addons\Model;
4
5
use SilverStripe\ORM\DataObject;
6
use SilverStripe\Control\Controller;
7
8
/**
9
 * A version of an add-on package.
10
 */
11
class AddonVersion extends DataObject 
12
{
13
14
	private static $db = [
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...
15
		'Name' => 'Varchar(255)',
16
		'Description' => 'Text',
17
		'Type' => 'Varchar(100)',
18
		'Released' => 'SS_Datetime',
19
		'Extra' => 'MultiValueField',
20
		'Homepage' => 'Varchar(255)',
21
		'Version' => 'Varchar(100)',
22
		'PrettyVersion' => 'Varchar(100)',
23
		'Development' => 'Boolean',
24
		'License' => 'MultiValueField',
25
		'SourceType' => 'Varchar(100)',
26
		'SourceUrl' => 'Varchar(255)',
27
		'SourceReference' => 'Varchar(40)',
28
		'DistType' => 'Varchar(100)',
29
		'DistUrl' => 'Varchar(255)',
30
		'DistReference' => 'Varchar(100)',
31
		'DistChecksum' => 'Varchar(40)',
32
		'Dist' => 'MultiValueField',
33
		'Support' => 'MultiValueField'
34
	];
35
36
	private static $has_one = [
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...
37
		'Addon' => 'SilverStripe\Addons\Model\Addon'
38
	];
39
40
	private static $has_many = [
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...
41
		'Links' => 'SilverStripe\Addons\Model\AddonLink'
42
	];
43
44
	private static $many_many = [
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...
45
		'Authors' => 'SilverStripe\Addons\Model\AddonAuthor',
46
		'Keywords' => 'SilverStripe\Addons\Model\AddonKeyword',
47
		'CompatibleVersions' => 'SilverStripe\Addons\Model\SilverStripeVersion'
48
	];
49
50
	private static $default_sort = 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...
51
		'ID' => 'DESC'
52
	);
53
54
	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...
55
		'PrettyVersion' => 'Version',
56
		'Description' => 'Description'
57
	);
58
59
	public function DisplayVersion() 
60
	{
61
		return $this->PrettyVersion;
0 ignored issues
show
Documentation introduced by
The property PrettyVersion does not exist on object<SilverStripe\Addons\Model\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...
62
	}
63
64
	public function DisplayRequireVersion() 
65
	{
66
		return str_replace('.x-dev', '.*@dev', $this->DisplayVersion());
67
	}
68
69
	/**
70
	 * Fallback to SourceUrl with normalized github links.
71
	 */
72
	public function DisplayHomepage() 
73
	{
74
		if($this->Homepage) {
0 ignored issues
show
Documentation introduced by
The property Homepage does not exist on object<SilverStripe\Addons\Model\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
			return $this->Homepage;
0 ignored issues
show
Documentation introduced by
The property Homepage does not exist on object<SilverStripe\Addons\Model\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...
76
		} else {
77
			return str_replace(
78
				array('git://github.com', '[email protected]'),
79
				'https://github.com',
80
				$this->SourceUrl
0 ignored issues
show
Documentation introduced by
The property SourceUrl does not exist on object<SilverStripe\Addons\Model\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...
81
			);
82
		}
83
	}
84
85
	public function getRequires() 
86
	{
87
		return $this->Links()->filter('Type', 'require');
0 ignored issues
show
Documentation Bug introduced by
The method Links does not exist on object<SilverStripe\Addons\Model\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...
88
	}
89
90
	public function getRequiresDev() 
91
	{
92
		return $this->Links()->filter('Type', 'require-dev');
0 ignored issues
show
Documentation Bug introduced by
The method Links does not exist on object<SilverStripe\Addons\Model\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...
93
	}
94
95
	public function getSuggests() 
96
	{
97
		return $this->Links()->filter('Type', 'suggest');
0 ignored issues
show
Documentation Bug introduced by
The method Links does not exist on object<SilverStripe\Addons\Model\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...
98
	}
99
100
	public function getProvides() 
101
	{
102
		return $this->Links()->filter('Type', 'provide');
0 ignored issues
show
Documentation Bug introduced by
The method Links does not exist on object<SilverStripe\Addons\Model\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...
103
	}
104
105
	public function getConflicts() 
106
	{
107
		return $this->Links()->filter('Type', 'conflict');
0 ignored issues
show
Documentation Bug introduced by
The method Links does not exist on object<SilverStripe\Addons\Model\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...
108
	}
109
110
	public function getReplaces() 
111
	{
112
		return $this->Links()->filter('Type', 'replace');
0 ignored issues
show
Documentation Bug introduced by
The method Links does not exist on object<SilverStripe\Addons\Model\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...
113
	}
114
115
	public function InstallLink() 
116
	{
117
		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<SilverStripe\Addons\Model\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...
118
	}
119
120
	public function onBeforeDelete() 
121
	{
122
		parent::onBeforeDelete();
123
124
		// Remove our relations but leave the related objects for objects
125
		// that may be used by other objects.
126
		foreach($this->Links() as $link) {
0 ignored issues
show
Documentation Bug introduced by
The method Links does not exist on object<SilverStripe\Addons\Model\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...
127
			$link->delete();
128
		}
129
		$this->Authors()->removeAll();
0 ignored issues
show
Documentation Bug introduced by
The method Authors does not exist on object<SilverStripe\Addons\Model\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...
130
		$this->Keywords()->removeAll();
0 ignored issues
show
Documentation Bug introduced by
The method Keywords does not exist on object<SilverStripe\Addons\Model\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...
131
		$this->CompatibleVersions()->removeAll();
0 ignored issues
show
Documentation Bug introduced by
The method CompatibleVersions does not exist on object<SilverStripe\Addons\Model\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...
132
	}
133
134
}