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

AddonAuthor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A GravatarUrl() 0 9 1
A Link() 0 4 1
A Addons() 0 4 1
1
<?php
2
3
namespace SilverStripe\Addons\Model;
4
5
use SilverStripe\ORM\DataObject;
6
use SilverStripe\Control\Controller;
7
use SilverStripe\Control\Director;
8
9
/**
10
 * An author who can be linked to several add-ons.
11
 */
12
class AddonAuthor extends DataObject 
13
{
14
15
	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...
16
		'Name' => 'Varchar(255)',
17
		'Email' => 'Varchar(255)',
18
		'Homepage' => 'Varchar(255)',
19
		'Role' => 'Varchar(255)'
20
	];
21
22
	private static $belongs_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...
23
		'Versions' => 'SilverStripe\Addons\Model\AddonVersion'
24
	];
25
26
	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...
27
28
	public function GravatarUrl($size, $default = 'mm') 
29
	{
30
		return sprintf(
31
			'http://www.gravatar.com/avatar/%s?s=%d&d=%s',
32
			md5(strtolower(trim($this->Email))),
0 ignored issues
show
Documentation introduced by
The property Email does not exist on object<SilverStripe\Addons\Model\AddonAuthor>. 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...
33
			$size,
34
			$default
35
		);
36
	}
37
38
	public function Link() 
39
	{
40
		return Controller::join_links(Director::baseURL(), 'authors', $this->ID);
41
	}
42
43
	public function Addons() 
44
	{
45
		return Addon::get()->filter('ID', $this->Versions()->column('AddonID'));
0 ignored issues
show
Documentation Bug introduced by
The method Versions does not exist on object<SilverStripe\Addons\Model\AddonAuthor>? 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...
46
	}
47
48
}
49