Skip to content

Access to undeclared property _propertyValidationState on simple templates #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dktapps opened this issue Oct 14, 2021 · 3 comments
Closed
Labels
code style Improve code style of the generated code

Comments

@dktapps
Copy link
Contributor

dktapps commented Oct 14, 2021

Describe the bug
I initially found this and various other bugs using PHPStan:
image

The vast majority of these issues are the same thing, but only this one looks actively harmful as far as I can tell (most of the others are just unused use and dead code which could be prevented from generating with the right efforts).

Bear in mind that this is just PHPStan level 1, and higher levels might find more problems.

Expected behavior
The generated code shouldn't be trying to access an undeclared property. This happens in both mutable and immutable models.

Schema

{
	"$schema": "http://json-schema.org/draft-04/schema#",
	"type": "object",
	"additionalProperties": false,
	"properties": {
		"mode": {
			"enum": [
				"blacklist",
				"whitelist",
				"allow",
				"disallow"
			],
			"default": "disallow",
			"description": "The listed plugins will either be allowed or disallowed based on this setting"
		},
		"plugins": {
			"anyOf": [
				{
					"type": "array",
					"items": {
						"type": "string"
					}
				},
				{
					"type": "null"
				}
			],
			"default": [],
			"description": "List of plugins to allow or disallow"
		}
	}
}

My generator config can be seen here: https://github.com/pmmp/DataModels/blob/3f398d966d5180d68e33c8f4054ab592094ea54c/generate-schemas.php

Version:
0.21.5

@wol-soft
Copy link
Owner

The access to the dynamic _propertyValidationState actually isn't harmful. It's an intended dynamic property used to cache validation results for composition validations (anyOf/allOf eg.) to be able to determine whether a validator must be re-evaluated on a property change or not.

@wol-soft wol-soft added the code style Improve code style of the generated code label Oct 15, 2021
@dktapps
Copy link
Contributor Author

dktapps commented Oct 15, 2021

@dktapps
Copy link
Contributor Author

dktapps commented Dec 10, 2021

Worth mentioning this will start generating warnings in 8.2 due to this RFC: https://wiki.php.net/rfc/deprecate_dynamic_properties

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code style Improve code style of the generated code
Projects
None yet
Development

No branches or pull requests

2 participants