types   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 78
ccs 34
cts 34
cp 1
rs 10
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A find_fields() 0 13 2
A delete() 0 9 2
A find() 0 17 3
A load() 0 11 2
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2016 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\content\model\mapper;
11
12
use blitze\sitemaker\model\base_mapper;
0 ignored issues
show
Bug introduced by
The type blitze\sitemaker\model\base_mapper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
class types extends base_mapper
15
{
16
	/** @var string */
17
	protected $entity_class = 'blitze\content\model\entity\type';
18
19
	/** @var string */
20
	protected $entity_pkey = 'content_id';
21
22
	/**
23
	 * {@inheritdoc}
24
	 */
25 3
	public function load(array $condition = array())
26
	{
27 3
		$entity = parent::load($condition);
28
29
		if ($entity)
30 3
		{
31 3
			$fields = $this->find_fields($entity->get_content_id());
32 3
			$entity->set_content_fields(array_pop($fields));
33 3
		}
34
35 3
		return $entity;
36
	}
37
38
	/**
39
	 * {@inheritdoc}
40
	 */
41 20
	public function find(array $condition = array())
42
	{
43 20
		parent::find($condition);
44
45 20
		if ($this->collection->count())
46 20
		{
47 20
			$content_fields = $this->find_fields(array_keys($this->collection->get_entities()));
48
49 20
			foreach ($content_fields as $content_id => $fields)
50
			{
51 20
				/** @var \blitze\content\model\entity\type $entity */
52 20
				$entity = &$this->collection[$content_id];
53 20
				$entity->set_content_fields($fields);
54
			}
55 20
		}
56
57
		return $this->collection;
58
	}
59
60
	/**
61 2
	 * {@inheritdoc}
62
	 */
63
	public function delete($entity)
64 2
	{
65
		/** @var \blitze\content\model\entity\type $entity */
66 2
		parent::delete($entity);
67 2
68 2
		if ($entity instanceof $this->entity_class)
69 2
		{
70 2
			$fields_mapper = $this->mapper_factory->create('fields');
71 2
			$fields_mapper->delete(array('content_id', '=', $entity->get_content_id()));
72
		}
73
	}
74
75
	/**
76
	 * @param int|array $content_ids
77 22
	 * @return array
78
	 */
79 22
	protected function find_fields($content_ids)
80 22
	{
81
		$fields_mapper = $this->mapper_factory->create('fields');
82 22
		$collection = $fields_mapper->find(array('content_id', '=', $content_ids));
83 22
84
		$content_fields = array();
85 22
		foreach ($collection as $entity)
86 22
		{
87 22
			$content_id = $entity->get_content_id();
88
			$content_fields[$content_id][$entity->get_field_name()] = $entity->to_array();
89 22
		}
90
91
		return $content_fields;
92
	}
93
}
94