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

Addon   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 180
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

Changes 0
Metric Value
wmc 18
lcom 2
cbo 6
dl 0
loc 180
c 0
b 0
f 0
rs 10

16 Methods

Rating   Name   Duplication   Size   Complexity  
A SortedVersions() 0 10 1
A MasterVersion() 0 4 1
A Authors() 0 4 1
A VendorName() 0 4 1
A VendorLink() 0 6 1
A PackageName() 0 4 1
A Link() 0 6 1
A DescriptionText() 0 4 1
A RSSTitle() 0 4 1
A PackagistUrl() 0 4 1
A getAdjustedHelpfulRobotScore() 0 4 1
A getElasticaMapping() 0 14 1
A getElasticaDocument() 0 15 1
A onBeforeDelete() 0 18 3
A getDateCreated() 0 4 1
A HelpfulRobotData() 0 6 1
1
<?php
2
3
namespace SilverStripe\Addons\Model;
4
5
use Elastica\Document;
6
use Elastica\Type\Mapping;
7
use SilverStripe\ORM\ArrayData;
8
use SilverStripe\ORM\ArrayList;
9
use SilverStripe\Control\Controller;
10
use SilverStripe\Control\Director;
11
use SilverStripe\ORM\DataObject;
12
13
/**
14
 * An add-on with one or more versions.
15
 */
16
class Addon extends DataObject 
17
{
18
19
	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...
20
		'Name' => 'Varchar(255)',
21
		'Description' => 'Text',
22
		'Type' => 'Varchar(100)',
23
		'Readme' => 'HTMLText',
24
		'Released' => 'SS_Datetime',
25
		'Repository' => 'Varchar(255)',
26
		'Downloads' => 'Int',
27
		'DownloadsMonthly' => 'Int',
28
		'Favers' => 'Int',
29
		'LastUpdated' => 'SS_Datetime',
30
		'LastBuilt' => 'SS_Datetime',
31
		'BuildQueued' => 'Boolean',
32
		'HelpfulRobotData' => 'Text',
33
		'HelpfulRobotScore' => 'Int',
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
		'Vendor' => 'SilverStripe\Addons\Model\AddonVendor'
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
		'Versions' => 'SilverStripe\Addons\Model\AddonVersion'
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
		'Keywords' => 'SilverStripe\Addons\Model\AddonKeyword',
46
		'Screenshots' => 'SilverStripe\Assets\Image',
47
		'CompatibleVersions' => 'SilverStripe\Addons\Model\SilverStripeVersion'
48
	];
49
50
	private static $default_sort = 'Name';
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
52
	private static $extensions = [
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...
53
		'SilverStripe\\Elastica\\Searchable'
54
	];
55
56
	/**
57
	 * Gets the addon's versions sorted from newest to oldest.
58
	 *
59
	 * @return ArrayList
60
	 */
61
	public function SortedVersions() 
62
	{
63
		$versions = $this->Versions()->toArray();
0 ignored issues
show
Bug introduced by
The method Versions() does not exist on SilverStripe\Addons\Model\Addon. Did you maybe mean SortedVersions()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
64
65
		usort($versions, function($a, $b) {
66
			return version_compare($b->Version, $a->Version);
67
		});
68
69
		return new ArrayList($versions);
70
	}
71
72
	public function MasterVersion() 
73
	{
74
		return $this->Versions()->filter('PrettyVersion', ['dev-master', 'trunk'])->First();
0 ignored issues
show
Bug introduced by
The method Versions() does not exist on SilverStripe\Addons\Model\Addon. Did you maybe mean SortedVersions()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
75
	}
76
77
	public function Authors() 
78
	{
79
		return $this->Versions()->relation('Authors');
0 ignored issues
show
Bug introduced by
The method Versions() does not exist on SilverStripe\Addons\Model\Addon. Did you maybe mean SortedVersions()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
80
	}
81
82
	public function VendorName() 
83
	{
84
		return substr($this->Name, 0, strpos($this->Name, '/'));
0 ignored issues
show
Documentation introduced by
The property Name does not exist on object<SilverStripe\Addons\Model\Addon>. 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...
85
	}
86
87
	public function VendorLink() 
88
	{
89
		return Controller::join_links(
90
			Director::baseURL(), 'add-ons', $this->VendorName()
91
		);
92
	}
93
94
	public function PackageName() 
95
	{
96
		return substr($this->Name, strpos($this->Name, '/') + 1);
0 ignored issues
show
Documentation introduced by
The property Name does not exist on object<SilverStripe\Addons\Model\Addon>. 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...
97
	}
98
99
	public function Link() 
100
	{
101
		return Controller::join_links(
102
			Director::baseURL(), 'add-ons', $this->Name
0 ignored issues
show
Documentation introduced by
The property Name does not exist on object<SilverStripe\Addons\Model\Addon>. 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...
103
		);
104
	}
105
106
	public function DescriptionText() 
107
	{
108
		return $this->Description;
0 ignored issues
show
Documentation introduced by
The property Description does not exist on object<SilverStripe\Addons\Model\Addon>. 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...
109
	}
110
111
	public function RSSTitle() 
112
	{
113
		return sprintf('New module release: %s', $this->Name);
0 ignored issues
show
Documentation introduced by
The property Name does not exist on object<SilverStripe\Addons\Model\Addon>. 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...
114
	}
115
116
	public function PackagistUrl()
117
	{
118
		return "https://packagist.org/packages/$this->Name";
0 ignored issues
show
Documentation introduced by
The property Name does not exist on object<SilverStripe\Addons\Model\Addon>. 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...
119
	}
120
121
	/**
122
	 * Remove the effect of code of conduct Helpful Robot measure that we currently don't include in the Supported module definition
123
	 *
124
	 * @return integer Adjusted Helpful Robot score
125
	 */
126
	public function getAdjustedHelpfulRobotScore()
127
	{
128
		return round(min(100, $this->HelpfulRobotScore / 92.9 * 100));
0 ignored issues
show
Documentation introduced by
The property HelpfulRobotScore does not exist on object<SilverStripe\Addons\Model\Addon>. 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...
129
	}
130
131
	public function getElasticaMapping() 
132
	{
133
		return new Mapping(null, [
134
			'name' => ['type' => 'string'],
135
			'description' => ['type' => 'string'],
136
			'type' => ['type' => 'string'],
137
			'compatibility' => ['type' => 'string'],
138
			'vendor' => ['type' => 'string'],
139
			'tags' => ['type' => 'string'],
140
			'released' => ['type' => 'date'],
141
			'downloads' => ['type' => 'string'],
142
			'readme' => ['type' => 'string']
143
		]);
144
	}
145
146
	public function getElasticaDocument() 
147
	{
148
		return new Document($this->ID, [
149
			'name' => $this->Name,
0 ignored issues
show
Documentation introduced by
The property Name does not exist on object<SilverStripe\Addons\Model\Addon>. 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...
150
			'description' => $this->Description,
0 ignored issues
show
Documentation introduced by
The property Description does not exist on object<SilverStripe\Addons\Model\Addon>. 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...
151
			'type' => $this->Type,
0 ignored issues
show
Documentation introduced by
The property Type does not exist on object<SilverStripe\Addons\Model\Addon>. 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...
152
			'compatibility' => $this->CompatibleVersions()->column('Name'),
0 ignored issues
show
Documentation Bug introduced by
The method CompatibleVersions does not exist on object<SilverStripe\Addons\Model\Addon>? 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...
153
			'vendor' => $this->VendorName(),
154
			'tags' => $this->Keywords()->column('Name'),
0 ignored issues
show
Documentation Bug introduced by
The method Keywords does not exist on object<SilverStripe\Addons\Model\Addon>? 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...
155
			'released' => $this->obj('Released')->Format('c'),
156
			'downloads' => (int) $this->Downloads,
0 ignored issues
show
Documentation introduced by
The property Downloads does not exist on object<SilverStripe\Addons\Model\Addon>. 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...
157
			'readme' => strip_tags($this->Readme),
0 ignored issues
show
Documentation introduced by
The property Readme does not exist on object<SilverStripe\Addons\Model\Addon>. 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...
158
			'_boost' => sqrt($this->Downloads)
0 ignored issues
show
Documentation introduced by
The property Downloads does not exist on object<SilverStripe\Addons\Model\Addon>. 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...
159
		]);
160
	}
161
162
	public function onBeforeDelete() 
163
	{
164
		parent::onBeforeDelete();
165
166
		// Partially cascade delete. Leave author and keywords in place,
167
		// since they might be related to other addons.
168
		foreach($this->Screenshots() as $image) {
0 ignored issues
show
Documentation Bug introduced by
The method Screenshots does not exist on object<SilverStripe\Addons\Model\Addon>? 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...
169
			$image->delete();
170
		}
171
		$this->Screenshots()->removeAll();
0 ignored issues
show
Documentation Bug introduced by
The method Screenshots does not exist on object<SilverStripe\Addons\Model\Addon>? 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...
172
173
		foreach($this->Versions() as $version) {
0 ignored issues
show
Bug introduced by
The method Versions() does not exist on SilverStripe\Addons\Model\Addon. Did you maybe mean SortedVersions()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
174
			$version->delete();
175
		}
176
177
		$this->Keywords()->removeAll();
0 ignored issues
show
Documentation Bug introduced by
The method Keywords does not exist on object<SilverStripe\Addons\Model\Addon>? 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...
178
		$this->CompatibleVersions()->removeAll();
0 ignored issues
show
Documentation Bug introduced by
The method CompatibleVersions does not exist on object<SilverStripe\Addons\Model\Addon>? 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...
179
	}
180
181
	public function getDateCreated() 
182
	{
183
		return date('Y-m-d', strtotime($this->Created));
184
	}
185
186
	/**
187
	 * @return array
188
	 */
189
	public function HelpfulRobotData()
190
	{
191
		$data = json_decode($this->HelpfulRobotData, true);
0 ignored issues
show
Documentation introduced by
The property HelpfulRobotData does not exist on object<SilverStripe\Addons\Model\Addon>. 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...
192
193
		return new ArrayData($data["inspections"][0]);
194
	}
195
}
196