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.

CacheableControllerA::getResponse()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 2
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 9.9666
c 0
b 0
f 0
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'));
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