Completed
Branch EDTR/master (810f49)
by
unknown
28:59 queued 20:31
created

SessionRequests   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 36.73 %

Coupling/Cohesion

Components 3
Dependencies 4

Importance

Changes 0
Metric Value
dl 18
loc 49
rs 10
c 0
b 0
f 0
wmc 5
lcom 3
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A matchesCurrentRequest() 0 4 3
A requestHandler() 0 5 1
A registerDependencies() 17 17 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace EventEspresso\core\domain\entities\routing\handlers\shared;
4
5
use EE_Dependency_Map;
6
use EventEspresso\core\domain\entities\routing\handlers\Route;
7
8
/**
9
 * Class SessionRequests
10
 * registers dependencies and loads resources for requests where EE_Session may be required
11
 *
12
 * @package EventEspresso\core\domain\entities\routing\handlers\shared
13
 * @author  Brent Christensen
14
 * @since   \$VID:$
15
 */
16
class SessionRequests extends Route
17
{
18
19
    /**
20
     * returns true if the current request matches this route
21
     *
22
     * @return bool
23
     * @since   $VID:$
24
     */
25
    public function matchesCurrentRequest()
26
    {
27
        return $this->request->isAdmin() || $this->request->isEeAjax() || $this->request->isFrontend();
28
    }
29
30
31
    /**
32
     * @since $VID:$
33
     */
34 View Code Duplication
    protected function registerDependencies()
35
    {
36
        $this->dependency_map->registerDependencies(
37
            'EE_Session',
38
            [
39
                'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
40
                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
41
                'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
42
                'EventEspresso\core\services\session\SessionStartHandler'  => EE_Dependency_Map::load_from_cache,
43
                'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
44
            ]
45
        );
46
        $this->dependency_map->registerDependencies(
47
            'EventEspresso\core\services\session\SessionStartHandler',
48
            ['EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache]
49
        );
50
    }
51
52
53
    /**
54
     * implements logic required to run during request
55
     *
56
     * @return bool
57
     * @since   $VID:$
58
     */
59
    protected function requestHandler()
60
    {
61
        $this->loader->getShared('EE_Session');
62
        return true;
63
    }
64
}
65