Passed
Push — develop ( 917e37...ca2d13 )
by Jens
02:20
created

SitemapRouting::__construct()   D

Complexity

Conditions 10
Paths 8

Size

Total Lines 33
Code Lines 27

Duplication

Lines 10
Ratio 30.3 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
eloc 27
c 1
b 0
f 0
nc 8
nop 3
dl 10
loc 33
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
 * Created by IntelliJ IDEA.
4
 * User: Jens
5
 * Date: 29-1-2017
6
 * Time: 16:30
7
 */
8
9
namespace library\components\cms;
10
11
12
use library\components\CmsComponent;
13
14
class SitemapRouting
15
{
16
17
    /**
18
     * SitemapRouting constructor.
19
     * @param \library\cc\Request $request
20
     * @param mixed|string $relativeCmsUri
21
     * @param CmsComponent $cmsComponent
22
     */
23
    public function __construct($request, $relativeCmsUri, $cmsComponent)
24
    {
25
        if ($relativeCmsUri == '/sitemap') {
26
            $cmsComponent->subTemplate = 'cms/sitemap';
27
            if (isset($request::$post[CmsComponent::POST_PARAMETER_SAVE])) {
28
                $cmsComponent->storage->saveSitemap($request::$post);
29
            }
30
            $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_SITEMAP);
31
            $cmsComponent->setParameter(CmsComponent::PARAMETER_SITEMAP, $cmsComponent->storage->getSitemap());
32
        } elseif ($relativeCmsUri == '/sitemap/new') {
33
            $cmsComponent->subTemplate = 'cms/sitemap/form';
34
            $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_SITEMAP);
35 View Code Duplication
            if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post[CmsComponent::POST_PARAMETER_TEMPLATE], $request::$post[CmsComponent::POST_PARAMETER_COMPONENT])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
                $cmsComponent->storage->addSitemapItem($request::$post);
37
                header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/sitemap');
38
                exit;
39
            }
40
        } elseif ($relativeCmsUri == '/sitemap/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
41
            $cmsComponent->subTemplate = 'cms/sitemap/form';
42
            $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_SITEMAP);
43
            $sitemapItem = $cmsComponent->storage->getSitemapItemBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]);
44 View Code Duplication
            if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post[CmsComponent::POST_PARAMETER_TEMPLATE], $request::$post[CmsComponent::POST_PARAMETER_COMPONENT])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
                $cmsComponent->storage->saveSitemapItem($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post);
46
                header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/sitemap');
47
                exit;
48
            }
49
            $cmsComponent->setParameter(CmsComponent::PARAMETER_SITEMAP_ITEM, $sitemapItem);
50
        } elseif ($relativeCmsUri == '/sitemap/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
51
            $cmsComponent->storage->deleteSitemapItemBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]);
52
            header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/sitemap');
53
            exit;
54
        }
55
    }
56
}