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

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

03 Apr 2026 01:24AM UTC coverage: 98.248% (-0.4%) from 98.654%
23929639588

Pull #125

github

Enno Woortmann
docs
Pull Request #125: attributes

1496 of 1526 new or added lines in 66 files covered. (98.03%)

4 existing lines in 3 files now uncovered.

4374 of 4452 relevant lines covered (98.25%)

620.23 hits per line

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

57.14
/src/Model/Validator/Factory/SimplePropertyValidatorFactory.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace PHPModelGenerator\Model\Validator\Factory;
6

7
use PHPModelGenerator\Exception\SchemaException;
8
use PHPModelGenerator\Model\Property\PropertyInterface;
9
use PHPModelGenerator\Model\Schema;
10
use PHPModelGenerator\Model\SchemaDefinition\JsonSchema;
11
use PHPModelGenerator\Model\Validator\PropertyValidatorInterface;
12
use PHPModelGenerator\SchemaProcessor\SchemaProcessor;
13

14
abstract class SimplePropertyValidatorFactory extends AbstractValidatorFactory
15
{
16
    public function modify(
1,954✔
17
        SchemaProcessor $schemaProcessor,
18
        Schema $schema,
19
        PropertyInterface $property,
20
        JsonSchema $propertySchema,
21
    ): void {
22
        if (!$this->hasValidValue($property, $propertySchema)) {
1,954✔
23
            return;
1,922✔
24
        }
25

26
        $property->addValidator(
795✔
27
            $this->getValidator($property, $propertySchema->getJson()[$this->key]),
795✔
28
        );
795✔
29
    }
30

31
    protected function hasValidValue(PropertyInterface $property, JsonSchema $propertySchema): bool
2,161✔
32
    {
33
        $json = $propertySchema->getJson();
2,161✔
34

35
        if (!isset($json[$this->key])) {
2,161✔
36
            return false;
2,156✔
37
        }
38

39
        if (!$this->isValueValid($json[$this->key])) {
811✔
NEW
40
            throw new SchemaException(
×
NEW
41
                sprintf(
×
NEW
42
                    "Invalid %s %s for property '%s' in file %s",
×
NEW
43
                    $this->key,
×
NEW
44
                    str_replace("\n", '', var_export($json[$this->key], true)),
×
NEW
45
                    $property->getName(),
×
NEW
46
                    $propertySchema->getFile(),
×
NEW
47
                ),
×
NEW
48
            );
×
49
        }
50

51
        return true;
811✔
52
    }
53

54
    abstract protected function isValueValid(mixed $value): bool;
55

56
    abstract protected function getValidator(PropertyInterface $property, mixed $value): PropertyValidatorInterface;
57
}
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