Completed
Push — develop ( de7659...415144 )
by Daniel
09:44
created

add_item::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2.0023

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 20
ccs 11
cts 12
cp 0.9167
rs 9.4285
cc 2
eloc 10
nc 2
nop 0
crap 2.0023
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 1
	public function execute()
19
	{
20 1
		$menu_id = $this->request->variable('menu_id', 0);
21
22 1
		$menu_mapper = $this->mapper_factory->create('menus', 'menus');
23 1
		$items_mapper = $this->mapper_factory->create('menus', 'items');
24
25 1
		if ($menu_mapper->load(array('menu_id', '=', $menu_id)) === null)
26 1
		{
27
			throw new \blitze\sitemaker\exception\out_of_bounds('MENU_NOT_FOUND');
28
		}
29
30 1
		$entity = $items_mapper->create_entity(array(
31 1
			'menu_id'	=> $menu_id,
32 1
		));
33
34 1
		$entity = $items_mapper->save($entity);
35
36 1
		return $entity->to_array();
37
	}
38
}
39