Skip to content

Commit 5b1cdee

Browse files
committed
chore(phpstan): fix latest issues detection
1 parent b5878d1 commit 5b1cdee

File tree

14 files changed

+56
-21
lines changed

14 files changed

+56
-21
lines changed

src/Bridge/LeagueOpenAPIValidation/Exception/InvalidOpenApiDefinitionException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class InvalidOpenApiDefinitionException extends InvalidArgumentException
99
{
1010
public function __construct(Throwable $previous)
1111
{
12-
parent::__construct(sprintf(
12+
parent::__construct(\sprintf(
1313
"The given OpenApi definition can't be loaded:\n%s -> %s",
1414
$previous::class,
1515
$previous->getMessage()

src/Bridge/LeagueOpenAPIValidation/Factory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function fromYamlFile(string $path): self
2323
{
2424
if (!is_readable($path)) {
2525
throw new InvalidArgumentException(
26-
sprintf('Filename given isn\'t readable: %s', $path)
26+
\sprintf('Filename given isn\'t readable: %s', $path)
2727
);
2828
}
2929

@@ -36,7 +36,7 @@ public static function fromJsonFile(string $path): self
3636
{
3737
if (!is_readable($path)) {
3838
throw new InvalidArgumentException(
39-
sprintf('Filename given isn\'t readable: %s', $path)
39+
\sprintf('Filename given isn\'t readable: %s', $path)
4040
);
4141
}
4242

src/Http/Factory/Headers.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,18 @@ public function __construct(mixed $headers = [])
2525
}
2626

2727
foreach ($headers as $name => $values) {
28-
$this->set($name, $values);
28+
if (\is_string($values)) {
29+
$this->set($name, $values);
30+
} elseif (\is_array($values)) {
31+
foreach ($values as $value) {
32+
if (!\is_string($value)) {
33+
throw new InvalidArgumentException('Header values must be string[]|string.');
34+
}
35+
$this->set($name, $value);
36+
}
37+
} else {
38+
throw new InvalidArgumentException('Header values must be string[]|string.');
39+
}
2940
}
3041
}
3142

@@ -40,7 +51,7 @@ public function __toString(): string
4051
foreach ($this->headers as $name => $values) {
4152
$name = ucwords($name, '-');
4253
foreach ($values as $value) {
43-
$asString .= sprintf('%s: %s', $name, $value).PHP_EOL;
54+
$asString .= \sprintf('%s: %s', $name, $value).PHP_EOL;
4455
}
4556
}
4657

src/Http/Factory/Resolver/FakerValueResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private function resolveFakerValue(array $matches): mixed
3838
);
3939
} catch (InvalidArgumentException) {
4040
} catch (JsonException $error) {
41-
$message = sprintf(
41+
$message = \sprintf(
4242
"Can't extract the arguments to call method %s: [%s]",
4343
$matches[1],
4444
$matches[2]

src/Http/Factory/Uri.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,42 @@ class Uri implements Stringable
1212
public function __construct(mixed $value)
1313
{
1414
if (\is_array($value)) {
15-
if (!isset($value['base'])) {
15+
if (!\is_string($value['base'])) {
1616
throw new InvalidArgumentException(
1717
'If you want to build an URI from an array, use the schema: [ base => string, ?parameters => [string => mixed]'
1818
);
1919
}
2020

21+
// Check if parameters is a valid string[]
2122
$parameters = $value['parameters'] ?? [];
22-
$value = str_replace(array_keys($parameters), $parameters, (string) $value['base']);
23-
} elseif (!\is_string($value)) {
23+
if (!\is_array($parameters)) {
24+
throw new InvalidArgumentException('value parameters must be an array.');
25+
}
26+
27+
$search = [];
28+
$replace = [];
29+
foreach ($parameters as $name => $parameter) {
30+
if (!\is_string($name) || !\is_string($parameter)) {
31+
throw new InvalidArgumentException(\sprintf(
32+
'Invalid parameter given {name: %s, parameter: %s}',
33+
var_export($name, true),
34+
var_export($parameter, true)
35+
));
36+
}
37+
$search[] = $name;
38+
$replace[] = $parameter;
39+
}
40+
41+
$this->uri = str_replace(
42+
$search,
43+
$replace,
44+
(string) $value['base']
45+
);
46+
} elseif (\is_string($value)) {
47+
$this->uri = $value;
48+
} else {
2449
throw new InvalidArgumentException('$value must be a string or an array.');
2550
}
26-
$this->uri = $value;
2751
}
2852

2953
public function __toString(): string

src/Validator/Exception/ApiSchemaException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ApiSchemaException extends RuntimeException implements ValidationException
1010
public function __construct(
1111
Throwable $previous
1212
) {
13-
$message = sprintf(
13+
$message = \sprintf(
1414
'Something went wrong with the API schema: %s.',
1515
$previous->getMessage()
1616
);

src/Validator/Exception/DataSchemaException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function __construct(
1212
public readonly string $path,
1313
Throwable $previous
1414
) {
15-
$message = sprintf(
15+
$message = \sprintf(
1616
"Data validation failed for property \"%s\", invalid value: %s\n\n> %s",
1717
$path,
1818
var_export($value, true),

src/Validator/Exception/GenericException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class GenericException extends RuntimeException implements ValidationException
1010
public function __construct(
1111
Throwable $previous
1212
) {
13-
$message = sprintf(
13+
$message = \sprintf(
1414
'Something went wrong: %s.',
1515
$previous->getMessage()
1616
);

src/Validator/Exception/OperationNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function __construct(
1212
public readonly RequestInterface $request,
1313
Throwable $previous = null
1414
) {
15-
$message = sprintf(
15+
$message = \sprintf(
1616
'API operation for request [%s] %s hasn\'t been found.',
1717
$request->getMethod(),
1818
$request->getUri()

src/Validator/Exception/ResponseNotExpectedException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function __construct(
1414
public readonly ResponseInterface $response,
1515
Throwable $previous
1616
) {
17-
$message = sprintf(
17+
$message = \sprintf(
1818
'API response with status code %d isn\'t defined in the spec for request [%s] %s.',
1919
$response->getStatusCode(),
2020
$request->getMethod(),

0 commit comments

Comments
 (0)