Completed
Branch BETA-4.9-messages-queue-fixed (941081)
by
unknown
17:38 queued 10s
created

EE_Request   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 113
Duplicated Lines 2.65 %

Coupling/Cohesion

Components 1
Dependencies 0
Metric Value
wmc 18
lcom 1
cbo 0
dl 3
loc 113
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 4
A params() 0 3 1
A get() 0 3 2
A is_set() 0 3 2
B set() 3 6 7
A un_set() 0 6 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 if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
/**
3
 * class EE_Request
4
 *
5
 * @package         Event Espresso
6
 * @subpackage  /core/
7
 * @author          Brent Christensen
8
 *
9
 * ------------------------------------------------------------------------
10
 */
11
class EE_Request {
12
13
	/**
14
	 * @access    private
15
	 * 	@type 	array $_params $_REQUEST parameters
16
	 */
17
	private $_params = array();
18
19
	/**
20
	 * 	whether current request is via AJAX
21
	 *	@type 	boolean
22
	 * 	@access public
23
	 */
24
	public $ajax = FALSE;
25
26
	/**
27
	 * 	whether current request is via AJAX from the frontend of the site
28
	 *	@type 	boolean
29
	 * 	@access public
30
	 */
31
	public $front_ajax = FALSE;
32
33
34
35
	/**
36
	 *    class constructor
37
	 *
38
	 * @access    public
39
	 * @param array $request
40
	 */
41
	public function __construct( $request ) {
42
		// grab request vars
43
		$this->_params = $request;
44
		// AJAX ???
45
		$this->ajax = defined( 'DOING_AJAX' ) ? TRUE : FALSE;
46
		$this->front_ajax = $this->is_set( 'ee_front_ajax' ) && $this->get( 'ee_front_ajax' ) == 1 ? TRUE : FALSE;
47
	}
48
49
50
51
	/**
52
	 * returns contents of $_REQUEST
53
	 * @return array
54
	 */
55
	public function params() {
56
		return $this->_params;
57
	}
58
59
60
61
	/**
62
	 *    setter
63
	 *
64
	 * @access    public
65
	 * @param      $key
66
	 * @param      $value
67
	 * @param bool $override_ee
68
	 * @return    void
69
	 */
70
	public function set( $key, $value, $override_ee = FALSE ) {
71
		// don't allow "ee" to be overwritten unless explicitly instructed to do so
72 View Code Duplication
		if ( $key != 'ee' || ( $key == 'ee' && empty( $this->_params['ee'] )) || ( $key == 'ee' && ! empty( $this->_params['ee'] ) && $override_ee )) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
			$this->_params[ $key ] = $value;
74
		}
75
	}
76
77
78
79
	/**
80
	 *    getter
81
	 *
82
	 * @access    public
83
	 * @param      $key
84
	 * @param null $default
85
	 * @return    mixed
86
	 */
87
	public function get( $key, $default = NULL ) {
88
		return isset( $this->_params[ $key ] ) ? $this->_params[ $key ] : $default;
89
	}
90
91
92
93
	/**
94
	 *    check if param exists
95
	 *
96
	 * @access    public
97
	 * @param $key
98
	 * @return    boolean
99
	 */
100
	public function is_set( $key ) {
101
		return isset( $this->_params[ $key ] ) ? TRUE : FALSE;
102
	}
103
104
105
106
	/**
107
	 *    remove param
108
	 *
109
	 * @access    public
110
	 * @param $key
111
	 * @param bool $unset_from_global_too
112
	 */
113
	public function un_set( $key, $unset_from_global_too = false ) {
114
		unset( $this->_params[ $key ] );
115
		if ( $unset_from_global_too ) {
116
			unset( $_REQUEST[ $key ] );
117
		}
118
	}
119
120
121
122
123
}
124
// End of file EE_Request.core.php
125
// Location: /core/request_stack/EE_Request.core.php