Kohana_Model_Promo_Code   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 42
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 26 2
A validate_purchase() 0 4 1
A is_expired() 0 4 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_Promo_Code extends Jam_Model {
11
12
	/**
13
	 * @codeCoverageIgnore
14
	 */
15
	public static function initialize(Jam_Meta $meta)
16
	{
17
		$meta
18
			->name_key('code')
19
			->unique_key(function($key){
0 ignored issues
show
Documentation introduced by
function ($key) { re...key) ? 'code' : 'id'; } is of type object<Closure>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
20
				return is_string($key) ? 'code' : 'id';
21
			})
22
			->behaviors(array(
23
				'tokenable' => Jam::behavior('tokenable', array(
24
					'field' => 'code',
25
					'uppercase' => TRUE,
26
				)),
27
			))
28
			->associations(array(
29
				'purchases' => Jam::association('hasmany', array('inverse_of' => 'promo_code', 'foreign_model' => 'purchase')),
30
				'promotion' => Jam::association('belongsto', array('inverse_of' => 'promo_codes'))
31
			))
32
			->fields(array(
33
				'id' => Jam::field('primary'),
34
				'origin' => Jam::field('string'),
35
				'allow_multiple' => Jam::field('boolean'),
36
				'created_at' => Jam::field('timestamp', array('auto_now_create' => TRUE, 'format' => 'Y-m-d H:i:s')),
37
				'expires_at' => Jam::field('timestamp', array('format' => 'Y-m-d H:i:s'))
38
			))
39
			->validator('promotion', 'origin', array('present' => TRUE));
40
	}
41
42 1
	public function validate_purchase(Model_Purchase $purchase)
43
	{
44 1
		$this->get_insist('promotion')->validate_purchase($purchase);
45 1
	}
46
47 4
	public function is_expired()
48
	{
49 4
		return (bool) $this->expires_at AND strtotime($this->expires_at) < time();
0 ignored issues
show
Documentation introduced by
The property expires_at does not exist on object<Kohana_Model_Promo_Code>. 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