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

api-platform / core / 18370496742

09 Oct 2025 08:35AM UTC coverage: 0.0% (-21.9%) from 21.92%
18370496742

push

github

soyuka
docs: changelog 4.2.2

0 of 56436 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/State/Parameter/ValueCaster.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@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
declare(strict_types=1);
13

14
namespace ApiPlatform\State\Parameter;
15

16
/**
17
 * Caster returns the default value when a value can not be casted
18
 * This is used by parameters before they get validated by constraints
19
 * Therefore we do not need to throw exceptions, validation will just fail.
20
 *
21
 * @internal
22
 */
23
final class ValueCaster
24
{
25
    public static function toBool(mixed $v): mixed
26
    {
27
        if (!\is_string($v)) {
×
28
            return $v;
×
29
        }
30

31
        return match (strtolower($v)) {
×
32
            '1', 'true' => true,
×
33
            '0', 'false' => false,
×
34
            default => $v,
×
35
        };
×
36
    }
37

38
    public static function toInt(mixed $v): mixed
39
    {
40
        if (\is_int($v)) {
×
41
            return $v;
×
42
        }
43

44
        $value = filter_var($v, \FILTER_VALIDATE_INT);
×
45

46
        return false === $value ? $v : $value;
×
47
    }
48

49
    public static function toFloat(mixed $v): mixed
50
    {
51
        if (\is_float($v)) {
×
52
            return $v;
×
53
        }
54

55
        $value = filter_var($v, \FILTER_VALIDATE_FLOAT);
×
56

57
        return false === $value ? $v : $value;
×
58
    }
59
}
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