Completed
Push — master ( 7d425f...c84cb4 )
by Haralan
16:06 queued 10:38
created

Kohana_Jam_Association_Autocreate   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90%
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 42
ccs 18
cts 20
cp 0.9
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C set() 0 25 8
1
<?php defined('SYSPATH') OR die('No direct script access.');
2
3
/**
4
 * Creates the record if it does not exist and is a string
5
 *
6
 * @package    Jam
7
 * @category   Associations
8
 * @author     Ivan Kerin
9
 * @copyright  (c) 2013 Despark Ltd.
10
 * @license    http://www.opensource.org/licenses/isc-license.txt
11
 */
12
abstract class Kohana_Jam_Association_Autocreate extends Jam_Association_Belongsto {
13
14
	/**
15
	 * @deprecated Use $additional_fields instead
16
	 * Will be removed in 0.6
17
	 * @var array
18
	 */
19
	public $default_fields = array();
20
21
	/**
22
	 * Additional fields to search for existing entry by.
23
	 * They get set if a new entry is autocreated.
24
	 * @var array
25
	 */
26
	public $additional_fields = array();
27
28 4
	public function set(Jam_Validated $model, $value, $is_changed)
29
	{
30 4
		if ($is_changed AND $value AND is_string($value) AND ! is_numeric($value))
31 4
		{
32 2
			if ($this->default_fields AND ! $this->additional_fields)
0 ignored issues
show
Deprecated Code introduced by
The property Kohana_Jam_Association_Autocreate::$default_fields has been deprecated with message: Use $additional_fields instead
Will be removed in 0.6

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
33 2
			{
34
				$this->additional_fields = $this->default_fields;
0 ignored issues
show
Deprecated Code introduced by
The property Kohana_Jam_Association_Autocreate::$default_fields has been deprecated with message: Use $additional_fields instead
Will be removed in 0.6

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
35
			}
36
37 2
			if (! is_array($this->additional_fields))
38 2
			{
39 1
				$this->additional_fields = array();
40 1
			}
41
42 2
			$value = Jam::find_or_create(
43 2
				$this->foreign_model,
44 2
				array_merge(
45 2
					array(':name_key' => $value),
46 2
					$this->additional_fields
47 2
				)
48 2
			);
49 2
		}
50
51 4
		return parent::set($model, $value, $is_changed);
52
	}
53
}
54