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

wol-soft / php-json-schema-model-generator / 10944162140

19 Sep 2024 03:30PM UTC coverage: 98.855% (+0.007%) from 98.848%
10944162140

Pull #84

github

wol-soft
add typing test
Pull Request #84: Optional const

34 of 34 new or added lines in 6 files covered. (100.0%)

3023 of 3058 relevant lines covered (98.86%)

531.51 hits per line

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

94.44
/src/Model/Validator/MultiTypeCheckValidator.php
1
<?php
2

3
declare(strict_types = 1);
4

5
namespace PHPModelGenerator\Model\Validator;
6

7
use PHPModelGenerator\Exception\Generic\InvalidTypeException;
8
use PHPModelGenerator\Model\Property\PropertyInterface;
9

10
/**
11
 * Class MultiTypeCheckValidator
12
 *
13
 * @package PHPModelGenerator\Model\Validator
14
 */
15
class MultiTypeCheckValidator extends PropertyValidator implements TypeCheckInterface
16
{
17
    /** @var string[] */
18
    protected $types;
19

20
    /**
21
     * MultiTypeCheckValidator constructor.
22
     *
23
     * @param string[]          $types
24
     * @param PropertyInterface $property
25
     * @param bool              $allowImplicitNull
26
     */
27
    public function __construct(array $types, PropertyInterface $property, bool $allowImplicitNull)
28
    {
29
        $this->types = $types;
59✔
30

31
        // if null is explicitly allowed we don't need an implicit null pass through
32
        if (in_array('null', $types)) {
59✔
33
            $allowImplicitNull = false;
15✔
34
        }
35

36
        parent::__construct(
59✔
37
            $property,
59✔
38
            join(
59✔
39
                ' && ',
59✔
40
                array_map(
59✔
41
                    static function (string $allowedType) use ($property) : string {
59✔
42
                        return ReflectionTypeCheckValidator::fromType($allowedType, $property)->getCheck();
59✔
43
                    },
59✔
44
                    $types,
59✔
45
                )
59✔
46
            ) . ($allowImplicitNull ? ' && $value !== null' : ''),
59✔
47
            InvalidTypeException::class,
59✔
48
            [$types],
59✔
49
        );
59✔
50
    }
51

52
    /**
53
     * @inheritDoc
54
     */
55
    public function getTypes(): array
56
    {
57
        return $this->types;
×
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