update_block::execute()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 3
nop 1
dl 0
loc 25
ccs 17
cts 17
cp 1
crap 3
rs 9.8333
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\blocks\action;
11
12
class update_block extends base_action
13
{
14
	/**
15
	 * {@inheritdoc}
16
	 * @throws \blitze\sitemaker\exception\out_of_bounds
17
	 */
18 4
	public function execute($style_id)
19
	{
20 4
		$block_id = $this->request->variable('id', 0);
21 4
		$field = $this->request->variable('field', 'icon');
22
23
		$allowed_fields = array(
24 4
			'title'	=> $this->request->variable('title', '', true),
25 4
			'icon'	=> $this->request->variable('icon', ''),
26 4
		);
27
28 4
		$block_mapper = $this->mapper_factory->create('blocks');
29
30 4
		if (($entity = $block_mapper->load(array('bid', '=', $block_id))) === null)
31 4
		{
32 1
			throw new \blitze\sitemaker\exception\out_of_bounds('bid');
33
		}
34
35 3
		if (isset($allowed_fields[$field]))
36 3
		{
37 2
			$mutator = 'set_' . $field;
38 2
			$entity->$mutator($allowed_fields[$field]);
39 2
			$entity = $block_mapper->save($entity);
40 2
		}
41
42 3
		return $this->render_block($entity);
43
	}
44
}
45