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

RestApiRequests   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 67
Duplicated Lines 52.24 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
dl 35
loc 67
rs 10
c 0
b 0
f 0
wmc 3
lcom 2
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A matchesCurrentRequest() 0 4 1
A requestHandler() 0 5 1
A registerDependencies() 35 35 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 RestApiRequests
10
 * registers dependencies and loads resources for REST API requests
11
 *
12
 * @package EventEspresso\core\domain\entities\routing\handlers\shared
13
 * @author  Brent Christensen
14
 * @since   \$VID:$
15
 */
16
class RestApiRequests 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->isWordPressApi();
28
    }
29
30
31
    /**
32
     * @since $VID:$
33
     */
34 View Code Duplication
    protected function registerDependencies()
35
    {
36
        $this->dependency_map->registerDependencies(
37
            'EventEspresso\core\libraries\rest_api\CalculatedModelFields',
38
            [
39
                'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache
40
            ]
41
        );
42
        $this->dependency_map->registerDependencies(
43
            'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory',
44
            ['EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache]
45
        );
46
        $this->dependency_map->registerDependencies(
47
            'EventEspresso\core\libraries\rest_api\controllers\model\Read',
48
            ['EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache]
49
        );
50
        $this->dependency_map->registerDependencies(
51
            'EventEspresso\core\libraries\rest_api\calculations\Datetime',
52
            [
53
                'EEM_Datetime'     => EE_Dependency_Map::load_from_cache,
54
                'EEM_Registration' => EE_Dependency_Map::load_from_cache
55
            ]
56
        );
57
        $this->dependency_map->registerDependencies(
58
            'EventEspresso\core\libraries\rest_api\calculations\Event',
59
            [
60
                'EEM_Event'        => EE_Dependency_Map::load_from_cache,
61
                'EEM_Registration' => EE_Dependency_Map::load_from_cache
62
            ]
63
        );
64
        $this->dependency_map->registerDependencies(
65
            'EventEspresso\core\libraries\rest_api\calculations\Registration',
66
            ['EEM_Registration' => EE_Dependency_Map::load_from_cache]
67
        );
68
    }
69
70
71
    /**
72
     * implements logic required to run during request
73
     *
74
     * @return bool
75
     * @since   $VID:$
76
     */
77
    protected function requestHandler()
78
    {
79
        // rest api handled by module for now
80
        return true;
81
    }
82
}
83