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

codeigniter4 / settings / 13399286100

18 Feb 2025 08:14PM UTC coverage: 85.526%. Remained the same
13399286100

push

github

web-flow
chore: update dependencies to support PHP 8.1 - 8.4 (#145)

* move to PHP 8.1 and PHPUnit 10

* update tests

* cs fix

* update workflows

* update php version in the docs

* update rector config

* update psalm config

1 of 2 new or added lines in 2 files covered. (50.0%)

195 of 228 relevant lines covered (85.53%)

55.95 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);
48✔
33
    }
34

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

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

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

50
    public function flush()
51
    {
52
        $this->general  = [];
6✔
53
        $this->contexts = [];
6✔
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) {
120✔
62
            return isset($this->general[$class]) && array_key_exists($property, $this->general[$class]);
114✔
63
        }
64

65
        return isset($this->contexts[$context][$class]) && array_key_exists($property, $this->contexts[$context][$class]);
30✔
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)) {
84✔
76
            return null;
×
77
        }
78

79
        return $context === null
84✔
80
            ? $this->parseValue(...$this->general[$class][$property])
84✔
81
            : $this->parseValue(...$this->contexts[$context][$class][$property]);
84✔
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);
114✔
92
        $value = $this->prepareValue($value);
114✔
93

94
        if ($context === null) {
114✔
95
            $this->general[$class][$property] = [
108✔
96
                $value,
108✔
97
                $type,
108✔
98
            ];
108✔
99
        } else {
100
            $this->contexts[$context][$class][$property] = [
24✔
101
                $value,
24✔
102
                $type,
24✔
103
            ];
24✔
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) {
18✔
113
            unset($this->general[$class][$property]);
12✔
114
        } else {
115
            unset($this->contexts[$context][$class][$property]);
6✔
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

© 2026 Coveralls, Inc