Completed
Push — master ( f44bce...b547a8 )
by Filipe
01:54
created

Factory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 36
rs 10
c 0
b 0
f 0
ccs 4
cts 4
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A resolve() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of slick/di package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Di\Definition;
11
12
use Slick\Di\DefinitionInterface;
13
14
/**
15
 * Factory definition allows creation of object with a callable
16
 *
17
 * @package Slick\Di\Definition
18
 * @author  Filipe Silva <[email protected]>
19
 */
20
class Factory extends AbstractDefinition implements DefinitionInterface
21
{
22
    /**
23
     * @var callable
24
     */
25
    protected $callable;
26
27
    /**
28
     * @var array
29
     */
30
    protected $parameters;
31
32
    /**
33
     * Factory needs a name and a callable
34
     *
35
     * @param callable $callable
36
     * @param array    $parameters
37
     */
38
    public function __construct(
39
        callable $callable,
40
        array $parameters = []
41
    ) {
42
        $this->callable = $callable;
43
        $this->parameters = $parameters;
44
    }
45 34
46
    /**
47 34
     * Resolves the definition into a scalar or object
48 34
     *
49 34
     * @return mixed
50
     */
51
    public function resolve()
52
    {
53
        return call_user_func_array($this->callable, $this->parameters);
54
    }
55
}
56