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

RequestProcessor::preRequest()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %
Metric Value
cc 3
eloc 5
nc 3
nop 3
dl 8
loc 8
rs 9.4285
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