Passed
Push — develop ( f31b27...ac6bc8 )
by Jens
03:16
created

BricksRouting::__construct()   D

Complexity

Conditions 10
Paths 8

Size

Total Lines 34
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
c 0
b 0
f 0
cc 10
eloc 29
nc 8
nop 3
rs 4.8196

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * User: jensk
4
 * Date: 30-1-2017
5
 * Time: 13:27
6
 */
7
8
namespace library\components\cms\configuration;
9
10
11
use library\cc\Request;
12
use library\components\cms\CmsRouting;
13
use library\components\CmsComponent;
14
15
class BricksRouting implements CmsRouting
16
{
17
18
	/**
19
	 * CmsRouting constructor.
20
	 *
21
	 * @param Request      $request
22
	 * @param string       $relativeCmsUri
23
	 * @param CmsComponent $cmsComponent
24
	 */
25
	public function __construct($request, $relativeCmsUri, $cmsComponent)
26
	{
27
		if ($relativeCmsUri == '/configuration/bricks') {
28
			$cmsComponent->subTemplate = 'cms/configuration/bricks';
29
			$cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION);
30
			$cmsComponent->setParameter(CmsComponent::PARAMETER_BRICKS, $cmsComponent->storage->getBricks());
31
		} elseif ($relativeCmsUri == '/configuration/bricks/new') {
32
			$cmsComponent->subTemplate = 'cms/configuration/bricks-form';
33
			$cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION);
34
			if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) {
35
				$cmsComponent->storage->addBrick($request::$post);
36
				header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/bricks');
37
				exit;
38
			}
39
		} elseif ($relativeCmsUri == '/configuration/bricks/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
40
			$cmsComponent->subTemplate = 'cms/configuration/bricks-form';
41
			$cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION);
42
			$brick = $cmsComponent->storage->getBrickBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]);
43
			if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE])) {
44
				$cmsComponent->storage->saveBrick($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post);
45
				header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/bricks');
46
				exit;
47
			}
48
			$cmsComponent->setParameter(CmsComponent::PARAMETER_BRICK, $brick);
49
		} elseif ($relativeCmsUri == '/configuration/bricks/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
50
			$cmsComponent->storage->deleteBrickBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]);
51
			header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/configuration/bricks');
52
			exit;
53
		} elseif ($relativeCmsUri == '/configuration/image-set') {
54
			$cmsComponent->subTemplate = 'cms/configuration/image-set';
55
			$cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_CONFIGURATION);
56
			$cmsComponent->setParameter(CmsComponent::PARAMETER_IMAGE_SET, $cmsComponent->storage->getImageSet());
57
		}
58
	}
59
}