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 ( 15625b...b1045e )
by Hong
02:42
created

Factory::getObjectByClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
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\Shared\Base\ObjectAbstract;
18
use Phossa2\Di\Exception\LogicException;
19
use Phossa2\Di\Interfaces\FactoryInterface;
20
use Phossa2\Di\Interfaces\ResolverInterface;
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 FactoryHelperTrait;
36
37
    /**
38
     * @param  ResolverInterface
39
     * @access public
40
     */
41
    public function __construct(ResolverInterface $resolver)
42
    {
43
        $this->setResolver($resolver);
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49
    public function createInstance(/*# string */ $rawId, array $arguments)
50
    {
51
        // get service 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
        foreach ($this->mergeMethods($methods) as $method) {
95
            $this->executeMethod($method, $object);
96
        }
97
    }
98
99
    /**
100
     * if $object provided, build callable like [$object, $method] and execute it.
101
     *
102
     * method:
103
     *
104
     * - callable
105
     *
106
     * - array ['function', [ arguments...]]
107
     *
108
     * - array [callable, [ arguments ...]]
109
     *
110
     * - array ['method', [ arguments ...]]
111
     *   will be converted to [[$object, 'method'], [ ... ]]
112
     *
113
     * @param  array|callable method
114
     * @param  object|null $object to construct callable
115
     * @throws LogicException if something goes wrong
116
     * @access protected
117
     */
118
    protected function executeMethod($method, $object = null)
119
    {
120
        // is callable
121
        if (is_callable($method)) {
122
            return $this->executeCallable($method);
123
124
        // is [ method, arguments ]
125
        } elseif (isset($method[0])) {
126
            return $this->executeCallable(
127
                $this->getObjectMethod($object, $method[0]), // callable
128
                isset($method[1]) ? $method[1] : [] // arguments
129
            );
130
        }
131
    }
132
133
    /**
134
     * Things to do after an object created.
135
     *
136
     * @param  object $object
137
     * @param  array $definition service definition for $object
138
     * @access protected
139
     */
140
    protected function afterCreation($object, array $definition)
141
    {
142
        // execute methods of THIS object
143
        if (isset($definition['methods'])) {
144
            $this->executeMethodBatch($definition['methods'], $object);
145
        }
146
147
        // execute common methods for all objects
148
        if (!isset($definition['skip']) || !$definition['skip']) {
149
            $methods = $this->getCommonMethods();
150
            $this->executeMethodBatch($methods, $object);
151
        }
152
    }
153
}
154