Passed
Push — master ( 1df8e7...70b96d )
by Julien
04:51
created

CacheTask::hasAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Modules\Cli\Tasks;
13
14
use Phalcon\Cache\Exception\InvalidArgumentException;
15
use Zemit\Modules\Cli\Task;
16
17
class CacheTask extends Task
18
{
19
    public string $cliDoc = <<<DOC
20
Usage:
21
  zemit cli cache clear
22
  zemit cli cache has <key>
23
  zemit cli cache delete <key>
24
  zemit cli cache delete-multiple [<key>...]
25
26
DOC;
27
    
28
    /**
29
     * Clears all items from the cache.
30
     *
31
     * @return bool True if all items were successfully cleared, false otherwise.
32
     */
33
    public function clearAction(): bool
34
    {
35
        return $this->cache->clear();
0 ignored issues
show
Bug Best Practice introduced by
The property cache does not exist on Zemit\Modules\Cli\Tasks\CacheTask. Since you implemented __get, consider adding a @property annotation.
Loading history...
36
    }
37
    
38
    /**
39
     * Checks if the given action key exists in the cache.
40
     *
41
     * @param string $key The key identifying the action in the cache.
42
     * @return bool Returns true if the action key exists in the cache, false otherwise.
43
     * @throws InvalidArgumentException
44
     */
45
    public function hasAction(string $key): bool
46
    {
47
        return $this->cache->has($key);
0 ignored issues
show
Bug Best Practice introduced by
The property cache does not exist on Zemit\Modules\Cli\Tasks\CacheTask. Since you implemented __get, consider adding a @property annotation.
Loading history...
48
    }
49
    
50
    /**
51
     * Deletes an item from the cache.
52
     *
53
     * @param string $key The key of the item to be deleted.
54
     * @return bool True if the item was successfully deleted, false otherwise.
55
     * @throws InvalidArgumentException
56
     */
57
    public function deleteAction(string $key): bool
58
    {
59
        return $this->cache->delete($key);
0 ignored issues
show
Bug Best Practice introduced by
The property cache does not exist on Zemit\Modules\Cli\Tasks\CacheTask. Since you implemented __get, consider adding a @property annotation.
Loading history...
60
    }
61
    
62
    /**
63
     * Deletes multiple cache entries specified by the given keys.
64
     *
65
     * @param mixed ...$keys A variable number of keys representing the cache entries to be deleted.
66
     *
67
     * @return bool Returns true if all cache entries were successfully deleted, false otherwise.
68
     */
69
    public function deleteMultipleAction(string ...$keys): bool
70
    {
71
        return $this->cache->deleteMultiple($keys);
0 ignored issues
show
Bug Best Practice introduced by
The property cache does not exist on Zemit\Modules\Cli\Tasks\CacheTask. Since you implemented __get, consider adding a @property annotation.
Loading history...
72
    }
73
}
74