AdvertisementStyle   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A requireDefaultRecords() 0 18 6
1
<?php
2
3
/**
4
 * @nicolaas [at] sunnysideup.co.nz
5
 *
6
 *
7
 **/
8
9
10
class AdvertisementStyle 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...
11
{
12
    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...
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
13
        "Title" => "Varchar(100)",
14
        "FileLocation" => "Varchar(100)"
15
    );
16
17
    private static $has_many = 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...
Unused Code introduced by
The property $has_many is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
18
        "Parent" => "SiteTree"
19
    );
20
21
    private static $array_of_js_file_options = array();
0 ignored issues
show
Unused Code introduced by
The property $array_of_js_file_options is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
22
23
    private static $fx = array(
0 ignored issues
show
Unused Code introduced by
The property $fx is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
24
        "blindX",
25
        "blindY",
26
        "blindZ",
27
        "cover",
28
        "curtainX",
29
        "curtainY",
30
        "fade",
31
        "fadeZoom",
32
        "growX",
33
        "growY",
34
        "none",
35
        "scrollUp",
36
        "scrollDown",
37
        "scrollLeft",
38
        "scrollRight",
39
        "scrollHorz",
40
        "scrollVert",
41
        "shuffle",
42
        "slideX",
43
        "slideY",
44
        "toss",
45
        "turnUp",
46
        "turnDown",
47
        "turnLeft",
48
        "turnRight",
49
        "uncover",
50
        "wipe",
51
        "zoom"
52
    );
53
54
    public function requireDefaultRecords()
55
    {
56
        parent::requireDefaultRecords();
57
        if ($a = Config::inst()->get("AdvertisementStyle", "array_of_js_file_options")) {
58
            if (is_array($a)) {
59
                if (count($a)) {
60
                    foreach ($a as $k => $v) {
61
                        if (!AdvertisementStyle::get()->where("Title = '".$k."' OR FileLocation = '".$v."'")->First()) {
62
                            $o = new AdvertisementStyle();
63
                            $o->Title = $k;
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<AdvertisementStyle>. 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...
64
                            $o->FileLocation = $v;
0 ignored issues
show
Documentation introduced by
The property FileLocation does not exist on object<AdvertisementStyle>. 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...
65
                            $o->write();
66
                        }
67
                    }
68
                }
69
            }
70
        }
71
    }
72
}
73