RepeatOrder_OrderItem::getCMSFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
class RepeatOrder_OrderItem extends DataObject
3
{
4
    public static $db = array(
5
        'Quantity' => 'Int'
6
    );
7
    public static $has_one = array(
8
        'Product' => 'Product',
9
        'Order' => 'RepeatOrder',
10
        'Alternative1' => 'Product',
11
        'Alternative2' => 'Product',
12
        'Alternative3' => 'Product',
13
        'Alternative4' => 'Product',
14
        'Alternative5' => 'Product',
15
        'Alternative6' => 'Product',
16
        'Alternative7' => 'Product',
17
        'Alternative8' => 'Product',
18
        'Alternative9' => 'Product'
19
    );
20
21
    public function getCMSFields()
22
    {
23
        $fields = parent::getCMSFields();
24
        return $fields;
25
    }
26
27
    public function Title()
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...
28
    {
29
        if ($product = $this->Product()) {
0 ignored issues
show
Bug introduced by
The method Product() does not exist on RepeatOrder_OrderItem. Did you maybe mean getProductID()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
30
            return $product->Title;
31
        }
32
        return "NOT FOUND";
33
    }
34
35
    public function BuyableTitle()
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...
36
    {
37
        if ($product = $this->Product()) {
0 ignored issues
show
Bug introduced by
The method Product() does not exist on RepeatOrder_OrderItem. Did you maybe mean getProductID()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
38
            return $product->Title;
39
        }
40
        return "NOT FOUND";
41
    }
42
43
    /**
44
     * returns a link to the product
45
     * @return string
46
     */
47
    public function Link()
48
    {
49
        if ($product = $this->Product()) {
0 ignored issues
show
Bug introduced by
The method Product() does not exist on RepeatOrder_OrderItem. Did you maybe mean getProductID()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
50
            return $product->Link;
51
        }
52
        return '';
53
    }
54
55
    /**
56
     * returns the product ID
57
     * @return string
58
     */
59
    public function getProductID()
60
    {
61
        if ($product = $this->Product()) {
0 ignored issues
show
Bug introduced by
The method Product() does not exist on RepeatOrder_OrderItem. Did you maybe mean getProductID()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
62
            return $product->ID;
63
        }
64
        return 0;
65
    }
66
67
    /**
68
     * @return Field (EcomQuantityField)
0 ignored issues
show
Documentation introduced by
Should the return type not be HiddenField?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
69
     **/
70
    public function IDField()
71
    {
72
        $field = HiddenField::create(
73
            'Product[ID]['.$this->Product()->ID.']',
0 ignored issues
show
Bug introduced by
The method Product() does not exist on RepeatOrder_OrderItem. Did you maybe mean getProductID()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
74
            "",
75
            $this->Product()->ID
0 ignored issues
show
Bug introduced by
The method Product() does not exist on RepeatOrder_OrderItem. Did you maybe mean getProductID()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
76
        );
77
        return $field;
78
    }
79
80
    /**
81
     * @return Field (EcomQuantityField)
0 ignored issues
show
Documentation introduced by
Should the return type not be NumericField?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
82
     **/
83
    public function QuantityField()
84
    {
85
        $field = NumericField::create(
86
            'Product[Quantity]['.$this->Product()->ID.']',
0 ignored issues
show
Bug introduced by
The method Product() does not exist on RepeatOrder_OrderItem. Did you maybe mean getProductID()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
87
            "",
88
            $this->Quantity
0 ignored issues
show
Documentation introduced by
The property Quantity does not exist on object<RepeatOrder_OrderItem>. 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...
89
        )->addExtraClass('ajaxQuantityField');
90
        return $field;
91
    }
92
93
    /**
94
     * Alias for AlternativesPerProduct
95
     */
96
    public function TableAlternatives()
97
    {
98
        return $this->AlternativesPerProduct();
99
    }
100
101
    /**
102
     * returns a list of alternatives per product (if any)
103
     * @return ArrayList|null
104
     */
105
    public function AlternativesPerProduct()
106
    {
107
        $dos = ArrayList::create();
108
        $altCount = Config::inst()->get('RepeatOrderForm', 'number_of_product_alternatives');
109
        for ($i = 1; $i <= $altCount; $i++) {
110
            $alternativeField = "Alternative".$i."ID";
111
            if ($this->$alternativeField) {
112
                $product = Product::get()->filter(['ID' => $this->$alternativeField])->first();
113
                if ($product) {
114
                    $dos->push($product);
115
                }
116
            }
117
        }
118
        if ($dos && $dos->count()) {
119
            return $dos;
120
        }
121
        return null;
122
    }
123
}
124