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

SitemapRouting   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 43
Duplicated Lines 23.26 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 43
rs 10
wmc 10
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
D __construct() 10 33 10

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}