Kohana_Model_Purchase_Item_Shipping   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 61.53%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 4
dl 0
loc 44
ccs 8
cts 13
cp 0.6153
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 12 1
A get_price() 0 5 2
A performFreeze() 0 9 2
A performUnfreeze() 0 9 2
1
<?php defined('SYSPATH') OR die('No direct script access.');
2
3
/**
4
 * @package    openbuildings\shipping
5
 * @author     Haralan Dobrev <[email protected]>
6
 * @copyright  2013 OpenBuildings, Inc.
7
 * @license    http://spdx.org/licenses/BSD-3-Clause
8
 */
9
class Kohana_Model_Purchase_Item_Shipping extends Model_Purchase_Item {
10
11
	/**
12
	 * @codeCoverageIgnore
13
	 */
14
	public static function initialize(Jam_Meta $meta)
15
	{
16
		parent::initialize($meta);
17
18
		$meta
19
			->table('purchase_items')
20
			->fields(array(
21
				'is_payable' => Jam::field('boolean', array(
22
					'default' => TRUE
23
				))
24
			));
25
	}
26
27 2
	public function get_price()
28
	{
29 2
		$reference = $this->get_reference_paranoid();
30 2
		return $reference ? $reference->price_for_purchase_item($this) : new Jam_Price(0, 'GBP');
31
	}
32
33 1
	public function performFreeze()
34
	{
35 1
		parent::performFreeze();
36
37 1
		if ($this->reference)
0 ignored issues
show
Documentation introduced by
The property reference does not exist on object<Kohana_Model_Purchase_Item_Shipping>. 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...
38
		{
39 1
			$this->reference->freeze();
0 ignored issues
show
Documentation introduced by
The property reference does not exist on object<Kohana_Model_Purchase_Item_Shipping>. 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
		}
41 1
	}
42
43
	public function performUnfreeze()
44
	{
45
		parent::performUnfreeze();
46
47
		if ($this->reference)
0 ignored issues
show
Documentation introduced by
The property reference does not exist on object<Kohana_Model_Purchase_Item_Shipping>. 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...
48
		{
49
			$this->reference->unfreeze();
0 ignored issues
show
Documentation introduced by
The property reference does not exist on object<Kohana_Model_Purchase_Item_Shipping>. 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...
50
		}
51
	}
52
}
53