RequestCacheControl::getMaxStale()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * PSR-7 Cache Helpers
4
 *
5
 * @copyright Copyright (c) 2016, Michel Hunziker <[email protected]>
6
 * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD-3-Clause License
7
 */
8
9
namespace Micheh\Cache\Header;
10
11
/**
12
 * Cache-Control header for a request.
13
 */
14
class RequestCacheControl extends CacheControl
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    protected static $directiveMethods = [
20
        'max-stale' => 'withMaxStale',
21
        'min-fresh' => 'withMinFresh',
22
        'only-if-cached' => 'withOnlyIfCached',
23
    ];
24
25
    /**
26
     * Create a new Request Cache-Control object from a header string.
27
     *
28
     * @param string $string
29
     * @return static
30
     */
31 1
    public static function fromString($string)
32
    {
33 1
        return static::createFromString($string);
34
    }
35
36
    /**
37
     * Set how many seconds a stale representation is acceptable.
38
     *
39
     * @param int $seconds
40
     * @return static
41
     */
42 1
    public function withMaxStale($seconds)
43
    {
44 1
        return $this->withDirective('max-stale', (int) $seconds);
45
    }
46
47
    /**
48
     * @return int|null
49
     */
50 1
    public function getMaxStale()
51
    {
52 1
        return $this->getDirective('max-stale');
53
    }
54
55
    /**
56
     * Set how many seconds the representation should still be fresh.
57
     *
58
     * @param int $seconds
59
     * @return static
60
     */
61 1
    public function withMinFresh($seconds)
62
    {
63 1
        return $this->withDirective('min-fresh', (int) $seconds);
64
    }
65
66
    /**
67
     * @return int|null
68
     */
69 1
    public function getMinFresh()
70
    {
71 1
        return $this->getDirective('min-fresh');
72
    }
73
74
    /**
75
     * Set whether only a stored response should be returned.
76
     *
77
     * @param bool $flag
78
     * @return static
79
     */
80 1
    public function withOnlyIfCached($flag = true)
81
    {
82 1
        return $this->withDirective('only-if-cached', (bool) $flag);
83
    }
84
85
    /**
86
     * @return bool
87
     */
88 1
    public function hasOnlyIfCached()
89
    {
90 1
        return $this->hasDirective('only-if-cached');
91
    }
92
}
93