ShortListItem   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getActualRecord() 0 4 1
1
<?php
2
3
/*
4
 * @file ShortListItem.php
5
 *
6
 * An item that gets added to a shortlist.
7
 *
8
 * Any DataObject that is attached to a ShortListItem **MUST**:
9
 *
10
 * * Provide Link() & AbsoluteLink() functions.
11
 * * Provide a preview for the item with forTemplate()
12
 *
13
 **/
14
class ShortListItem extends DataObject
15
{
16
    private static $db = 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...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
17
        'ItemType'  => 'Varchar(128)',
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
18
        'ItemID'    => 'Varchar(12)'
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
19
    );
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
20
21
    private static $has_one = 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...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
22
        'ShortList' => 'ShortList'
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
23
    );
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
24
25
    public function getActualRecord()
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
26
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
27
        return DataObject::get_by_id($this->ItemType, $this->ItemID);
0 ignored issues
show
Documentation introduced by
The property ItemType does not exist on object<ShortListItem>. 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...
Documentation introduced by
The property ItemID does not exist on object<ShortListItem>. 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...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
28
    }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
29
}
30