Completed
Push — namespace-model ( 32fe71...476d0e )
by Sam
16:05
created

RequestProcessor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 40
Duplicated Lines 40 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 16
loc 40
rs 10
wmc 8
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setFilters() 0 3 1
A preRequest() 8 8 3
A postRequest() 8 8 3

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 SilverStripe\Control;
4
5
use SilverStripe\Model\DataModel;
6
7
8
use SilverStripe\Control\HTTPRequest;
9
use SilverStripe\Control\HTTPResponse;
10
11
12
13
/**
14
 * Represents a request processer that delegates pre and post request handling to nested request filters
15
 *
16
 * @package framework
17
 * @subpackage control
18
 */
19
class RequestProcessor implements RequestFilter {
20
21
	/**
22
	 * List of currently assigned request filters
23
	 *
24
	 * @var array
25
	 */
26
	private $filters = array();
27
28
	public function __construct($filters = array()) {
29
		$this->filters = $filters;
30
	}
31
32
	/**
33
	 * Assign a list of request filters
34
	 *
35
	 * @param array $filters
36
	 */
37
	public function setFilters($filters) {
38
		$this->filters = $filters;
39
	}
40
41 View Code Duplication
	public function preRequest(HTTPRequest $request, Session $session, DataModel $model) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
42
		foreach ($this->filters as $filter) {
43
			$res = $filter->preRequest($request, $session, $model);
44
			if ($res === false) {
45
				return false;
46
			}
47
		}
48
	}
49
50 View Code Duplication
	public function postRequest(HTTPRequest $request, HTTPResponse $response, DataModel $model) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
51
		foreach ($this->filters as $filter) {
52
			$res = $filter->postRequest($request, $response, $model);
53
			if ($res === false) {
54
				return false;
55
			}
56
		}
57
	}
58
}
59