Completed
Push — ezp25003-trash_subitems_count_... ( c4ee15...9f71a1 )
by
unknown
60:38 queued 26:57
created

LocationMatcherFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 60
loc 60
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setContainer() 4 4 1
A __construct() 14 14 1
A getMatcher() 8 8 2
A setSiteAccess() 8 8 2

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
 * File containing the LocationMatcherFactory 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
 * @version //autogentag//
10
 */
11
namespace eZ\Bundle\EzPublishCoreBundle\Matcher;
12
13
use eZ\Publish\API\Repository\Repository;
14
use eZ\Publish\Core\MVC\ConfigResolverInterface;
15
use eZ\Publish\Core\MVC\Symfony\Matcher\LocationMatcherFactory as BaseMatcherFactory;
16
use eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessAware;
17
use eZ\Publish\Core\MVC\Symfony\SiteAccess;
18
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
19
use Symfony\Component\DependencyInjection\ContainerInterface;
20
21
/**
22
 * @deprecated Deprecated since 6.0, will be removed in 6.1. Location view in general is deprecated. Use content view instead.
23
 */
24 View Code Duplication
class LocationMatcherFactory extends BaseMatcherFactory implements SiteAccessAware, ContainerAwareInterface
0 ignored issues
show
Deprecated Code introduced by
The class eZ\Publish\Core\MVC\Symf...\LocationMatcherFactory has been deprecated with message: since 6.0 location view in general is deprecated. Use content view instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
Duplication introduced by
This class seems to be duplicated in 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...
25
{
26
    /**
27
     * @var \Symfony\Component\DependencyInjection\ContainerInterface
28
     */
29
    private $container;
30
31
    /**
32
     * @var \eZ\Publish\Core\MVC\ConfigResolverInterface;
33
     */
34
    private $configResolver;
35
36
    public function __construct(ConfigResolverInterface $configResolver, Repository $repository)
37
    {
38
        @trigger_error(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
39
            "Location view has been deprecated in 6.0, and will be removed in 6.1.\n" .
40
            'Use content view instead.',
41
            E_USER_DEPRECATED
42
        );
43
44
        $this->configResolver = $configResolver;
45
        parent::__construct(
46
            $repository,
47
            $this->configResolver->getParameter('location_view')
48
        );
49
    }
50
51
    public function setContainer(ContainerInterface $container = null)
52
    {
53
        $this->container = $container;
54
    }
55
56
    /**
57
     * @param string $matcherIdentifier
58
     *
59
     * @return \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MatcherInterface
60
     */
61
    protected function getMatcher($matcherIdentifier)
62
    {
63
        if ($this->container->has($matcherIdentifier)) {
64
            return $this->container->get($matcherIdentifier);
65
        }
66
67
        return parent::getMatcher($matcherIdentifier);
68
    }
69
70
    /**
71
     * Changes internal configuration to use the one for passed SiteAccess.
72
     *
73
     * @param SiteAccess $siteAccess
74
     */
75
    public function setSiteAccess(SiteAccess $siteAccess = null)
76
    {
77
        if ($siteAccess === null) {
78
            return;
79
        }
80
81
        $this->matchConfig = $this->configResolver->getParameter('location_view', 'ezsettings', $siteAccess->name);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->configResolver->g...gs', $siteAccess->name) of type * is incompatible with the declared type array of property $matchConfig.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
82
    }
83
}
84