AddonAuthor::Addons()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * An author who can be linked to several add-ons.
4
 */
5
class AddonAuthor extends DataObject
6
{
7
8
    public static $db = array(
9
        'Name' => 'Varchar(255)',
10
        'Email' => 'Varchar(255)',
11
        'Homepage' => 'Varchar(255)',
12
        'Role' => 'Varchar(255)'
13
    );
14
15
    public static $belongs_many_many = array(
16
        'Versions' => 'AddonVersion'
17
    );
18
19
    public static $default_sort = 'Name';
20
21
    public function GravatarUrl($size, $default = 'mm')
22
    {
23
        return sprintf(
24
            'https://www.gravatar.com/avatar/%s?s=%d&d=%s',
25
            md5(strtolower(trim($this->Email))),
0 ignored issues
show
Documentation introduced by
The property Email does not exist on object<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...
26
            $size,
27
            $default
28
        );
29
    }
30
31
    public function Link()
32
    {
33
        return Controller::join_links(Director::baseURL(), 'authors', $this->ID);
34
    }
35
36
    public function Addons()
37
    {
38
        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<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...
39
    }
40
}
41