Failed Conditions
Push — v3.x ( babbd8...d960e5 )
by Chad
02:14
created

AbstractCache::verifyValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace Chadicus\Marvel\Api\Cache;
4
5
/**
6
 * A PSR-16 implementation which does not save or store any data.
7
 */
8
abstract class AbstractCache
9
{
10
    /**
11
     * Verifies the the given cache key is a legal value.
12
     *
13
     * @param mixed $key The cache key to validate.
14
     *
15
     * @return void
16
     *
17
     * @throws InvalidArgumentException Thrown if the $key string is not a legal value.
18
     */
19
    final protected function verifyKey($key)
20
    {
21
        if (!is_string($key) || $key === '') {
22
            throw new InvalidArgumentException('$key must be a valid non-empty string');
23
        }
24
    }
25
26
    /**
27
     * Verify a given $value is an instance of PSR-7 ResponseInterface.
28
     *
29
     * @param mixed $value The PSR-7 Response to cache.
30
     *
31
     * @return void
32
     *
33
     * @throws InvalidArgumentException Thrown if $value is not a PSR-7 Response instance.
34
     */
35
    final protected function verifyValue($value)
36
    {
37
        if (!is_a($value, '\\Psr\\Http\\Message\\ResponseInterface')) {
38
            throw new InvalidArgumentException('$value an instance of \\Psr\\Http\\Message\\ResponseInterface');
39
        }
40
    }
41
}
42