Completed
Pull Request — master (#165)
by Paul
03:21
created

Service   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 2
cbo 0
dl 0
loc 76
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getClassName() 0 4 1
A hasClassName() 0 4 1
A __construct() 0 4 1
A setFactoryMethod() 0 4 1
A getFactoryMethod() 0 4 1
A hasFactoryMethod() 0 4 1
1
<?php
2
/**
3
 * This file is part of the PPI Framework.
4
 *
5
 * @copyright  Copyright (c) 2012 Paul Dragoonis <[email protected]>
6
 * @license    http://opensource.org/licenses/mit-license.php MIT
7
 *
8
 * @link       http://www.ppi.io
9
 */
10
11
namespace PPI\Framework\Module;
12
13
/**
14
 * The PPI Server class. These instances can be registered into the
15
 * ServiceLocator.
16
 *
17
 * @author     Paul Dragoonis <[email protected]>
18
 */
19
class Service
20
{
21
    /**
22
     * The class name for this service.
23
     *
24
     * @var null|string
25
     */
26
    protected $className = null;
27
28
    /**
29
     * Get the factory method name for this service.
30
     *
31
     * @var null|string
32
     */
33
    protected $factoryMethod = null;
34
35
    /**
36
     * Constructor.
37
     *
38
     * @param type $className
39
     */
40
    public function __construct($className = null)
41
    {
42
        $this->className = $className;
0 ignored issues
show
Documentation Bug introduced by
It seems like $className can also be of type object<PPI\Framework\Module\type>. However, the property $className is declared as type null|string. 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
    /**
46
     * Get the class name for this service.
47
     *
48
     * @return null|string
49
     */
50
    public function getClassName()
51
    {
52
        return $this->className;
53
    }
54
55
    /**
56
     * Check if we have a class name for this service.
57
     *
58
     * @return bool
59
     */
60
    public function hasClassName()
61
    {
62
        return $this->className !== null;
63
    }
64
65
    /**
66
     * Set the factory method name.
67
     *
68
     * @param string $method
69
     */
70
    public function setFactoryMethod($method)
71
    {
72
        $this->factoryMethod = $method;
73
    }
74
75
    /**
76
     * Get the factory method name.
77
     *
78
     * @return null|string
79
     */
80
    public function getFactoryMethod()
81
    {
82
        return $this->factoryMethod;
83
    }
84
85
    /**
86
     * Check if we have a factory method name.
87
     *
88
     * @return bool
89
     */
90
    public function hasFactoryMethod()
91
    {
92
        return $this->factoryMethod !== null;
93
    }
94
}
95