Completed
Push — develop ( 1aadc7...f2612d )
by
unknown
25:44 queued 16:02
created

Module   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 4 1
A getAutoloaderConfig() 0 18 1
A onBootstrap() 0 9 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2015 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Install;
12
13
use Zend\ModuleManager\Feature;
14
use Zend\EventManager\EventInterface;
15
16
/**
17
 * Module "Install" initialization.
18
 *
19
 * @author Mathias Gelhausen <[email protected]>
20
 * @since 0.20
21
 */
22
class Module implements Feature\AutoloaderProviderInterface, Feature\ConfigProviderInterface, Feature\BootstrapListenerInterface
23
{
24
25
    public function getConfig()
26
    {
27
        return include __DIR__ . '/config/module.config.php';
28
    }
29
30
    public function getAutoloaderConfig()
31
    {
32
        return array(
33
            'Zend\Loader\ClassMapAutoloader' => array(
34
                __DIR__ . '/autoload_classmap.php',
35
                array(
36
                    // We need this filter for initial user creation.
37
                    'Auth\Entity\Filter\CredentialFilter' => __DIR__ . '/../Auth/src/Auth/Entity/Filter/CredentialFilter.php',
38
                ),
39
            ),
40
            'Zend\Loader\StandardAutoloader' => array(
41
                'namespaces' => array(
42
                    __NAMESPACE__ => __DIR__ . '/src' /* . __NAMESPACE__*/,
43
                    __NAMESPACE__ . 'Test' => __DIR__ . '/test/' . __NAMESPACE__ . 'Test',
44
                ),
45
            ),
46
        );
47
    }
48
49
    /**
50
     * Listen to the bootstrap event.
51
     *
52
     * @param EventInterface|\Zend\Mvc\MvcEvent $e
53
     *
54
     * @return void
55
     */
56
    public function onBootstrap(EventInterface $e)
57
    {
58
        $application  = $e->getApplication();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Zend\EventManager\EventInterface as the method getApplication() does only exist in the following implementations of said interface: Zend\Mvc\MvcEvent.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
59
        $eventManager = $application->getEventManager();
60
        $services     = $application->getServiceManager();
61
62
        $services->get('Install/Listener/LanguageSetter')
63
                 ->attach($eventManager);
64
    }
65
}
66