Kohana_Model_Term   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 43
ccs 16
cts 20
cp 0.8
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A only_children() 0 4 1
A unique_key() 0 4 3
A initialize() 0 29 1
1
<?php defined('SYSPATH') OR die('No direct script access.');
2
3
/**
4
 * @author     Ivan Kerin <[email protected]>
5
 * @copyright  (c) 2014 Clippings Ltd.
6
 * @license    http://spdx.org/licenses/BSD-3-Clause
7
 */
8
class Kohana_Model_Term extends Jam_Model
9
{
10 1
	public static function initialize(Jam_Meta $meta)
11
	{
12
		$meta
13 1
			->table('terms')
14 1
			->name_key('name');
15
16 1
		$meta->behaviors(array(
17 1
			'nested' => Jam::behavior('Nested'),
18 1
			'sluggable' => Jam::behavior('Sluggable', array('uses_primary_key' => FALSE, 'auto_save' => FALSE, 'unique' => TRUE))
19
		));
20
21 1
		$meta->associations(array(
22 1
			'vocabulary' => Jam::association('belongsto', array('inverse_of' => 'terms')),
23
		));
24
25 1
		$meta->fields(array(
26 1
			'id' => Jam::field('primary'),
27 1
			'name' => Jam::field('string'),
28
29 1
			'is_hidden' => Jam::field('boolean', array()),  // whether to show / hide the term
30
31
			// Analytics
32 1
			'created_at' => Jam::field('timestamp', array('auto_now_create' => TRUE, 'format' => 'Y-m-d H:i:s')),
33 1
			'updated_at' => Jam::field('timestamp', array('auto_now_update' => TRUE, 'format' => 'Y-m-d H:i:s')),
34
		));
35
36
		$meta
37 1
			->validator('name', array('present' => TRUE));
38 1
	}
39
40
	public function only_children(array $terms)
41
	{
42
		return $this->children->where('slug', 'IN', $terms);
0 ignored issues
show
Documentation introduced by
The property children does not exist on object<Kohana_Model_Term>. 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...
43
	}
44
45
46
	public static function unique_key($value)
47
	{
48
		return (is_numeric($value) OR $value === NULL) ? 'id' : 'slug';
49
	}
50
}