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

ICanBoogie / Common / 6398009159

03 Oct 2023 08:19PM UTC coverage: 45.965% (+1.6%) from 44.407%
6398009159

push

github

olvlvl
Use named parameters for exceptions

26 of 26 new or added lines in 7 files covered. (100.0%)

131 of 285 relevant lines covered (45.96%)

2.28 hits per line

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

0.0
/lib/OffsetNotDefined.php
1
<?php
2

3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
namespace ICanBoogie;
13

14
use LogicException;
15
use Throwable;
16

17
/**
18
 * Exception thrown when an array offset is not defined.
19
 *
20
 * For example, this could be triggered by an offset out of bounds while setting an array value.
21
 */
22
class OffsetNotDefined extends LogicException implements OffsetError
23
{
24
    /**
25
     * @phpstan-ignore-next-line
26
     */
27
    public function __construct(
28
        public readonly string|int $offset,
29
        public readonly array|object|null $container = null,
30
        string $message = null,
31
        Throwable $previous = null
32
    ) {
33
        if (!$message) {
×
34
            if (is_object($container)) {
×
35
                $message = format('Undefined offset %offset for object of class %class.', [
×
36
                    '%offset' => $offset,
×
37
                    '%class' => get_class($container)
×
38
                ]);
×
39
            } elseif (is_array($container)) {
×
40
                $message = format('Undefined offset %offset for the array: !array', [
×
41
                    '%offset' => $offset,
×
42
                    '!array' => $container
×
43
                ]);
×
44
            } else {
45
                $message = format('Undefined offset %offset.', [
×
46
                    '%offset' => $offset
×
47
                ]);
×
48
            }
49
        }
50

51
        parent::__construct($message, previous: $previous);
×
52
    }
53
}
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