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

edit_block::execute()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 30
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 3.0015

Importance

Changes 6
Bugs 0 Features 1
Metric Value
c 6
b 0
f 1
dl 0
loc 30
ccs 17
cts 18
cp 0.9444
rs 8.8571
cc 3
eloc 14
nc 3
nop 1
crap 3.0015
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 edit_block extends base_action
13
{
14
	/** @var \phpbb\language\language */
15
	protected $translator;
16
17
	/**
18
	 * {@inheritdoc}
19
	 * @throws \blitze\sitemaker\exception\out_of_bounds
20
	 * @throws \blitze\sitemaker\exception\invalid_argument
21
	 */
22 3
	public function execute($style_id)
23
	{
24 3
		$block_id = $this->request->variable('id', 0);
25
26 3
		$cfg_handler = $this->phpbb_container->get('blitze.sitemaker.blocks.cfg_handler');
27 3
		$block_mapper = $this->mapper_factory->create('blocks', 'blocks');
28
29
		/** @type \blitze\sitemaker\model\blocks\entity\block $entity */
30 3
		if (($entity = $block_mapper->load(array('bid', '=', $block_id))) === null)
31 3
		{
32 1
			throw new \blitze\sitemaker\exception\out_of_bounds('BLOCK_NOT_FOUND');
33
		}
34
35 2
		if (($block_instance = $this->block_factory->get_block($entity->get_name())) === null)
36 2
		{
37
			throw new \blitze\sitemaker\exception\invalid_argument(array($name, 'BLOCK_NOT_FOUND'));
38
		}
39
40 2
		$default_settings = $block_instance->get_config($entity->get_settings());
41
42 2
		$extension = $this->get_extension($block_instance);
43
44 2
		$this->translator->add_lang('blocks_admin', $extension);
45
46 2
		return array_merge(array(
47 2
				'form' => $cfg_handler->get_edit_form($entity->to_array(), $default_settings),
48 2
			),
49 2
			$this->render_block($entity)
50 2
		);
51
	}
52
53
	/**
54
	 * @param \blitze\sitemaker\services\blocks\driver\block_interface $block_instance
55
	 * @return string
56
	 */
57 2
	protected function get_extension(\blitze\sitemaker\services\blocks\driver\block_interface $block_instance)
58
	{
59 2
		$class_name = get_class($block_instance);
60 2
		list($namespace, $extension) = explode('\\', $class_name);
61
62 2
		return $namespace . '/' . $extension;
63
	}
64
}
65