edit_block   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 54
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get_extension() 0 6 1
A execute() 0 31 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\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 4
	public function execute($style_id)
23
	{
24 4
		$this->translator->add_lang('css_presets', 'blitze/sitemaker');
25 4
		$this->translator->add_lang('posting');
26
27 4
		$block_id = $this->request->variable('id', 0);
28
29 4
		$cfg_handler = $this->phpbb_container->get('blitze.sitemaker.blocks.cfg_handler');
30 4
		$block_mapper = $this->mapper_factory->create('blocks');
31
32
		/** @var \blitze\sitemaker\model\entity\block $entity */
33 4
		if (($entity = $block_mapper->load(array('bid', '=', $block_id))) === null)
34 4
		{
35 1
			throw new \blitze\sitemaker\exception\out_of_bounds('bid');
36
		}
37
38 3
		if (($block_instance = $this->block_factory->get_block($entity->get_name())) === null)
39 3
		{
40 1
			throw new \blitze\sitemaker\exception\invalid_argument(array($entity->get_name(), 'SERVICE_NOT_FOUND'));
41
		}
42
43 2
		$default_settings = $block_instance->get_config($entity->get_settings());
44
45 2
		$extension = $this->get_extension($block_instance);
46
47 2
		$this->translator->add_lang('blocks_admin', $extension);
48
49 2
		return array_merge(array(
50 2
				'form' => $cfg_handler->get_edit_form($entity->to_array(), $default_settings),
51 2
			),
52 2
			$this->render_block($entity)
53 2
		);
54
	}
55
56
	/**
57
	 * @param \blitze\sitemaker\services\blocks\driver\block_interface $block_instance
58
	 * @return string
59
	 */
60 2
	protected function get_extension(\blitze\sitemaker\services\blocks\driver\block_interface $block_instance)
61
	{
62 2
		$class_name = get_class($block_instance);
63 2
		list($namespace, $extension) = explode('\\', $class_name);
64
65 2
		return $namespace . '/' . $extension;
66
	}
67
}
68