GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 7b42e1...c93f43 )
by Marius
10:41 queued 04:09
created

CacheableControllerA   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 67
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0
wmc 12
lcom 0
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getLastModified() 0 3 1
C addCacheHeaders() 0 39 8
A getResponse() 0 9 3
1
<?php
2
/**
3
 * @package application
4
 * @subpackage controllers
5
 * @author marius orcsik <[email protected]>
6
 * @date 2011.02.21
7
 */
8
namespace vsc\application\controllers;
9
10
use vsc\domain\models\CacheableModelA;
11
use vsc\domain\models\ModelA;
12
use vsc\infrastructure\caching\CacheableInterface;
13
use vsc\presentation\requests\HttpRequestA;
14
use vsc\presentation\responses\HttpResponseA;
15
use vsc\presentation\responses\HttpResponseType;
16
use vsc\presentation\views\ExceptionView;
17
use vsc\application\processors\ProcessorA;
18
19
abstract class CacheableControllerA extends FrontControllerA implements CacheableInterface {
20
21 1
	public function getLastModified() {
22 1
		return false;
23
	}
24
25
	/**
26
	 * @param HttpRequestA $oRequest
27
	 * @param ModelA $oModel
28
	 * @param HttpResponseA $oResponse
29
	 * @return HttpResponseA
30
	 */
31 2
	public function addCacheHeaders (HttpRequestA $oRequest, ModelA $oModel, HttpResponseA $oResponse) {
32 2
		$iExpireTime = 600; // ten minute
33 2
		$oNow = new \DateTime('now', new \DateTimeZone('GMT'));
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
34 2
		$oResponse->setDate($oNow->format('r'));
35 2
		if (CacheableModelA::isValid($oModel)) {
36
			try {
37
				/** @var CacheableModelA $oModel */
38 1
				$sLastModified = $oModel->getLastModified();
39
40 1
				$oLastModified = new \DateTime($sLastModified, new \DateTimeZone('GMT'));
41 1
				$oResponse->setLastModified($oLastModified->format('r'));
42 1
				$oMax = $oLastModified->getTimestamp() > $oNow->getTimestamp() ? $oLastModified : $oNow;
43
44 1
				$sModifiedSince = $oRequest->getIfModifiedSince();
45 1
				if (!empty ($sModifiedSince)) {
46 1
					$oModifiedSince = new \DateTime($sModifiedSince, new \DateTimeZone('GMT'));
47
48 1
					if ($oLastModified->getTimestamp() <= $oModifiedSince->getTimestamp()) {
49 1
						$oResponse->setStatus(HttpResponseType::NOT_MODIFIED);
50
					}
51
				}
52
			} catch (\Exception $e) {
53
				$oMax = $oNow;
54
			}
55 1
			$oResponse->setExpires($oMax->add(new \DateInterval('P2W'))->format('r')); // adding 2 weeks
56
		} else {
57
			try {
58 1
				$oResponse->setETag(substr(sha1($oResponse->getOutput()), 0, 8));
59 1
				$oResponse->setCacheControl('public, max-age=' . $iExpireTime);
60
			} catch (ExceptionView $v) {
61
				//
62
			}
63
64 1
			if (trim($oRequest->getIfNoneMatch(), '"') == trim($oResponse->getETag(), '"')) {
65 1
				$oResponse->setStatus(HttpResponseType::NOT_MODIFIED);
66
			}
67
		}
68 2
		return $oResponse;
69
	}
70
71
	/**
72
	 * @param HttpRequestA $oRequest
73
	 * @param ProcessorA $oProcessor
0 ignored issues
show
Documentation introduced by
Should the type for parameter $oProcessor not be ProcessorA|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
74
	 * @returns HttpResponseA
75
	 */
76 4
	public function getResponse(HttpRequestA $oRequest, $oProcessor = null) {
77 4
		$oResponse = parent::getResponse($oRequest, $oProcessor);
78
79 4
		if (!($oResponse->isRedirect() || $oResponse->isError())) {
80 4
			$this->addCacheHeaders($oRequest, $this->getView()->getModel(), $oResponse);
81
		}
82
83 4
		return $oResponse;
84
	}
85
}
86