Skip to content

Commit f768b94

Browse files
committed
refactor: correct more PHPStan discoverd issues
1 parent 6890b03 commit f768b94

File tree

4 files changed

+11
-23
lines changed

4 files changed

+11
-23
lines changed

phpstan-baseline.neon

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,12 @@ parameters:
6666
path: src/JsonSchema/Constraints/Factory.php
6767

6868
-
69-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:getConfig\\(\\) should return int\\<0, 511\\> but returns int\\.$#"
69+
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:getConfig\\(\\) should return int\\<0, 1023\\> but returns int\\.$#"
7070
count: 1
7171
path: src/JsonSchema/Constraints/Factory.php
7272

7373
-
74-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:getErrorContext\\(\\) should return 1\\|2 but returns int\\.$#"
75-
count: 1
76-
path: src/JsonSchema/Constraints/Factory.php
77-
78-
-
79-
message: "#^Property JsonSchema\\\\Constraints\\\\Factory\\:\\:\\$checkMode \\(int\\<0, 511\\>\\) does not accept int\\.$#"
74+
message: "#^Property JsonSchema\\\\Constraints\\\\Factory\\:\\:\\$checkMode \\(int\\<0, 1023\\>\\) does not accept int\\.$#"
8075
count: 2
8176
path: src/JsonSchema/Constraints/Factory.php
8277

@@ -630,16 +625,6 @@ parameters:
630625
count: 1
631626
path: src/JsonSchema/Iterator/ObjectIterator.php
632627

633-
-
634-
message: "#^Offset 4 does not exist on array\\{0\\: string, 1\\: non\\-falsy\\-string, 2\\: string, 3\\: non\\-falsy\\-string, 4\\?\\: string, 5\\?\\: non\\-falsy\\-string&numeric\\-string\\}\\.$#"
635-
count: 1
636-
path: src/JsonSchema/Rfc3339.php
637-
638-
-
639-
message: "#^Offset 5 does not exist on array\\{0\\: string, 1\\: non\\-falsy\\-string, 2\\: string, 3\\: non\\-falsy\\-string, 4\\?\\: string, 5\\?\\: non\\-falsy\\-string&numeric\\-string\\}\\.$#"
640-
count: 1
641-
path: src/JsonSchema/Rfc3339.php
642-
643628
-
644629
message: "#^Access to an undefined property object\\:\\:\\$properties\\.$#"
645630
count: 3

src/JsonSchema/Constraints/Factory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Factory
4646
private $typeCheck = [];
4747

4848
/**
49-
* @var int Validation context
49+
* @var int-mask-of<Validator::ERROR_*> Validation context
5050
*/
5151
protected $errorContext = Validator::ERROR_DOCUMENT_VALIDATION;
5252

@@ -199,7 +199,7 @@ public function createInstanceFor($constraintName)
199199
/**
200200
* Get the error context
201201
*
202-
* @phpstan-return Validator::ERROR_DOCUMENT_VALIDATION|Validator::ERROR_SCHEMA_VALIDATION
202+
* @return int-mask-of<Validator::ERROR_*>
203203
*/
204204
public function getErrorContext(): int
205205
{
@@ -209,7 +209,7 @@ public function getErrorContext(): int
209209
/**
210210
* Set the error context
211211
*
212-
* @phpstan-param Validator::ERROR_DOCUMENT_VALIDATION|Validator::ERROR_SCHEMA_VALIDATION $errorContext
212+
* @param int-mask-of<Validator::ERROR_*> $errorContext
213213
*/
214214
public function setErrorContext(int $errorContext): void
215215
{

src/JsonSchema/Entity/ErrorBag.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* pointer: string,
1717
* message: string,
1818
* constraint: array{name: string, params: array<string, mixed>},
19-
* context: int
19+
* "context": int-mask-of<Validator::ERROR_*>
2020
* }
2121
* @phpstan-type ErrorList list<Error>
2222
*/
@@ -29,8 +29,7 @@ class ErrorBag
2929
private $errors = [];
3030

3131
/**
32-
* @var int All error types that have occurred
33-
* @phpstan-var int-mask-of<Validator::ERROR_*>
32+
* @var int-mask-of<Validator::ERROR_*> All error types that have occurred
3433
*/
3534
protected $errorMask = Validator::ERROR_NONE;
3635

@@ -56,6 +55,7 @@ public function addError(ConstraintError $constraint, ?JsonPointer $path = null,
5655
{
5756
$message = $constraint->getMessage();
5857
$name = $constraint->getValue();
58+
/** @var Error $error */
5959
$error = [
6060
'property' => $this->convertJsonPointerIntoPropertyPath($path ?: new JsonPointer('')),
6161
'pointer' => ltrim((string) ($path ?: new JsonPointer('')), '#'),

src/JsonSchema/Rfc3339.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public static function createFromString($input): ?\DateTime
4949
}
5050

5151
$mutable = \DateTime::createFromFormat('U.u', $dateTime->format('U.u'));
52+
if ($mutable === false) {
53+
throw new \RuntimeException('Unable to create DateTime from DateTimeImmutable');
54+
}
5255
$mutable->setTimezone($dateTime->getTimezone());
5356

5457
return $mutable;

0 commit comments

Comments
 (0)