Kohana_Jam_Validator_Rule_Purchase_Promocode   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 17 3
A valid_promo_code() 0 7 1
1
<?php defined('SYSPATH') OR die('No direct script access.');
2
3
/**
4
 * Validate for available and not expired promo_code_text
5
 * Specific for a purchase model
6
 *
7
 * @package    openbuildings\promotions
8
 * @author     Ivan Kerin <[email protected]>
9
 * @copyright  (c) 2013 OpenBuildings Ltd.
10
 * @license    http://spdx.org/licenses/BSD-3-Clause
11
 */
12
class Kohana_Jam_Validator_Rule_Purchase_Promocode extends Jam_Validator_Rule {
13
14 1
	public function validate(Jam_Validated $model, $attribute, $value)
15
	{
16 1
		$promo_code = $this->valid_promo_code($value, $model);
0 ignored issues
show
Compatibility introduced by
$model of type object<Jam_Validated> is not a sub-type of object<Model_Purchase>. It seems like you assume a child class of the class Jam_Validated to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
17
18 1
		if (! $promo_code)
19
		{
20 1
			$model->errors()->add('promo_code_text', 'invalid');
21
		}
22 1
		elseif ($promo_code->is_expired())
23
		{
24 1
			$model->errors()->add('promo_code_text', 'expired');
25
		}
26
		else
27
		{
28 1
			$promo_code->validate_purchase($model);
29
		}
30 1
	}
31
32 1
	public function valid_promo_code($code, Model_Purchase $purchase)
33
	{
34 1
		return Jam::all('promo_code')
35 1
			->where('code', '=', $code)
36 1
			->available_for_purchase($purchase)
37 1
			->first();
38
	}
39
}
40