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

edit_block   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 95.45%

Importance

Changes 7
Bugs 0 Features 1
Metric Value
wmc 4
c 7
b 0
f 1
lcom 1
cbo 8
dl 0
loc 53
ccs 21
cts 22
cp 0.9545
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B execute() 0 30 3
A get_extension() 0 7 1
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