Skip to content
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

Various cs fixes #6504

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions docs/src/DependencyInjection/Compiler/AttributeFilterPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private function createFilterDefinitions(\ReflectionClass $resourceReflectionCla
}

if (null === $filterReflectionClass = $container->getReflectionClass($filterClass, false)) {
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $filterClass, $id));
throw new InvalidArgumentException(\sprintf('Class "%s" used for service "%s" cannot be found.', $filterClass, $id));
}

if ($container->has($filterClass) && ($parentDefinition = $container->findDefinition($filterClass))->isAbstract()) {
Expand All @@ -75,7 +75,7 @@ private function createFilterDefinitions(\ReflectionClass $resourceReflectionCla

foreach ($arguments as $key => $value) {
if (!isset($parameterNames[$key])) {
throw new InvalidArgumentException(sprintf('Class "%s" does not have argument "$%s".', $filterClass, $key));
throw new InvalidArgumentException(\sprintf('Class "%s" does not have argument "$%s".', $filterClass, $key));
}

$definition->setArgument("$$key", $value);
Expand Down
2 changes: 1 addition & 1 deletion src/Action/ExceptionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __invoke(FlattenException $exception, Request $request): Respons

$headers = $exception->getHeaders();
$format = ErrorFormatGuesser::guessErrorFormat($request, $this->errorFormats);
$headers['Content-Type'] = sprintf('%s; charset=utf-8', $format['value'][0]);
$headers['Content-Type'] = \sprintf('%s; charset=utf-8', $format['value'][0]);
$headers['X-Content-Type-Options'] = 'nosniff';
$headers['X-Frame-Options'] = 'deny';

Expand Down
2 changes: 1 addition & 1 deletion src/Api/CompositeIdentifierParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function stringify(array $identifiers): string
{
$composite = [];
foreach ($identifiers as $name => $value) {
$composite[] = sprintf('%s=%s', $name, $value);
$composite[] = \sprintf('%s=%s', $name, $value);
}

return implode(';', $composite);
Expand Down
2 changes: 1 addition & 1 deletion src/Api/FilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace ApiPlatform\Api;

if (interface_exists(\ApiPlatform\Metadata\FilterInterface::class)) {
trigger_deprecation('api-platform', '3.3', sprintf('%s is deprecated in favor of %s. This class will be removed in 4.0.', FilterInterface::class, \ApiPlatform\Metadata\FilterInterface::class));
trigger_deprecation('api-platform', '3.3', \sprintf('%s is deprecated in favor of %s. This class will be removed in 4.0.', FilterInterface::class, \ApiPlatform\Metadata\FilterInterface::class));
class_alias(
\ApiPlatform\Metadata\FilterInterface::class,
__NAMESPACE__.'\FilterInterface'
Expand Down
2 changes: 1 addition & 1 deletion src/Api/FilterLocatorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private function setFilterLocator(?ContainerInterface $filterLocator, bool $allo
if ($filterLocator instanceof ContainerInterface || (null === $filterLocator && $allowNull)) {
$this->filterLocator = $filterLocator;
} else {
throw new InvalidArgumentException(sprintf('The "$filterLocator" argument is expected to be an implementation of the "%s" interface%s.', ContainerInterface::class, $allowNull ? ' or null' : ''));
throw new InvalidArgumentException(\sprintf('The "$filterLocator" argument is expected to be an implementation of the "%s" interface%s.', ContainerInterface::class, $allowNull ? ' or null' : ''));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Api/IdentifiersExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private function getIdentifierValue(object $item, string $class, string $propert
$collectionValueType = $type->getCollectionValueTypes()[0] ?? null;

if (null !== $collectionValueType && $collectionValueType->getClassName() === $class) {
return $this->resolveIdentifierValue($this->propertyAccessor->getValue($item, sprintf('%s[0].%s', $propertyName, $property)), $parameterName);
return $this->resolveIdentifierValue($this->propertyAccessor->getValue($item, \sprintf('%s[0].%s', $propertyName, $property)), $parameterName);
}
}

Expand Down Expand Up @@ -162,6 +162,6 @@ private function resolveIdentifierValue(mixed $identifierValue, string $paramete
return (string) $identifierValue->value;
}

throw new RuntimeException(sprintf('We were not able to resolve the identifier matching parameter "%s".', $parameterName));
throw new RuntimeException(\sprintf('We were not able to resolve the identifier matching parameter "%s".', $parameterName));
}
}
8 changes: 4 additions & 4 deletions src/Api/QueryParameterValidator/Validator/ArrayItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public function validate(string $name, array $filterDescription, array $queryPar
$nbItems = \count($value);

if (null !== $maxItems && $nbItems > $maxItems) {
$errorList[] = sprintf('Query parameter "%s" must contain less than %d values', $name, $maxItems);
$errorList[] = \sprintf('Query parameter "%s" must contain less than %d values', $name, $maxItems);
}

if (null !== $minItems && $nbItems < $minItems) {
$errorList[] = sprintf('Query parameter "%s" must contain more than %d values', $name, $minItems);
$errorList[] = \sprintf('Query parameter "%s" must contain more than %d values', $name, $minItems);
}

if (true === $uniqueItems && $nbItems > \count(array_unique($value))) {
$errorList[] = sprintf('Query parameter "%s" must contain unique values', $name);
$errorList[] = \sprintf('Query parameter "%s" must contain unique values', $name);
}

return $errorList;
Expand Down Expand Up @@ -85,7 +85,7 @@ private static function getSeparator(string $collectionFormat): string
'ssv' => ' ',
'tsv' => '\t',
'pipes' => '|',
default => throw new \InvalidArgumentException(sprintf('Unknown collection format %s', $collectionFormat)),
default => throw new \InvalidArgumentException(\sprintf('Unknown collection format %s', $collectionFormat)),
};
}
}
8 changes: 4 additions & 4 deletions src/Api/QueryParameterValidator/Validator/Bounds.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ public function validate(string $name, array $filterDescription, array $queryPar

if (null !== $maximum) {
if (($filterDescription['openapi']['exclusiveMaximum'] ?? $filterDescription['swagger']['exclusiveMaximum'] ?? false) && $value >= $maximum) {
$errorList[] = sprintf('Query parameter "%s" must be less than %s', $name, $maximum);
$errorList[] = \sprintf('Query parameter "%s" must be less than %s', $name, $maximum);
} elseif ($value > $maximum) {
$errorList[] = sprintf('Query parameter "%s" must be less than or equal to %s', $name, $maximum);
$errorList[] = \sprintf('Query parameter "%s" must be less than or equal to %s', $name, $maximum);
}
}

if (null !== $minimum) {
if (($filterDescription['openapi']['exclusiveMinimum'] ?? $filterDescription['swagger']['exclusiveMinimum'] ?? false) && $value <= $minimum) {
$errorList[] = sprintf('Query parameter "%s" must be greater than %s', $name, $minimum);
$errorList[] = \sprintf('Query parameter "%s" must be greater than %s', $name, $minimum);
} elseif ($value < $minimum) {
$errorList[] = sprintf('Query parameter "%s" must be greater than or equal to %s', $name, $minimum);
$errorList[] = \sprintf('Query parameter "%s" must be greater than or equal to %s', $name, $minimum);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Api/QueryParameterValidator/Validator/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function validate(string $name, array $filterDescription, array $queryPar

if (null !== $enum && !\in_array($value, $enum, true)) {
return [
sprintf('Query parameter "%s" must be one of "%s"', $name, implode(', ', $enum)),
\sprintf('Query parameter "%s" must be one of "%s"', $name, implode(', ', $enum)),
];
}

Expand Down
4 changes: 2 additions & 2 deletions src/Api/QueryParameterValidator/Validator/Length.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public function validate(string $name, array $filterDescription, array $queryPar
$errorList = [];

if (null !== $maxLength && mb_strlen($value) > $maxLength) {
$errorList[] = sprintf('Query parameter "%s" length must be lower than or equal to %s', $name, $maxLength);
$errorList[] = \sprintf('Query parameter "%s" length must be lower than or equal to %s', $name, $maxLength);
}

if (null !== $minLength && mb_strlen($value) < $minLength) {
$errorList[] = sprintf('Query parameter "%s" length must be greater than or equal to %s', $name, $minLength);
$errorList[] = \sprintf('Query parameter "%s" length must be greater than or equal to %s', $name, $minLength);
}

return $errorList;
Expand Down
2 changes: 1 addition & 1 deletion src/Api/QueryParameterValidator/Validator/MultipleOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function validate(string $name, array $filterDescription, array $queryPar

if (null !== $multipleOf && 0 !== ($value % $multipleOf)) {
return [
sprintf('Query parameter "%s" must multiple of %s', $name, $multipleOf),
\sprintf('Query parameter "%s" must multiple of %s', $name, $multipleOf),
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Api/QueryParameterValidator/Validator/Pattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function validate(string $name, array $filterDescription, array $queryPar

if (null !== $pattern && !preg_match($pattern, $value)) {
return [
sprintf('Query parameter "%s" must match pattern %s', $name, $pattern),
\sprintf('Query parameter "%s" must match pattern %s', $name, $pattern),
];
}

Expand Down
4 changes: 2 additions & 2 deletions src/Api/QueryParameterValidator/Validator/Required.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function validate(string $name, array $filterDescription, array $queryPar
// if query param is not given, then break
if (!$this->requestHasQueryParameter($queryParameters, $name)) {
return [
sprintf('Query parameter "%s" is required', $name),
\sprintf('Query parameter "%s" is required', $name),
];
}

Expand All @@ -46,7 +46,7 @@ public function validate(string $name, array $filterDescription, array $queryPar
// if query param is empty and the configuration does not allow it
if (!($filterDescription['openapi']['allowEmptyValue'] ?? $filterDescription['swagger']['allowEmptyValue'] ?? false) && empty($this->requestGetQueryParameter($queryParameters, $name))) {
return [
sprintf('Query parameter "%s" does not allow empty value', $name),
\sprintf('Query parameter "%s" does not allow empty value', $name),
];
}

Expand Down
6 changes: 3 additions & 3 deletions src/Api/ResourceClassResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ public function getResourceClass(mixed $value, ?string $resourceClass = null, bo
}

if (null !== $actualClass && !$this->isResourceClass($actualClass)) {
throw new InvalidArgumentException(sprintf('No resource class found for object of type "%s".', $actualClass));
throw new InvalidArgumentException(\sprintf('No resource class found for object of type "%s".', $actualClass));
}

if (null !== $resourceClass && !$this->isResourceClass($resourceClass)) {
throw new InvalidArgumentException(sprintf('Specified class "%s" is not a resource class.', $resourceClass));
throw new InvalidArgumentException(\sprintf('Specified class "%s" is not a resource class.', $resourceClass));
}

if ($strict && null !== $actualClass && !is_a($actualClass, $resourceClass, true)) {
throw new InvalidArgumentException(sprintf('Object of type "%s" does not match "%s" resource class.', $actualClass, $resourceClass));
throw new InvalidArgumentException(\sprintf('Object of type "%s" does not match "%s" resource class.', $actualClass, $resourceClass));
}

$targetClass = $actualClass ?? $resourceClass;
Expand Down
2 changes: 1 addition & 1 deletion src/Api/UriVariablesConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function convert(array $uriVariables, string $class, array $context = [])
$uriVariables[$parameterName] = $uriVariableTransformer->transform($value, $types, $context);
break;
} catch (InvalidUriVariableException $e) {
throw new InvalidUriVariableException(sprintf('Identifier "%s" could not be transformed.', $parameterName), $e->getCode(), $e);
throw new InvalidUriVariableException(\sprintf('Identifier "%s" could not be transformed.', $parameterName), $e->getCode(), $e);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/Common/Filter/BooleanFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private function normalizeValue($value, string $property): ?bool
}

$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('Invalid boolean value for "%s" property, expected one of ( "%s" )', $property, implode('" | "', [
'exception' => new InvalidArgumentException(\sprintf('Invalid boolean value for "%s" property, expected one of ( "%s" )', $property, implode('" | "', [
'true',
'false',
'1',
Expand Down
4 changes: 2 additions & 2 deletions src/Doctrine/Common/Filter/DateFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected function getFilterDescription(string $property, string $period): array
$propertyName = $this->normalizePropertyName($property);

return [
sprintf('%s[%s]', $propertyName, $period) => [
\sprintf('%s[%s]', $propertyName, $period) => [
'property' => $propertyName,
'type' => \DateTimeInterface::class,
'required' => false,
Expand All @@ -85,7 +85,7 @@ private function normalizeValue($value, string $operator): ?string
{
if (false === \is_string($value)) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('Invalid value for "[%s]", expected string', $operator)),
'exception' => new InvalidArgumentException(\sprintf('Invalid value for "[%s]", expected string', $operator)),
]);

return null;
Expand Down
4 changes: 2 additions & 2 deletions src/Doctrine/Common/Filter/ExistsFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getDescription(string $resourceClass): array
continue;
}
$propertyName = $this->normalizePropertyName($property);
$description[sprintf('%s[%s]', $this->existsParameterName, $propertyName)] = [
$description[\sprintf('%s[%s]', $this->existsParameterName, $propertyName)] = [
'property' => $propertyName,
'type' => 'bool',
'required' => false,
Expand Down Expand Up @@ -81,7 +81,7 @@ private function normalizeValue($value, string $property): ?bool
}

$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('Invalid value for "%s[%s]", expected one of ( "%s" )', $this->existsParameterName, $property, implode('" | "', [
'exception' => new InvalidArgumentException(\sprintf('Invalid value for "%s[%s]", expected one of ( "%s" )', $this->existsParameterName, $property, implode('" | "', [
'true',
'false',
'1',
Expand Down
4 changes: 2 additions & 2 deletions src/Doctrine/Common/Filter/NumericFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function normalizeValues($value, string $property): ?array
{
if (!is_numeric($value) && (!\is_array($value) || !$this->isNumericArray($value))) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('Invalid numeric value for "%s" property', $property)),
'exception' => new InvalidArgumentException(\sprintf('Invalid numeric value for "%s" property', $property)),
]);

return null;
Expand All @@ -102,7 +102,7 @@ protected function normalizeValues($value, string $property): ?array

if (empty($values)) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('At least one value is required, multiple values should be in "%1$s[]=firstvalue&%1$s[]=secondvalue" format', $property)),
'exception' => new InvalidArgumentException(\sprintf('At least one value is required, multiple values should be in "%1$s[]=firstvalue&%1$s[]=secondvalue" format', $property)),
]);

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/Common/Filter/OrderFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getDescription(string $resourceClass): array
continue;
}
$propertyName = $this->normalizePropertyName($property);
$description[sprintf('%s[%s]', $this->orderParameterName, $propertyName)] = [
$description[\sprintf('%s[%s]', $this->orderParameterName, $propertyName)] = [
'property' => $propertyName,
'type' => 'string',
'required' => false,
Expand Down
10 changes: 5 additions & 5 deletions src/Doctrine/Common/Filter/RangeFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function getFilterDescription(string $fieldName, string $operator): ar
$propertyName = $this->normalizePropertyName($fieldName);

return [
sprintf('%s[%s]', $propertyName, $operator) => [
\sprintf('%s[%s]', $propertyName, $operator) => [
'property' => $propertyName,
'type' => 'string',
'required' => false,
Expand All @@ -88,7 +88,7 @@ private function normalizeValues(array $values, string $property): ?array

if (empty($values)) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('At least one valid operator ("%s") is required for "%s" property', implode('", "', $operators), $property)),
'exception' => new InvalidArgumentException(\sprintf('At least one valid operator ("%s") is required for "%s" property', implode('", "', $operators), $property)),
]);

return null;
Expand All @@ -104,15 +104,15 @@ private function normalizeBetweenValues(array $values): ?array
{
if (2 !== \count($values)) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('Invalid format for "[%s]", expected "<min>..<max>"', self::PARAMETER_BETWEEN)),
'exception' => new InvalidArgumentException(\sprintf('Invalid format for "[%s]", expected "<min>..<max>"', self::PARAMETER_BETWEEN)),
]);

return null;
}

if (!is_numeric($values[0]) || !is_numeric($values[1])) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('Invalid values for "[%s]" range, expected numbers', self::PARAMETER_BETWEEN)),
'exception' => new InvalidArgumentException(\sprintf('Invalid values for "[%s]" range, expected numbers', self::PARAMETER_BETWEEN)),
]);

return null;
Expand All @@ -128,7 +128,7 @@ private function normalizeValue(string $value, string $operator): float|int|null
{
if (!is_numeric($value)) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('Invalid value for "[%s]", expected number', $operator)),
'exception' => new InvalidArgumentException(\sprintf('Invalid value for "[%s]", expected number', $operator)),
]);

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/Common/Filter/SearchFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ protected function normalizeValues(array $values, string $property): ?array

if (empty($values)) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('At least one value is required, multiple values should be in "%1$s[]=firstvalue&%1$s[]=secondvalue" format', $property)),
'exception' => new InvalidArgumentException(\sprintf('At least one value is required, multiple values should be in "%1$s[]=firstvalue&%1$s[]=secondvalue" format', $property)),
]);

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/Common/State/LinksHandlerLocatorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ private function getLinksHandler(Operation $operation): ?callable
return [$this->handleLinksLocator->get($handleLinks), 'handleLinks'];
}

throw new RuntimeException(sprintf('Could not find handleLinks service "%s"', $handleLinks));
throw new RuntimeException(\sprintf('Could not find handleLinks service "%s"', $handleLinks));
}
}
Loading
Loading