validate_purchase()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php defined('SYSPATH') OR die('No direct script access.');
2
3
/**
4
 * @package    openbuildings\promotions
5
 * @author     Ivan Kerin <[email protected]>
6
 * @author     Yasen Yanev <[email protected]>
7
 * @copyright  (c) 2013 OpenBuildings Ltd.
8
 * @license    http://spdx.org/licenses/BSD-3-Clause
9
 */
10
class Kohana_Model_Promotion_Promocode extends Model_Promotion {
11
12
	/**
13
	 * @codeCoverageIgnore
14
	 */
15
	public static function initialize(Jam_Meta $meta)
16
	{
17
		parent::initialize($meta);
18
19
		$meta
20
			->associations(array(
21
				'promo_codes' => Jam::association('hasmany', array(
22
					'inverse_of' => 'promotion',
23
					'foreign_key' => 'promotion_id',
24
				)),
25
			));
26
	}
27
28 1
	public function applies_to(Model_Brand_Purchase $brand_purchase)
29
	{
30 1
		return $this->matches_brand_purchase_promo_code($brand_purchase);
31
	}
32
33
	/**
34
	 * @codeCoverageIgnore
35
	 */
36
	public function validate_purchase(Model_Purchase $brand_purchase)
37
	{
38
		// extend this to add custom validation for the purchase (or promocode)
39
	}
40
41 1
	public function matches_brand_purchase_promo_code(Model_Brand_Purchase $brand_purchase)
42
	{
43 1
		$promo_code = $brand_purchase->get_insist('purchase')->promo_code;
44
45 1
		if ( ! $promo_code)
46 1
			return FALSE;
47
48 1
		return $this->has_promo_code($promo_code);
49
	}
50
51 1
	public function has_promo_code(Model_Promo_Code $promo_code)
52
	{
53 1
		return $this->promo_codes->where('id', '=', $promo_code->id())->count_all() > 0;
0 ignored issues
show
Documentation introduced by
The property promo_codes does not exist on object<Kohana_Model_Promotion_Promocode>. 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...
54
	}
55
}
56