Completed
Push — master ( b7c5b8...080abf )
by Nicolaas
01:40
created

code/model/BuyableStockOrderEntry.php (4 issues)

Check for undocumented magic property with read access

Documentation Informational

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 *@author: Nicolaas [at] Sunny Side Up . Co . Nz
4
 *@description:
5
 * keeps a record of the quantity deduction made for each sale.  That is, if we sell 10 widgets in an order then an entry is made in this dataclass for
6
 * a reduction of ten widgets in the available quantity
7
 *
8
 **/
9
10
class BuyableStockOrderEntry extends DataObject
11
{
12
    private static $db = array(
13
        "Quantity" => "Int",
14
        "IncludeInCurrentCalculation" => "Boolean"
15
    );
16
17
    private static $has_one = array(
18
        "Parent" => "BuyableStockCalculatedQuantity",
19
        "Order" => "Order",
20
    );
21
22
    private static $defaults = array(
23
        "IncludeInCurrentCalculation" => 1
24
    );
25
26
27
    //MODEL ADMIN STUFF
28
    private static $searchable_fields = array(
29
        "Quantity",
30
        "IncludeInCurrentCalculation",
31
        "ParentID",
32
        "OrderID",
33
    );
34
35
    private static $field_labels = array(
36
        "Quantity" => "Calculated Quantity On Hand",
37
        "IncludeInCurrentCalculation" => "Include in Calculation",
38
        "ParentID" => "Buyable Calculation",
39
        "OrderID" => "Order"
40
    );
41
42
    private static $summary_fields = array(
43
        "OrderID",
44
        "ParentID",
45
        "Quantity"
46
    );
47
48
    private static $default_sort = "\"LastEdited\" DESC, \"ParentID\" ASC";
49
50
    private static $singular_name = "Stock Sale Entry";
51
    public function i18n_singular_name()
52
    {
53
        return _t("BuyableStockOrderEntry.STOCKSALEENTRY", "Stock Sale Entry");
54
    }
55
56
    private static $plural_name = "Stock Sale Entries";
57
    public function i18n_plural_name()
58
    {
59
        return _t("BuyableStockOrderEntry.STOCKSALEENTRIES", "Stock Sale Entries");
60
    }
61
62
    public function canCreate($member = null)
63
    {
64
        return false;
65
    }
66
67
    public function canEdit($member = null)
68
    {
69
        return false;
70
    }
71
72
    public function canDelete($member = null)
73
    {
74
        return false;
75
    }
76
77
    public function canView($member = null)
78
    {
79
        return $this->canDoAnything();
80
    }
81
82 View Code Duplication
    protected function canDoAnything()
83
    {
84
        EcommerceConfig::get("EcommerceRole", "admin_permission_code");
85
        if (!Permission::check("ADMIN") && !Permission::check($shopAdminCode)) {
86
            Security::permissionFailure($this, _t('Security.PERMFAILURE', ' This page is secured and you need administrator rights to access it. Enter your credentials below and we will send you right along.'));
87
        }
88
        return true;
89
    }
90
91
    public function onAfterWrite()
92
    {
93
        parent::onAfterWrite();
94
        if ($this->ID) {
95
            //basic checks
96
            if (!$this->ParentID) {
0 ignored issues
show
The property ParentID does not exist on object<BuyableStockOrderEntry>. 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...
97
                $this->delete();
98
                user_error("Can not create record without associated buyable.", E_USER_ERROR);
99
            }
100
            if (!$this->OrderID) {
0 ignored issues
show
The property OrderID does not exist on object<BuyableStockOrderEntry>. 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...
101
                $this->delete();
102
                user_error("Can not create record without order.", E_USER_ERROR);
103
            }
104
            //make sure no duplicates are created
105
            $toBeDeleted = BuyableStockOrderEntry::get()
106
                                            ->filter(array('OrderID' => $this->OrderID, 'ParentID' => $this->ParentID))
0 ignored issues
show
The property OrderID does not exist on object<BuyableStockOrderEntry>. 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...
The property ParentID does not exist on object<BuyableStockOrderEntry>. 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...
107
                                            ->exclude(array("ID"=> $this->ID))
108
                                            ->sort(array('LastEdited' => 'ASC'));
109
            foreach ($toBeDeleted as $youAreDodo) {
110
                $youAreDodo->delete();
111
                $youAreDodo->destroy();
112
                user_error("deleting BuyableStockOrderEntry because there are multiples!", E_USER_ERROR);
113
            }
114
        }
115
    }
116
}
117