Passed
Pull Request — cache (#765)
by Arnaud
08:40 queued 05:39
created

PostProcessCache::hasWithHash()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 7
rs 10
1
<?php
2
/**
3
 * This file is part of the Cecil/Cecil package.
4
 *
5
 * Copyright (c) Arnaud Ligny <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Cecil\Assets;
12
13
use Cecil\Util;
14
use Exception;
15
use Psr\SimpleCache\CacheInterface;
16
17
class PostProcessCache extends Cache implements CacheInterface
18
{
19
    /**
20
     * Cache::set() with a forced hash.
21
     *
22
     * @param string                 $key
23
     * @param mixed                  $value
24
     * @param null|int|\DateInterval $ttl
25
     * @param string                 $hash
26
     *
27
     * @return bool
28
     */
29
    public function setWithHash($key, $value, $ttl, string $hash): bool
30
    {
31
        if ($this->set($key, $value, $ttl) === false) {
32
            return false;
33
        }
34
35
        try {
36
            Util::getFS()->touch($this->getHashFilePathname($key, $hash));
37
        } catch (Exception $e) {
38
            $this->builder->getLogger()->warning($e->getMessage());
39
40
            return false;
41
        }
42
43
        return true;
44
    }
45
46
    /**
47
     * Cache::has() with a forced hash.
48
     *
49
     * @param string $key
50
     * @param string $hash
51
     *
52
     * @return bool
53
     */
54
    public function hasWithHash(string $key, string $hash): bool
55
    {
56
        if (!$this->has($key) || !Util::getFS()->exists($this->getHashFilePathname($key, $hash))) {
57
            return false;
58
        }
59
60
        return true;
61
    }
62
}
63