Kohana_Model_Collection_Promo_Code   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A not_expired() 0 8 2
A available() 0 9 1
A available_for_purchase() 0 10 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_Collection_Promo_Code extends Jam_Query_Builder_Collection {
10
11 1
	public function not_expired($current_time = NULL)
12
	{
13
		return $this
14 1
			->where_open()
15 1
				->where('expires_at', '=', NULL)
16 1
				->or_where('expires_at', '>=', date('Y-m-d H:i:s', $current_time ?: time()))
17 1
			->where_close();
18
	}
19
20 1
	public function available()
21
	{
22
		return $this
23 1
			->join('purchases', 'LEFT')
24 1
			->where_open()
25 1
				->where('allow_multiple', '=', TRUE)
26 1
				->or_where('purchase.id', '=', NULL)
27 1
			->where_close();
28
	}
29
30 1
	public function available_for_purchase(Model_Purchase $purchase)
31
	{
32
		return $this
33 1
			->join('purchases', 'LEFT')
34 1
			->where_open()
35 1
				->where('allow_multiple', '=', TRUE)
36 1
				->or_where('purchase.id', '=', NULL)
37 1
				->or_where('purchase.id', '=', $purchase->id())
38 1
			->where_close();
39
	}
40
}
41