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

codeigniter4 / CodeIgniter4 / 13793487137

11 Mar 2025 04:42PM UTC coverage: 84.508% (-0.003%) from 84.511%
13793487137

Pull #9482

github

web-flow
Merge dee9d30e3 into c970fd75c
Pull Request #9482: feat: Improve `Superglobals` service

22 of 27 new or added lines in 2 files covered. (81.48%)

20865 of 24690 relevant lines covered (84.51%)

191.09 hits per line

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

69.23
/system/HTTP/Parameters/InputParameters.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter 4 framework.
7
 *
8
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace CodeIgniter\HTTP\Parameters;
15

16
use CodeIgniter\Exceptions\InvalidArgumentException;
17
use CodeIgniter\Exceptions\RuntimeException;
18

19
/**
20
 * @template TKey of string
21
 * @template TValue of scalar|array<(int|string), mixed>
22
 *
23
 * @extends Parameters<TKey, TValue>
24
 *
25
 * @see \CodeIgniter\HTTP\Parameters\InputParametersTest
26
 */
27
class InputParameters extends Parameters
28
{
29
    public function override(array $parameters = []): void
30
    {
NEW
31
        $this->parameters = [];
×
32

NEW
33
        foreach ($parameters as $key => $value) {
×
NEW
34
            $this->set($key, $value);
×
35
        }
36
    }
37

38
    public function get(string $key, mixed $default = null): mixed
39
    {
40
        if ($default !== null && ! is_scalar($default)) {
1✔
41
            throw new InvalidArgumentException(sprintf('The default value for the InputParameters must be a scalar type, "%s" given.', gettype($default)));
1✔
42
        }
43

44
        // TODO: We need to check that the default value is set. Let's check the unique string
45
        $tempDefault = bin2hex(random_bytes(8));
1✔
46

47
        $value = parent::get($key, $tempDefault);
1✔
48

49
        if ($value !== null && $value !== $tempDefault && ! is_scalar($value)) {
1✔
NEW
50
            throw new RuntimeException(sprintf('The value of the key "%s" InputParameters does not contain a scalar value, "%s" given.', $key, gettype($value)));
×
51
        }
52

53
        return $value === $tempDefault ? $default : $value;
1✔
54
    }
55

56
    public function set(string $key, mixed $value): void
57
    {
58
        if (! is_scalar($value) && ! is_array($value)) {
3✔
59
            throw new InvalidArgumentException(sprintf('The value for the InputParameters must be a scalar type, "%s" given.', gettype($value)));
2✔
60
        }
61

62
        $this->parameters[$key] = $value;
1✔
63
    }
64
}
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