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

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

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

Pull #125

github

Enno Woortmann
attribute tests
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

96.43
/src/Model/Validator/PropertyNamesValidator.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace PHPModelGenerator\Model\Validator;
6

7
use PHPModelGenerator\Exception\Object\InvalidPropertyNamesException;
8
use PHPModelGenerator\Exception\SchemaException;
9
use PHPModelGenerator\Model\Property\Property;
10
use PHPModelGenerator\Model\Schema;
11
use PHPModelGenerator\Model\SchemaDefinition\JsonSchema;
12
use PHPModelGenerator\Model\Validator;
13
use PHPModelGenerator\PropertyProcessor\PropertyFactory;
14
use PHPModelGenerator\SchemaProcessor\SchemaProcessor;
15
use PHPModelGenerator\Utils\RenderHelper;
16

17
/**
18
 * Class PropertyNamesValidator
19
 *
20
 * @package PHPModelGenerator\Model\Validator
21
 */
22
class PropertyNamesValidator extends PropertyTemplateValidator
23
{
24
    /**
25
     * PropertyNamesValidator constructor.
26
     *
27
     * @throws SchemaException
28
     */
29
    public function __construct(
44✔
30
        SchemaProcessor $schemaProcessor,
31
        Schema $schema,
32
        JsonSchema $propertiesNames,
33
    ) {
34
        $this->isResolved = true;
44✔
35

36
        if (
37
            array_key_exists('const', $propertiesNames->getJson()) &&
44✔
38
            gettype($propertiesNames->getJson()['const']) !== 'string'
44✔
39
        ) {
40
            throw new SchemaException("Invalid const property name in file {$propertiesNames->getFile()}");
1✔
41
        }
42

43
        // Property names are always strings; ensure the schema declares the type so that
44
        // string-specific validators (minLength, maxLength, pattern) are applied.
45
        $propertiesNamesAsString = array_key_exists('type', $propertiesNames->getJson())
43✔
NEW
46
            ? $propertiesNames
×
47
            : $propertiesNames->withJson(['type' => 'string'] + $propertiesNames->getJson());
43✔
48

49
        $nameValidationProperty = (new PropertyFactory())
43✔
50
            ->create($schemaProcessor, $schema, 'property name', $propertiesNamesAsString)
43✔
51
            // the property name validator doesn't need type checks or required checks so simply filter them out
43✔
52
            ->filterValidators(static fn(Validator $validator): bool =>
43✔
53
                !is_a($validator->getValidator(), RequiredPropertyValidator::class) &&
43✔
54
                !is_a($validator->getValidator(), TypeCheckValidator::class));
43✔
55

56
        parent::__construct(
43✔
57
            new Property($schema->getClassName(), null, $propertiesNames),
43✔
58
            DIRECTORY_SEPARATOR . 'Validator' . DIRECTORY_SEPARATOR . 'PropertyNames.phptpl',
43✔
59
            [
43✔
60
                'nameValidationProperty' => $nameValidationProperty,
43✔
61
                'generatorConfiguration' => $schemaProcessor->getGeneratorConfiguration(),
43✔
62
                'viewHelper'             => new RenderHelper($schemaProcessor->getGeneratorConfiguration()),
43✔
63
                'schema'                 => $schema,
43✔
64
            ],
43✔
65
            InvalidPropertyNamesException::class,
43✔
66
            ['&$invalidProperties'],
43✔
67
        );
43✔
68
    }
69

70
    /**
71
     * Initialize all variables which are required to execute a property names validator
72
     */
73
    public function getValidatorSetUp(): string
43✔
74
    {
75
        return '$invalidProperties = [];';
43✔
76
    }
77
}
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