Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/JsonSchema/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class Validator extends BaseConstraint
{
public const SCHEMA_MEDIA_TYPE = 'application/schema+json';

public const ERROR_NONE = 0x00000000;
public const ERROR_ALL = 0xFFFFFFFF;
public const ERROR_DOCUMENT_VALIDATION = 0x00000001;
public const ERROR_SCHEMA_VALIDATION = 0x00000002;
public const ERROR_NONE = 0;
public const ERROR_ALL = -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self::ERROR_DOCUMENT_VALIDATION | self::ERROR_SCHEMA_VALIDATION also should work here no? Or just hardcode 3 because frankly this is very unlikely to change, so if a new type is added with 4 then you just gotta update the ERROR_ALL.. Doesn't sound that hard 🤷🏻

Suggested change
public const ERROR_ALL = -1;
public const ERROR_ALL = self::ERROR_DOCUMENT_VALIDATION | self::ERROR_SCHEMA_VALIDATION;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes more sense to me to use -1 for an E_ALL level. Like error_reporting(-1) is a common way to turn on all error levels for the engine...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, works for me with -1 too.. Not sure why PHPStan complains though, but I tried on my machine and wasn't able to quiet it down. Seems like the 0xFFFFFFFF makes it give up on some checks.

Copy link
Contributor

@staabm staabm Apr 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phpstan complains because it doesn’t support int-ranges from binary & and | operator yet.

see phpstan/phpstan#7912

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks, i thought i saw this work but must remember it wrong then :)

public const ERROR_DOCUMENT_VALIDATION = 1;
public const ERROR_SCHEMA_VALIDATION = 2;

/**
* Validates the given data against the schema and returns an object containing the results
Expand Down
Loading