ScalarDefinition   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 58.33%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
cbo 1
dl 0
loc 67
ccs 7
cts 12
cp 0.5833
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A invoke() 0 4 1
A getValue() 0 4 1
A setValue() 0 4 1
A factory() 0 4 1
1
<?php
2
/**
3
 * Fwk
4
 *
5
 * Copyright (c) 2011-2016, Julien Ballestracci <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
12
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
15
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
16
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
17
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
21
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
 * POSSIBILITY OF SUCH DAMAGE.
23
 *
24
 * PHP Version 5.3
25
 *
26
 * @category  DependencyInjection
27
 * @package   Fwk\Di
28
 * @author    Julien Ballestracci <[email protected]>
29
 * @copyright 2011-2016 Julien Ballestracci <[email protected]>
30
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
31
 * @link      http://fwk.io/di
32
 */
33
namespace Fwk\Di\Definitions;
34
35
use Fwk\Di\Container;
36
use Fwk\Di\DefinitionInterface;
37
38
/**
39
 * ScalarDefinition
40
 * 
41
 * Represents a scalar-typed definition: string, integer, boolean, float
42
 *
43
 * @category Definition
44
 * @package  Fwk\Di
45
 * @author   Julien Ballestracci <[email protected]>
46
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD License
47
 * @link     http://fwk.io/di
48
 */
49
class ScalarDefinition extends AbstractDefinition implements DefinitionInterface
50
{
51
    /**
52
     * The value
53
     * @var mixed
54
     */
55
    protected $value;
56
    
57
    /**
58
     * Constructor
59
     * 
60
     * @param mixed $value     The scalar value
61
     *
62
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
63
     */
64 39
    public function __construct($value)
65
    {
66 39
        $this->value = $value;
67 39
    }
68
    
69
    /**
70
     * Calls $this->callable and return its value
71
     * 
72
     * @param Container   $container The Di Container
73
     * @param null|string $name      Name of the definition (if any)
74
     * 
75
     * @return array<mixed>
76
     */
77 6
    public function invoke(Container $container, $name = null)
78
    {
79 6
        return $this->value;
80
    }
81
    
82
    /**
83
     * Returns the value
84
     * 
85
     * @return mixed
86
     */
87
    public function getValue()
88
    {
89
        return $this->value;
90
    }
91
    
92
    /**
93
     * Defines the array
94
     * 
95
     * @param mixed $value The scalar-typed value
96
     * 
97
     * @return void
98
     */
99
    public function setValue($value)
100
    {
101
        $this->value = $value;
102
    }
103
104
    /**
105
     * Factory
106
     *
107
     * @param mixed $value The scalar-typed definition
108
     *
109
     * @return ScalarDefition
0 ignored issues
show
Documentation introduced by
Should the return type not be ScalarDefinition?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
110
     */
111 39
    public static function factory($value)
112
    {
113 39
        return new static($value);
114
    }
115
}