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

h4kuna / data-type / 10057590774

23 Jul 2024 10:53AM UTC coverage: 96.646% (-0.6%) from 97.239%
10057590774

push

github

h4kuna
add nullable

0 of 4 new or added lines in 4 files covered. (0.0%)

634 of 656 relevant lines covered (96.65%)

0.97 hits per line

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

91.67
/src/Basic/Bools.php
1
<?php declare(strict_types=1);
2

3
namespace h4kuna\DataType\Basic;
4

5
use h4kuna\DataType\Exceptions\InvalidTypeException;
6
use Nette\StaticClass;
7

8
final class Bools
9
{
10
        use StaticClass;
11

12
        public static function nullable(mixed $value): ?bool
13
        {
NEW
14
                return $value === null ? null : self::from($value);
×
15
        }
16

17

18
        public static function from(mixed $value): bool
1✔
19
        {
20
                if ($value === true) {
1✔
21
                        return true;
1✔
22
                } elseif ($value === '' || $value === null || $value === false) {
1✔
23
                        return false;
1✔
24
                } elseif (is_numeric($value)) {
1✔
25
                        return match ((float) $value) {
1✔
26
                                1.0 => true,
1✔
27
                                0.0 => false,
1✔
28
                                default => throw InvalidTypeException::invalidBool($value),
1✔
29
                        };
30
                }
31
                throw InvalidTypeException::invalidBool($value);
1✔
32
        }
33

34
}
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