Affiliation::getCode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
class Affiliation extends DataObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    public static $db = array(
6
        "Title" => "Varchar(100)",
7
        "Code" => "Varchar(100)",
8
        "Link" => "Varchar(100)",
9
        "Sort" => "Int"
10
    );
11
12
    public static $has_one = array(
13
        "Parent" => "SiteTree",
14
        "Logo" => "Image"
15
    );
16
17
    public static function get_has_many_complex_table_field($controller, $name)
18
    {
19
        return new HasManyComplexTableField(
20
            $controller,
21
            $name,
22
            "Affiliation",
23
            $fieldList = self::$summary_fields,
24
            $detailFormFields = null,
25
            $sourceFilter = "ParentID = ".$controller->ID,
26
            $sourceSort = "Sort ASC, Title ASC",
27
            $sourceJoin = ""
28
        );
29
    }
30
31
    public function getCode()
32
    {
33
        if (!$this->getField("Code")) {
34
            return _t('Affiliation.GETCMSAFFLIATIONIDPREFIX', 'Affiliation').$this->ID;
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<Affiliation>. 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...
35
        }
36
        return $this->getField("Code");
37
    }
38
39
    public static $searchable_fields = array(
40
        "Title" => "PartialMatchFilter",
41
        "Code" => "PartialMatchFilter",
42
        "Link" => "PartialMatchFilter"
43
    );
44
45
    public static $summary_fields = array(
46
        "Title" => "Title",
47
        "Code" => "Code",
48
        "Link" => "Link"
49
    );
50
51
    public static $field_labels = array(
52
        "Sort" => "Sorting Index Number (lower numbers show first)"
53
    );
54
55
    public static $singular_name = "Affiliation";
56
57
    public static $plural_name = "Affiliations";
58
    //CRUD settings
59
60
    public static $default_sort = "Sort ASC, Title ASC";
61
62
    public static $defaults = array(
63
        "Sort" => 100
64
    );
65
66
    public function populateDefaults()
67
    {
68
        $this->Sort = 100;
0 ignored issues
show
Documentation introduced by
The property Sort does not exist on object<Affiliation>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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
        parent::populateDefaults();
70
    }
71
}
72