GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 8c3ee0...d7f4ea )
by Hong
04:46
created

Factory   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createInstance() 0 20 3
A executeCallable() 0 15 3
A executeMethodBatch() 0 8 2
A executeMethod() 0 12 3
A afterCreation() 0 12 4
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Di
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Di\Factory;
16
17
use Phossa2\Di\Container;
18
use Phossa2\Di\Traits\FactoryTrait;
19
use Phossa2\Shared\Base\ObjectAbstract;
20
use Phossa2\Di\Interfaces\FactoryInterface;
21
22
/**
23
 * Factory
24
 *
25
 * Wrapper of factorying methods for container
26
 *
27
 * @package Phossa2\Di
28
 * @author  Hong Zhang <[email protected]>
29
 * @see     FactoryInterface
30
 * @version 2.0.0
31
 * @since   2.0.0 added
32
 */
33
class Factory extends ObjectAbstract implements FactoryInterface
34
{
35
    use FactoryTrait;
36
37
    /**
38
     * @param  Container $container
39
     * @access public
40
     */
41
    public function __construct(Container $container)
42
    {
43
        $this->master = $container;
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49
    public function createInstance(/*# string */ $rawId, array $arguments)
50
    {
51
        // get definition
52
        $def = $this->getDefinition($rawId, $arguments);
53
54
        // arguments
55
        $args = isset($def['args']) ? $def['args'] : [];
56
57
        if (is_string($def['class'])) {
58
            $obj = $this->constructObject($def['class'], $args);
59
60
        } else {
61
            $obj = $this->executeCallable($def['class'], $args);
62
        }
63
64
        // execute after-creation methods
65
        $this->afterCreation($obj, $def);
66
67
        return $obj;
68
    }
69
70
    /**
71
     * {@inheritDoc}
72
     */
73
    public function executeCallable($callable, array $arguments = [])
74
    {
75
        // not callable
76
        if (!is_callable($callable)) {
77
            return $callable;
78
        }
79
80
        if (!empty($arguments)) {
81
            $params = $this->getCallableParameters($callable);
82
            $args = $this->matchArguments($params, $arguments);
83
            return call_user_func_array($callable, $args);
84
        } else {
85
            return call_user_func($callable);
86
        }
87
    }
88
89
    /**
90
     * {@inheritDoc}
91
     */
92
    public function executeMethodBatch(array $methods, $object = null)
93
    {
94
        $merged = $this->mergeMethods($methods);
95
96
        foreach ($merged as $method) {
97
            $this->executeMethod($method, $object);
98
        }
99
    }
100
101
    /**
102
     * if $object provided, build callable like [$object, $method] and execute it.
103
     *
104
     * method:
105
     * - ['function', [ arguments...]]
106
     *
107
     * - [ callable, [ arguments ...]]
108
     *
109
     * - ['method', [ arguments ...]]
110
     *   convert to [[$object, 'method'], [ ... ]]
111
     *
112
     * @param  mixed method
113
     * @param  object|null $object to construct callable
114
     * @throws LogicException if something goes wrong
115
     * @access protected
116
     */
117
    protected function executeMethod($method, $object = null)
118
    {
119
        $callable  = $method[0];
120
        $arguments = isset($method[1]) ? $method[1] : [];
121
122
        // rebuild callable from $object
123
        if (null !== $object) {
124
            $callable = [$object, $callable];
125
        }
126
127
        $this->executeCallable($callable, $arguments);
128
    }
129
130
    /**
131
     * Things to do after an object created.
132
     *
133
     * @param  object $object
134
     * @param  array $definition service definition for $object
135
     * @access protected
136
     */
137
    protected function afterCreation($object, array $definition)
138
    {
139
        // execute methods of THIS object
140
        if (isset($definition['methods'])) {
141
            $this->executeMethodBatch($definition['methods'], $object);
142
        }
143
144
        // execute common methods for all objects
145
        if (!isset($definition['skip']) || !$definition['skip']) {
146
            $this->executeCommonBatch($object);
147
        }
148
    }
149
}
150