ContextPlugin::init()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 4 Features 0
Metric Value
c 4
b 4
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace PEIP\ABS\Context;
4
5
/*
6
 * This file is part of the PEIP package.
7
 * (c) 2009-2016 Timo Michna <timomichna/yahoo.de>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
/*
14
 * PEIP\ABS\Context\ContextPlugin
15
 * Abstract base class for all context plugins.
16
 *
17
 * @author Timo Michna <timomichna/yahoo.de>
18
 * @package PEIP
19
 * @subpackage context
20
 * @implements \PEIP\INF\Context\ContextPlugin
21
 */
22
23
use PEIP\Context\XMLContext;
24
use PEIP\Factory\ServiceFactory;
25
26
abstract class ContextPlugin implements \PEIP\INF\Context\ContextPlugin
27
{
28
    protected $context;
29
30
    protected $builders = [];
31
32
    //protected static $builders = array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
33
34
    /**
35
     * Initializes the plugin with given context.
36
     * Registers node-builders of the plugin in with the given context.
37
     *
38
     * @param \PEIP\INF\Context\Context $context context instance to register the plugin with
39
     *
40
     * @return
41
     */
42
    public function init(\PEIP\INF\Context\Context $context)
43
    {
44
        $this->context = $context;
45
        foreach ($this->builders as $node => $method) {
46
            $context->registerNodeBuilder($node, [$this, $method]);
47
        }
48
    }
49
50
    /**
51
     * Builds and modifies an arbitrary service/object instance from a config-obect.
52
     *
53
     * @see XMLContext::doBuild
54
     * @see XMLContext::modifyService
55
     * @implements \PEIP\INF\Context\Context
56
     *
57
     * @param object $config       configuration object to build a service instance from.
58
     * @param array  $arguments    arguments for the service constructor
59
     * @param string $defaultClass class to create instance for if none is set in config
60
     *
61
     * @return object build and modified srvice instance
62
     */
63
    public function buildAndModify($config, $arguments, $defaultClass = false)
64
    {
65
        return ServiceFactory::buildAndModify($config, $arguments, $defaultClass);
0 ignored issues
show
Documentation introduced by
$config is of type object, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Bug introduced by
It seems like $defaultClass defined by parameter $defaultClass on line 63 can also be of type false; however, PEIP\Factory\ServiceFactory::buildAndModify() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
66
    }
67
}
68