Completed
Branch FET/11399/verify-paypal-creden... (c7ad03)
by
unknown
66:22 queued 52:43
created

Middleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 16.07 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 9
loc 56
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A processRequestStack() 9 9 2

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\services\request\middleware;
4
5
use EventEspresso\core\services\loaders\LoaderInterface;
6
use EventEspresso\core\services\request\RequestDecoratorInterface;
7
use EventEspresso\core\services\request\RequestInterface;
8
use EventEspresso\core\services\request\ResponseInterface;
9
10
defined('EVENT_ESPRESSO_VERSION') || exit;
11
12
13
14
/**
15
 * Class Middleware
16
 * Parent class for Middleware Request decorators.
17
 * Accepts an instance of another Middleware class,
18
 * and handles the passing of EE_Request and EE_Response objects to and from it
19
 * Middleware classes are for functionality that needs to run on nearly EVERY request.
20
 * They can perform their logic either before or after the core application has run:
21
 *    (see documentation for the handle() method below)
22
 * Middleware classes should NOT depend on core functionality,
23
 * because there is no guarantee that the core application has run
24
 *
25
 * @package EventEspresso\core\services\request\middleware
26
 * @author  Brent Christensen
27
 * @since   4.9.52
28
 */
29
abstract class Middleware implements RequestDecoratorInterface
30
{
31
32
    /**
33
     * @var RequestDecoratorInterface $request_stack_app
34
     */
35
    protected $request_stack_app;
36
37
    /**
38
     * @var RequestInterface $request
39
     */
40
    protected $request;
41
42
    /**
43
     * @var ResponseInterface $response
44
     */
45
    protected $response;
46
47
    /**
48
     * @var LoaderInterface
49
     */
50
    protected $loader;
51
52
53
54
    /**
55
     * @param RequestDecoratorInterface $request_stack_app
56
     * @param LoaderInterface           $loader
57
     */
58
    public function __construct(RequestDecoratorInterface $request_stack_app, LoaderInterface $loader)
59
    {
60
        $this->request_stack_app = $request_stack_app;
61
        $this->loader = $loader;
62
    }
63
64
65
66
    /**
67
     * process_request_stack
68
     *
69
     * @param RequestInterface $request
70
     * @param ResponseInterface      $response
71
     * @return ResponseInterface
72
     */
73 View Code Duplication
    protected function processRequestStack(RequestInterface $request, ResponseInterface $response)
74
    {
75
        $this->request  = $request;
76
        $this->response = $response;
77
        if (! $this->response->requestTerminated()) {
78
            $this->response = $this->request_stack_app->handleRequest($this->request, $this->response);
79
        }
80
        return $this->response;
81
    }
82
83
84
}
85
// Location: Middleware.php
86