Completed
Push — develop ( b4fd40...785f8f )
by greg
03:10
created

Website::setServiceManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace PlaygroundCore\Service;
4
5
use Zend\ServiceManager\ServiceManager;
6
use ZfcBase\EventManager\EventProvider;
7
use PlaygroundCore\Options\ModuleOptions;
8
use Zend\ServiceManager\ServiceLocatorInterface;
9
10 View Code Duplication
class Website extends EventProvider
0 ignored issues
show
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...
11
{
12
13
    /**
14
     * @var websiteMapper
15
     */
16
    protected $websiteMapper;
17
18
    /**
19
     * @var UserServiceOptionsInterface
20
     */
21
    protected $options;
22
23
    /**
24
     *
25
     * @var ServiceManager
26
     */
27
    protected $serviceLocator;
28
29
    public function __construct(ServiceLocatorInterface $locator)
30
    {
31
        $this->serviceLocator = $locator;
0 ignored issues
show
Documentation Bug introduced by
$locator is of type object<Zend\ServiceManag...erviceLocatorInterface>, but the property $serviceLocator was declared to be of type object<Zend\ServiceManager\ServiceManager>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof 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 given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
32
    }
33
34
    /**
35
     * getWebsiteMapper
36
     *
37
     * @return websiteMapper
38
     */
39
    public function getWebsiteMapper()
40
    {
41
        if (null === $this->websiteMapper) {
42
            $this->websiteMapper = $this->serviceLocator->get('playgroundcore_website_mapper');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->serviceLocator->g...ndcore_website_mapper') can also be of type array. However, the property $websiteMapper is declared as type object<PlaygroundCore\Service\websiteMapper>. 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...
43
        }
44
45
        return $this->websiteMapper;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->websiteMapper; of type object|array adds the type array to the return on line 45 which is incompatible with the return type documented by PlaygroundCore\Service\Website::getWebsiteMapper of type PlaygroundCore\Service\websiteMapper.
Loading history...
46
    }
47
48
    /**
49
     * setWebsiteMapper
50
     * @param  Mapper/Website $websiteMapper
0 ignored issues
show
Documentation introduced by
The doc-type Mapper/Website could not be parsed: Unknown type name "Mapper/Website" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
51
     *
52
     * @return PlaygroundCore\Entity\WebsiteMapper websiteMapper
53
     */
54
    public function setWebsiteMapper($websiteMapper)
55
    {
56
        $this->websiteMapper = $websiteMapper;
57
58
        return $this;
59
    }
60
61
    /**
62
     * setOptions
63
     * @param  ModuleOptions $options
64
     *
65
     * @return PlaygroundCore\Service\Website $this
66
     */
67
    public function setOptions(ModuleOptions $options)
68
    {
69
        $this->options = $options;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options of type object<PlaygroundCore\Options\ModuleOptions> is incompatible with the declared type object<PlaygroundCore\Se...erviceOptionsInterface> of property $options.

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...
70
71
        return $this;
72
    }
73
74
    /**
75
     * getOptions
76
     *
77
     * @return ModuleOptions $optins
78
     */
79
    public function getOptions()
80
    {
81
        if (!$this->options instanceof ModuleOptions) {
82
            $this->setOptions($this->serviceLocator->get('playgroundcore_module_options'));
0 ignored issues
show
Documentation introduced by
$this->serviceLocator->g...ndcore_module_options') is of type object|array, but the function expects a object<PlaygroundCore\Options\ModuleOptions>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
83
        }
84
85
        return $this->options;
86
    }
87
}
88