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

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

30 Mar 2026 09:08AM UTC coverage: 98.331% (-0.4%) from 98.717%
23736910562

Pull #123

github

Enno Woortmann
Merge remote-tracking branch 'origin/master' into drafts
Pull Request #123: Introduce Draft-based architecture: eliminate legacy processors, centralize modifier/validator registration

1374 of 1399 new or added lines in 60 files covered. (98.21%)

3 existing lines in 2 files now uncovered.

4243 of 4315 relevant lines covered (98.33%)

588.89 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,951✔
17
        SchemaProcessor $schemaProcessor,
18
        Schema $schema,
19
        PropertyInterface $property,
20
        JsonSchema $propertySchema,
21
    ): void {
22
        if (!$this->hasValidValue($property, $propertySchema)) {
1,951✔
23
            return;
1,919✔
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,158✔
32
    {
33
        $json = $propertySchema->getJson();
2,158✔
34

35
        if (!isset($json[$this->key])) {
2,158✔
36
            return false;
2,153✔
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