Passed
Branch develop (786e4f)
by Daniel
07:32
created

add_item::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 2
nop 0
dl 0
loc 23
ccs 15
cts 15
cp 1
crap 2
rs 9.0856
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2013 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\services\menus\action;
11
12
class add_item extends base_action
13
{
14
	/**
15
	 * {@inheritdoc}
16
	 * @throws \blitze\sitemaker\exception\out_of_bounds
17
	 */
18 2
	public function execute()
19
	{
20 2
		$menu_id = $this->request->variable('menu_id', 0);
21
22 2
		$menu_mapper = $this->mapper_factory->create('menus');
23 2
		$items_mapper = $this->mapper_factory->create('items');
24
25 2
		if ($menu_mapper->load(array('menu_id', '=', $menu_id)) === null)
26 2
		{
27 1
			throw new \blitze\sitemaker\exception\out_of_bounds('menu_id');
28
		}
29
30 1
		$entity = $items_mapper->create_entity(array(
31 1
			'menu_id'		=> $menu_id,
32 1
			'item_title'	=> $this->request->variable('item_title', '', true),
33 1
			'item_url'		=> $this->request->variable('item_url', ''),
34 1
			'item_target'	=> $this->request->variable('item_target', 0),
35 1
		));
36
37
		/** @var \blitze\sitemaker\model\entity\item $entity */
38 1
		$entity = $items_mapper->save($entity);
39
40 1
		return $entity->to_array();
41
	}
42
}
43