update_item   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 31
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 25 3
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 update_item extends base_action
13
{
14
	/**
15
	 * {@inheritdoc}
16
	 * @throws \blitze\sitemaker\exception\out_of_bounds
17
	 */
18 5
	public function execute()
19
	{
20 5
		$item_id = $this->request->variable('item_id', 0);
21 5
		$field = $this->request->variable('field', 'item_icon');
22
23
		$allowed_fields = array(
24 5
			'item_icon'		=> $this->request->variable('item_icon', ''),
25 5
			'item_title'	=> $this->request->variable('item_title', '', true),
26 5
		);
27
28 5
		$item_mapper = $this->mapper_factory->create('items');
29
30 5
		if (($entity = $item_mapper->load(array('item_id', '=', $item_id))) === null)
31 5
		{
32 1
			throw new \blitze\sitemaker\exception\out_of_bounds('item_id');
33
		}
34
35 4
		if (isset($allowed_fields[$field]))
36 4
		{
37 2
			$mutator = 'set_' . $field;
38 2
			$entity->$mutator($allowed_fields[$field]);
39 2
			$item_mapper->save($entity);
40 2
		}
41
42 4
		return $entity->to_array();
43
	}
44
}
45