Conditions | 3 |
Paths | 3 |
Total Lines | 16 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 3 |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | 4 | public function by(Request $request, $params) |
|
|
|||
17 | { |
||
18 | 4 | if (!isset($_SERVER['IF_MODIFIED_SINCE'])) { |
|
19 | 1 | return true; |
|
20 | } |
||
21 | |||
22 | 4 | $ifModifiedSince = new DateTime($_SERVER['IF_MODIFIED_SINCE']); |
|
23 | 4 | $lastModifiedOn = call_user_func($this->callback, $params); |
|
24 | |||
25 | 4 | header('Last-Modified: '.$lastModifiedOn->format(DateTime::RFC2822)); |
|
26 | 4 | if ($lastModifiedOn <= $ifModifiedSince) { |
|
27 | 3 | header('HTTP/1.1 304 Not Modified'); |
|
28 | |||
29 | 3 | return false; |
|
30 | } |
||
31 | 2 | } |
|
32 | } |
||
33 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: