Module   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
B onBootstrap() 0 24 1
A onRegister() 0 15 2
A getConfig() 0 4 1
A getAutoloaderConfig() 0 10 1
A getConsoleUsage() 0 15 1
A getInstallService() 0 4 1
1
<?php
2
3
namespace JhFlexiTime;
4
5
use Symfony\Component\Config\Definition\Exception\Exception;
6
use Zend\ModuleManager\Feature\ConfigProviderInterface;
7
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
8
use Zend\EventManager\EventInterface;
9
use Zend\Console\Adapter\AdapterInterface as Console;
10
use JhInstaller\Install\Installable;
11
use JhInstaller\Install\Exception as InstallException;
12
13
/**
14
 * JhFlexiTime Module
15
 * 
16
 * @author Ben Lill <[email protected]>
17
 */
18
class Module implements
19
    ConfigProviderInterface,
20
    AutoloaderProviderInterface,
21
    Installable
22
{
23
24
    public function onBootstrap(EventInterface $e)
25
    {
26
        $sl             = $e->getTarget()->getServiceManager();
27
        $eventManager   = $e->getTarget()->getEventManager();
28
        $eventManager->attach($sl->get('JhFlexiTime\Listener\BookingSaveListener'));
29
        $eventManager->attach($sl->get('JhFlexiTime\Listener\CappedCreditListener'));
30
31
        $sharedEvm = $eventManager->getSharedManager();
32
33
        //add roles to users created via HybridAuth
34
        $sharedEvm->attach(
35
            'ScnSocialAuth\Authentication\Adapter\HybridAuth',
36
            'registerViaProvider.post',
37
            [$this, 'onRegister']
38
        );
39
40
        //add roles to users created via ZfcUser
41
        $sharedEvm->attach('ZfcUser\Service\User', 'register.post', [$this, 'onRegister']);
42
43
        $notificationService = $sl->get('JhHubBase\Notification\NotificationService');
44
        $notificationService->addHandler(
45
            $sl->get('JhFlexiTime\NotificationHandler\MissedBookingEmailNotificationHandler')
46
        );
47
    }
48
49
    /**
50
     * Create User FlexiTime Settings
51
     * @param EventInterface $e
52
     */
53
    public function onRegister(EventInterface $e)
54
    {
55
        $application    = $e->getTarget();
0 ignored issues
show
Bug introduced by
The method getTarget does only exist in Zend\EventManager\EventInterface, but not in JhInstaller\Install\Exception.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
56
        $sl             = $application->getServiceManager();
57
        $installer      = $sl->get('JhFlexiTime\Install\Installer');
58
        $user           = $e->getParam('user');
0 ignored issues
show
Bug introduced by
The method getParam does only exist in Zend\EventManager\EventInterface, but not in JhInstaller\Install\Exception.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
59
60
        try {
61
            $installer->createSettingsRow($user);
62
            $installer->createRunningBalanceRow($user);
63
        } catch (InstallException $e) {
64
            //will only happen if database schema not created
65
            //log here
66
        }
67
    }
68
69
    /**
70
     * {@inheritDoc}
71
     */
72
    public function getConfig()
73
    {
74
        return include __DIR__ . '/../../config/module.config.php';
75
    }
76
 
77
    /**
78
     * {@inheritDoc}
79
     */
80
    public function getAutoloaderConfig()
81
    {
82
        return [
83
            'Zend\Loader\StandardAutoloader' => [
84
                'namespaces' => [
85
                    __NAMESPACE__ => __DIR__ . '/../../src/' . __NAMESPACE__,
86
                ],
87
            ],
88
        ];
89
    }
90
91
    /**
92
     * @param Console $console
93
     * @return array|null|string
94
     */
95
    public function getConsoleUsage(Console $console)
0 ignored issues
show
Unused Code introduced by
The parameter $console is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
96
    {
97
        return [
98
            're-calc-balance-user <userEmail>' =>
99
                "Recalculate a User's running balance",
100
            're-calc-balance-all ' =>
101
                "Recalculate all User's running balance",
102
            'calc-prev-month-balance' =>
103
                "Calculate the previous month balance for all users and add it on to their running balance",
104
            'set user init-balance <userEmail> <balance>' =>
105
                "Set a user's starting balance",
106
            'notify-missing-bookings' =>
107
                'Send reminder e-mail to any user who has missed bookings for the period specified in the config'
108
        ];
109
    }
110
111
    /**
112
     * @return string
113
     */
114
    public function getInstallService()
115
    {
116
        return 'JhFlexiTime\Install\Installer';
117
    }
118
}
119