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.

ServiceManagerFactory::setApplicationConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace MpaFirephpWrapperTest\Util;
21
22
use Zend\Mvc\Service\ServiceManagerConfig;
23
use Zend\ServiceManager\ServiceManager;
24
25
/**
26
 * Base test case to be used when a new service manager instance is required
27
 *
28
 * @license MIT
29
 * @link    https://github.com/zf-fr/ZfrRest
30
 * @author  Marco Pivetta <[email protected]>
31
 */
32
abstract class ServiceManagerFactory
33
{
34
    /**
35
     * @var array
36
     */
37
    private static $config = [];
38
39
    /**
40
     * @static
41
     * @param array $config
42
     */
43
    public static function setApplicationConfig(array $config)
44
    {
45
        static::$config = $config;
0 ignored issues
show
Bug introduced by
Since $config is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $config to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
46
    }
47
48
    /**
49
     * @static
50
     * @return array
51
     */
52
    public static function getApplicationConfig()
53
    {
54
        return static::$config;
0 ignored issues
show
Bug introduced by
Since $config is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $config to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
55
    }
56
57
    /**
58
     * @param  array|null $config
59
     * @return ServiceManager
60
     */
61
    public static function getServiceManager(array $config = null)
62
    {
63
        $config         = $config ? : static::getApplicationConfig();
64
        $serviceManager = new ServiceManager(
65
            new ServiceManagerConfig(
66
                isset($config['service_manager']) ? $config['service_manager'] : []
67
            )
68
        );
69
        $serviceManager->setService('ApplicationConfig', $config);
70
71
        /* @var $moduleManager \Zend\ModuleManager\ModuleManagerInterface */
72
        $moduleManager = $serviceManager->get('ModuleManager');
73
74
        $moduleManager->loadModules();
75
76
        return $serviceManager;
77
    }
78
}
79