ShippingMethod::requiresAddress()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * ShippingMethod is a base class for providing shipping options to customers.
5
 *
6
 * @package silvershop-shipping
7
 */
8
class ShippingMethod extends DataObject
9
{
10
    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...
11
        "Name" => "Varchar",
12
        "Description" => "Text",
13
        "Enabled" => "Boolean"
14
    );
15
16
    private static $casting = 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...
17
        'Rate' => 'Currency'
18
    );
19
20
    public function getCalculator(Order $order)
21
    {
22
        return new ShippingCalculator($this, $order);
23
    }
24
25
    public function calculateRate(ShippingPackage $package, Address $address)
26
    {
27
        return null;
28
    }
29
30
    public function getRate()
31
    {
32
        return $this->CalculatedRate;
0 ignored issues
show
Documentation introduced by
The property CalculatedRate does not exist on object<ShippingMethod>. 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...
33
    }
34
35
    public function getTitle()
36
    {
37
        $title = implode(" - ", array_filter(array(
38
            $this->Rate,
0 ignored issues
show
Documentation introduced by
The property Rate does not exist on object<ShippingMethod>. 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...
39
            $this->Name,
0 ignored issues
show
Documentation introduced by
The property Name does not exist on object<ShippingMethod>. 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...
40
            $this->Description
0 ignored issues
show
Documentation introduced by
The property Description does not exist on object<ShippingMethod>. 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...
41
        )));
42
43
        $this->extend('updateTitle', $title);
44
        return $title;
45
    }
46
47
    /**
48
     * Some shipping methods might require an address present on the order.
49
     *
50
     * @return bool
51
     */
52
    public function requiresAddress()
53
    {
54
        return false;
55
    }
56
}
57
58
/**
59
 * Helper class for encapsulating shipping calculation logic.
60
 */
61
class ShippingCalculator
62
{
63
    protected $method;
64
    protected $order;
65
66
    public function __construct(ShippingMethod $method, Order $order)
67
    {
68
        $this->method = $method;
69
        $this->order = $order;
70
    }
71
72
    public function calculate($address = null)
73
    {
74
        return $this->method->calculateRate(
75
            $this->order->createShippingPackage(),
76
            $address ? $address : $this->order->getShippingAddress()
77
        );
78
    }
79
}
80