EcommerceVoteDataDecorator   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A HasEcommerceVote() 0 4 1
A EcommerceVotes() 0 8 2
B updateCMSFields() 0 21 6
1
<?php
2
3
/**
4
 *@author nicolaas[at]sunnysideup.co.nz
5
 *
6
 *
7
 *
8
 **/
9
10
class EcommerceVoteDataDecorator 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...
11
{
12
    public function HasEcommerceVote()
13
    {
14
        return DataObject::get_one("EcommerceVote", "SessionID = '".Session_ID()."' AND PageID = ".$this->owner->ID);
15
    }
16
17
    public function EcommerceVotes()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
18
    {
19
        $count = DB::query("Select COUNT(ID) c FROM EcommerceVote WHERE PageID = ".$this->owner->ID);
20
        foreach ($count as $item) {
21
            return $item["c"];
22
        }
23
        return 0;
24
    }
25
26
    public function updateCMSFields(FieldSet &$fields)
27
    {
28
        $array = EcommerceVote::get_array_of_classes_used();
29
        $show = false;
30
        if (!is_array($array) || !count($array)) {
31
            $show = true;
32
        } else {
33
            foreach ($array as $className) {
34
                if ($this->owner instanceof $className) {
35
                    $show = true;
36
                }
37
            }
38
        }
39
        if ($show) {
40
            $fields->addFieldsToTab(
41
                "Root.Content.Votes",
42
                new LiteralField("Votes", "Number of votes: ".$this->EcommerceVotes())
0 ignored issues
show
Documentation introduced by
new \LiteralField('Votes...this->EcommerceVotes()) is of type object<LiteralField>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
            );
44
        }
45
        return $fields;
46
    }
47
}
48