WishListMemberDecorator   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 51
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extraStatics() 0 9 1
C updateCMSFields() 0 30 7
1
<?php
2
/**
3
 *
4
 * @author romain[at]sunnysideup.co.nz
5
 * @description: adds functions to the shopping cart
6
 *
7
 **/
8
9
class WishListMemberDecorator extends DataObjectDecorator
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...
10
{
11
12
    /**
13
     * Define extra database fields for member object.
14
     * @return array
15
     */
16
    public function extraStatics()
17
    {
18
        return array(
19
            'db' => array(
20
                //Wish list will be stored as a serialised array.
21
                'WishList' => 'Text'
22
            )
23
        );
24
    }
25
26
    /**
27
     * standard SS function - we dont need to show the Wish List field in the CMS.
28
     */
29
    public function updateCMSFields(&$fields)
30
    {
31
        $fields->removeByName("WishList");
32
        $member = Member::currentUser();
33
        if ($member && $member->IsAdmin()) {
34
            $html = "";
0 ignored issues
show
Unused Code introduced by
$html is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
35
            $array = unserialize($this->owner->WishList);
36
            $links = array();
37
            if (is_array($array) && count($array)) {
38
                foreach ($array as $item) {
39
                    $object = DataObject::get_by_id($item[0], $item[1]);
40
                    if ($object) {
41
                        $links[] = "<a href=\"".$object->Link()."\">".$object->Title."</a>";
42
                    } else {
43
                        $links[] = "error in retrieving object ".implode(", ", $item);
44
                    }
45
                }
46
            } else {
47
                $links[] = "no items on wishlist";
48
            }
49
            $html = "<ul><li>".implode("</li><li>", $links)."</li></ul>";
50
            $field = new LiteralField(
51
                "WishListOverview",
52
                $html
53
            );
54
            $fields->addFieldToTab("Root.WishList", $field);
55
        } else {
56
            $fields->removeByName("WishList");
57
        }
58
    }
59
}
60