Completed
Pull Request — master (#1)
by Rafał
13:36
created

PrefixCandidates   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPrefixes() 0 6 1
A setPathBuilder() 0 4 1
A setRoutePathsNames() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher MultiTenancy Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
namespace SWP\MultiTenancyBundle\Doctrine\PHPCR;
15
16
use SWP\Component\MultiTenancy\PathBuilder\TenantAwarePathBuilderInterface;
17
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\PrefixCandidates as BasePrefixCandidates;
18
19
/**
20
 * Class PrefixCandidates.
21
 */
22
class PrefixCandidates extends BasePrefixCandidates
23
{
24
    /**
25
     * @var TenantAwarePathBuilderInterface
26
     */
27
    protected $pathBuilder;
28
29
    /**
30
     * @var array
31
     */
32
    protected $routePathsNames = [];
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getPrefixes()
38
    {
39
        $this->idPrefixes = $this->pathBuilder->build($this->routePathsNames);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->pathBuilder->build($this->routePathsNames) can also be of type string. However, the property $idPrefixes is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
40
41
        return $this->idPrefixes;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->idPrefixes; of type string|array adds the type string to the return on line 41 which is incompatible with the return type of the parent method Symfony\Cmf\Bundle\Routi...Candidates::getPrefixes of type array.
Loading history...
42
    }
43
44
    /**
45
     * Sets path builder.
46
     *
47
     * @param TenantAwarePathBuilderInterface $pathBuilder
48
     */
49
    public function setPathBuilder(TenantAwarePathBuilderInterface $pathBuilder)
50
    {
51
        $this->pathBuilder = $pathBuilder;
52
    }
53
54
    /**
55
     * @param array $routePathsNames
56
     */
57
    public function setRoutePathsNames(array $routePathsNames = [])
58
    {
59
        $this->routePathsNames = $routePathsNames;
60
    }
61
}
62