• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

codeigniter4 / settings / 17488284278

05 Sep 2025 08:41AM UTC coverage: 85.088% (-0.4%) from 85.526%
17488284278

push

github

web-flow
update workflow for PHPUnit (#151)

194 of 228 relevant lines covered (85.09%)

18.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.43
/src/Handlers/ArrayHandler.php
1
<?php
2

3
namespace CodeIgniter\Settings\Handlers;
4

5
/**
6
 * Array Settings Handler
7
 *
8
 * Uses local storage to handle non-persistent
9
 * Settings requests. Useful mostly for testing
10
 * or extension by true persistent handlers.
11
 */
12
class ArrayHandler extends BaseHandler
13
{
14
    /**
15
     * Storage for general settings.
16
     * Format: ['class' => ['property' => ['value', 'type']]]
17
     *
18
     * @var array<string,array<string,array>>
19
     */
20
    private array $general = [];
21

22
    /**
23
     * Storage for context settings.
24
     * Format: ['context' => ['class' => ['property' => ['value', 'type']]]]
25
     *
26
     * @var array<string,array|null>
27
     */
28
    private array $contexts = [];
29

30
    public function has(string $class, string $property, ?string $context = null): bool
31
    {
32
        return $this->hasStored($class, $property, $context);
16✔
33
    }
34

35
    public function get(string $class, string $property, ?string $context = null)
36
    {
37
        return $this->getStored($class, $property, $context);
12✔
38
    }
39

40
    public function set(string $class, string $property, $value = null, ?string $context = null)
41
    {
42
        $this->setStored($class, $property, $value, $context);
12✔
43
    }
44

45
    public function forget(string $class, string $property, ?string $context = null)
46
    {
47
        $this->forgetStored($class, $property, $context);
2✔
48
    }
49

50
    public function flush()
51
    {
52
        $this->general  = [];
2✔
53
        $this->contexts = [];
2✔
54
    }
55

56
    /**
57
     * Checks whether this value is in storage.
58
     */
59
    protected function hasStored(string $class, string $property, ?string $context): bool
60
    {
61
        if ($context === null) {
40✔
62
            return isset($this->general[$class]) && array_key_exists($property, $this->general[$class]);
38✔
63
        }
64

65
        return isset($this->contexts[$context][$class]) && array_key_exists($property, $this->contexts[$context][$class]);
10✔
66
    }
67

68
    /**
69
     * Retrieves a value from storage.
70
     *
71
     * @return mixed|null
72
     */
73
    protected function getStored(string $class, string $property, ?string $context)
74
    {
75
        if (! $this->has($class, $property, $context)) {
28✔
76
            return null;
×
77
        }
78

79
        return $context === null
28✔
80
            ? $this->parseValue(...$this->general[$class][$property])
28✔
81
            : $this->parseValue(...$this->contexts[$context][$class][$property]);
28✔
82
    }
83

84
    /**
85
     * Adds values to storage.
86
     *
87
     * @param mixed $value
88
     */
89
    protected function setStored(string $class, string $property, $value, ?string $context): void
90
    {
91
        $type  = gettype($value);
38✔
92
        $value = $this->prepareValue($value);
38✔
93

94
        if ($context === null) {
38✔
95
            $this->general[$class][$property] = [
36✔
96
                $value,
36✔
97
                $type,
36✔
98
            ];
36✔
99
        } else {
100
            $this->contexts[$context][$class][$property] = [
8✔
101
                $value,
8✔
102
                $type,
8✔
103
            ];
8✔
104
        }
105
    }
106

107
    /**
108
     * Deletes an item from storage.
109
     */
110
    protected function forgetStored(string $class, string $property, ?string $context): void
111
    {
112
        if ($context === null) {
6✔
113
            unset($this->general[$class][$property]);
4✔
114
        } else {
115
            unset($this->contexts[$context][$class][$property]);
2✔
116
        }
117
    }
118
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc