Kohana_Model_Promotion_Promocode_Percent   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 25
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 10 1
A price_for_purchase_item() 0 8 1
1
<?php defined('SYSPATH') OR die('No direct script access.');
2
3
/**
4
 * @package    openbuildings\promotions
5
 * @author     Ivan Kerin <[email protected]>
6
 * @copyright  (c) 2013 OpenBuildings Ltd.
7
 * @license    http://spdx.org/licenses/BSD-3-Clause
8
 */
9
class Kohana_Model_Promotion_Promocode_Percent extends Model_Promotion_Promocode {
10
11
	/**
12
	 * @codeCoverageIgnore
13
	 */
14
	public static function initialize(Jam_Meta $meta)
15
	{
16
		parent::initialize($meta);
17
18
		$meta
19
			->fields(array(
20
				'amount' => Jam::field('float'),
21
			))
22
			->validator('amount', array('numeric' => array('between' => array(0, 1))));
23
	}
24
25 1
	public function price_for_purchase_item(Model_Purchase_Item $purchase_item)
26
	{
27 1
		$brand_purchase_price = $purchase_item->get_insist('brand_purchase')->total_price('product');
28
29
		return $brand_purchase_price
30 1
			->multiply_by($this->amount)
0 ignored issues
show
Documentation introduced by
The property amount does not exist on object<Kohana_Model_Promotion_Promocode_Percent>. 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...
31 1
			->multiply_by(-1);
32
	}
33
}
34