Completed
Push — master ( 4e0ac6...0fdc9b )
by Łukasz
25:36
created

URLAliasService   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 82
Duplicated Lines 34.15 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 28
loc 82
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 2

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A createUrlAlias() 0 4 1
A createGlobalUrlAlias() 0 4 1
A listLocationAliases() 15 15 1
A listGlobalAliases() 0 4 1
A removeAliases() 0 4 1
A lookup() 0 4 1
A reverseLookup() 13 13 1
A load() 0 4 1

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
/**
4
 * URLAliasService class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Repository\SiteAccessAware;
10
11
use eZ\Publish\API\Repository\URLAliasService as URLAliasServiceInterface;
12
use eZ\Publish\API\Repository\Values\Content\Location;
13
use eZ\Publish\Core\Repository\SiteAccessAware\Language\LanguageResolver;
14
15
/**
16
 * SiteAccess aware implementation of URLAliasService injecting languages where needed.
17
 */
18
class URLAliasService implements URLAliasServiceInterface
19
{
20
    /** @var \eZ\Publish\API\Repository\URLAliasService */
21
    protected $service;
22
23
    /** @var \eZ\Publish\Core\Repository\SiteAccessAware\Language\LanguageResolver */
24
    protected $languageResolver;
25
26
    /**
27
     * Construct service object from aggregated service and LanguageResolver.
28
     *
29
     * @param \eZ\Publish\API\Repository\URLAliasService $service
30
     * @param \eZ\Publish\Core\Repository\SiteAccessAware\Language\LanguageResolver $languageResolver
31
     */
32
    public function __construct(
33
        URLAliasServiceInterface $service,
34
        LanguageResolver $languageResolver
35
    ) {
36
        $this->service = $service;
37
        $this->languageResolver = $languageResolver;
38
    }
39
40
    public function createUrlAlias(Location $location, $path, $languageCode, $forwarding = false, $alwaysAvailable = false)
41
    {
42
        return $this->service->createUrlAlias($location, $path, $languageCode, $forwarding, $alwaysAvailable);
43
    }
44
45
    public function createGlobalUrlAlias($resource, $path, $languageCode, $forwarding = false, $alwaysAvailable = false)
46
    {
47
        return $this->service->createGlobalUrlAlias($resource, $path, $languageCode, $forwarding, $alwaysAvailable);
48
    }
49
50 View Code Duplication
    public function listLocationAliases(
51
        Location $location,
52
        $custom = true,
53
        $languageCode = null,
54
        bool $showAllTranslations = null,
55
        array $prioritizedLanguages = null
56
    ) {
57
        return $this->service->listLocationAliases(
58
            $location,
59
            $custom,
60
            $languageCode,
61
            $this->languageResolver->getShowAllTranslations($showAllTranslations),
62
            $this->languageResolver->getPrioritizedLanguages($prioritizedLanguages)
63
        );
64
    }
65
66
    public function listGlobalAliases($languageCode = null, $offset = 0, $limit = -1)
67
    {
68
        return $this->service->listGlobalAliases($languageCode, $offset, $limit);
69
    }
70
71
    public function removeAliases(array $aliasList)
72
    {
73
        return $this->service->removeAliases($aliasList);
74
    }
75
76
    public function lookup($url, $languageCode = null)
77
    {
78
        return $this->service->lookup($url, $languageCode);
79
    }
80
81 View Code Duplication
    public function reverseLookup(
82
        Location $location,
83
        $languageCode = null,
84
        bool $showAllTranslations = null,
85
        array $prioritizedLanguages = null
86
    ) {
87
        return $this->service->reverseLookup(
88
            $location,
89
            $languageCode,
90
            $this->languageResolver->getShowAllTranslations($showAllTranslations),
91
            $this->languageResolver->getPrioritizedLanguages($prioritizedLanguages)
92
        );
93
    }
94
95
    public function load($id)
96
    {
97
        return $this->service->load($id);
98
    }
99
}
100