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

codeigniter4 / CodeIgniter4 / 24027012979

06 Apr 2026 09:42AM UTC coverage: 86.556%. Remained the same
24027012979

Pull #10086

github

web-flow
Merge d0717fc15 into d6e3f7b3f
Pull Request #10086: feat(cast): Add precision and rounding mode in FloatCast

15 of 17 new or added lines in 2 files covered. (88.24%)

1 existing line in 1 file now uncovered.

22721 of 26250 relevant lines covered (86.56%)

220.32 hits per line

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

93.75
/system/Entity/Exceptions/CastException.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\Entity\Exceptions;
15

16
use CodeIgniter\Exceptions\FrameworkException;
17
use CodeIgniter\Exceptions\HasExitCodeInterface;
18

19
/**
20
 * CastException is thrown for invalid cast initialization and management.
21
 */
22
class CastException extends FrameworkException implements HasExitCodeInterface
23
{
24
    public function getExitCode(): int
25
    {
26
        return EXIT_CONFIG;
1✔
27
    }
28

29
    /**
30
     * Thrown when the cast class does not extends BaseCast.
31
     *
32
     * @return static
33
     */
34
    public static function forInvalidInterface(string $class)
35
    {
36
        return new static(lang('Cast.baseCastMissing', [$class]));
2✔
37
    }
38

39
    /**
40
     * Thrown when the Json format is invalid.
41
     *
42
     * @return static
43
     */
44
    public static function forInvalidJsonFormat(int $error)
45
    {
46
        return match ($error) {
47
            JSON_ERROR_DEPTH          => new static(lang('Cast.jsonErrorDepth')),
6✔
48
            JSON_ERROR_STATE_MISMATCH => new static(lang('Cast.jsonErrorStateMismatch')),
4✔
49
            JSON_ERROR_CTRL_CHAR      => new static(lang('Cast.jsonErrorCtrlChar')),
3✔
50
            JSON_ERROR_SYNTAX         => new static(lang('Cast.jsonErrorSyntax')),
2✔
51
            JSON_ERROR_UTF8           => new static(lang('Cast.jsonErrorUtf8')),
1✔
52
            default                   => new static(lang('Cast.jsonErrorUnknown')),
6✔
53
        };
54
    }
55

56
    /**
57
     * Thrown when the cast method is not `get` or `set`.
58
     *
59
     * @return static
60
     */
61
    public static function forInvalidMethod(string $method)
62
    {
63
        return new static(lang('Cast.invalidCastMethod', [$method]));
1✔
64
    }
65

66
    /**
67
     * Thrown when the casting timestamp is not correct timestamp.
68
     *
69
     * @return static
70
     */
71
    public static function forInvalidTimestamp()
72
    {
73
        return new static(lang('Cast.invalidTimestamp'));
1✔
74
    }
75

76
    /**
77
     * Thrown when the enum class is not specified in cast parameters.
78
     *
79
     * @return static
80
     */
81
    public static function forMissingEnumClass()
82
    {
83
        return new static(lang('Cast.enumMissingClass'));
4✔
84
    }
85

86
    /**
87
     * Thrown when the specified class is not an enum.
88
     *
89
     * @return static
90
     */
91
    public static function forNotEnum(string $class)
92
    {
93
        return new static(lang('Cast.enumNotEnum', [$class]));
4✔
94
    }
95

96
    /**
97
     * Thrown when an invalid value is provided for an enum.
98
     *
99
     * @return static
100
     */
101
    public static function forInvalidEnumValue(string $enumClass, mixed $value)
102
    {
103
        return new static(lang('Cast.enumInvalidValue', [$enumClass, $value]));
3✔
104
    }
105

106
    /**
107
     * Thrown when an invalid case name is provided for a unit enum.
108
     *
109
     * @return static
110
     */
111
    public static function forInvalidEnumCaseName(string $enumClass, string $caseName)
112
    {
113
        return new static(lang('Cast.enumInvalidCaseName', [$caseName, $enumClass]));
3✔
114
    }
115

116
    /**
117
     * Thrown when an enum instance of wrong type is provided.
118
     *
119
     * @return static
120
     */
121
    public static function forInvalidEnumType(string $expectedClass, string $actualClass)
122
    {
123
        return new static(lang('Cast.enumInvalidType', [$actualClass, $expectedClass]));
2✔
124
    }
125

126
    /**
127
     * Thrown when an invalid rounding mode is provided for float casting.
128
     *
129
     * @return static
130
     */
131
    public static function forInvalidFloatRoundingMode(string $mode)
132
    {
NEW
133
        return new static(lang('Cast.floatInvalidRoundingMode', [$mode]));
×
134
    }
135
}
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