Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
9 / 9
CRAP
100.00% covered (success)
100.00%
1 / 1
NullAdapter
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
9 / 9
9
100.00% covered (success)
100.00%
1 / 1
 getItemTtl
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 saveItem
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getItem
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasItem
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 deleteItem
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 clear
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 destroy
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 incrementItem
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 decrementItem
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Cache\Adapter;
16
17/**
18 * Null adapter cache class
19 *
20 * @category   Pop
21 * @package    Pop\Cache
22 * @author     Nick Sagona, III <nick@popphp.org>
23 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
24 * @license    https://www.popphp.org/license     New BSD License
25 * @version    5.0.0
26 */
27class NullAdapter extends AbstractAdapter
28{
29
30    /**
31     * Get the time-to-live for an item in cache
32     *
33     * @param  string $id
34     * @param  int    $default
35     * @return int
36     */
37    public function getItemTtl(string $id, int $default = 0): int
38    {
39        return $default;
40    }
41
42    /**
43     * Save an item to cache
44     *
45     * @param  string $id
46     * @param  mixed  $value
47     * @param  ?int   $ttl
48     * @return NullAdapter
49     */
50    public function saveItem(string $id, mixed $value, ?int $ttl = null): NullAdapter
51    {
52        return $this;
53    }
54
55    /**
56     * Get an item from cache
57     *
58     * @param  string $id
59     * @param  mixed  $default
60     * @return mixed
61     */
62    public function getItem(string $id, mixed $default = false): mixed
63    {
64        return $default;
65    }
66
67    /**
68     * Determine if the item exist in cache
69     *
70     * @param  string $id
71     * @return bool
72     */
73    public function hasItem(string $id): bool
74    {
75        return false;
76    }
77
78    /**
79     * Delete a value in cache
80     *
81     * @param  string $id
82     * @return NullAdapter
83     */
84    public function deleteItem(string $id): NullAdapter
85    {
86        return $this;
87    }
88
89    /**
90     * Clear all stored values from cache
91     *
92     * @return NullAdapter
93     */
94    public function clear(): NullAdapter
95    {
96        return $this;
97    }
98
99    /**
100     * Destroy cache resource
101     *
102     * @return NullAdapter
103     */
104    public function destroy(): NullAdapter
105    {
106        return $this;
107    }
108
109    /**
110     * Always returns $initial + $amount — nothing is ever actually persisted, so every call behaves as if
111     * the counter had just been created and immediately incremented once; there is no "first call" state.
112     *
113     * @param  string $id
114     * @param  int    $amount
115     * @param  int    $initial
116     * @param  ?int   $ttl
117     * @return int
118     */
119    public function incrementItem(string $id, int $amount = 1, int $initial = 0, ?int $ttl = null): int
120    {
121        return $initial + $amount;
122    }
123
124    /**
125     * Always returns $initial - $amount — nothing is ever actually persisted, so every call behaves as if
126     * the counter had just been created and immediately decremented once; there is no "first call" state.
127     *
128     * @param  string $id
129     * @param  int    $amount
130     * @param  int    $initial
131     * @param  ?int   $ttl
132     * @return int
133     */
134    public function decrementItem(string $id, int $amount = 1, int $initial = 0, ?int $ttl = null): int
135    {
136        return $initial - $amount;
137    }
138
139}