Skip to content

Commit

Permalink
Apply latest CS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Spea committed Jan 17, 2025
1 parent e207240 commit e2bb36f
Show file tree
Hide file tree
Showing 24 changed files with 57 additions and 58 deletions.
1 change: 0 additions & 1 deletion src/Annotation/Preferred.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* different versions with JMS serializer, and not specifying any version.
*
* @Annotation
*
* @Target({"METHOD", "PROPERTY"})
*/
final class Preferred
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/InvalidTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ final class InvalidTypeException extends SchemaException
{
private const CLASS_NOT_FOUND = 'Class or interface "%s" could not be found, maybe it\'s not autoloadable?';

public static function classNotFound(string $className, \Exception $previousException = null): self
public static function classNotFound(string $className, ?\Exception $previousException = null): self
{
return new self(
sprintf(self::CLASS_NOT_FOUND, $className),
\sprintf(self::CLASS_NOT_FOUND, $className),
$previousException ? $previousException->getCode() : 0,
$previousException
);
Expand Down
22 changes: 11 additions & 11 deletions src/Exception/ParseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class ParseException extends SchemaException
public static function classNotFound(string $className, \Exception $previousException): self
{
return new self(
sprintf(self::CLASS_NOT_FOUND, $className),
\sprintf(self::CLASS_NOT_FOUND, $className),
$previousException->getCode(),
$previousException
);
Expand All @@ -31,7 +31,7 @@ public static function classNotFound(string $className, \Exception $previousExce
public static function classError(string $className, \Exception $previousException): self
{
return new self(
sprintf(self::CLASS_ERROR, $className, $previousException->getMessage()),
\sprintf(self::CLASS_ERROR, $className, $previousException->getMessage()),
$previousException->getCode(),
$previousException
);
Expand All @@ -40,7 +40,7 @@ public static function classError(string $className, \Exception $previousExcepti
public static function propertyError(string $className, string $propertyName, \Exception $previousException): self
{
return new self(
sprintf(self::PROPERTY_ERROR, $className, $propertyName, $previousException->getMessage()),
\sprintf(self::PROPERTY_ERROR, $className, $propertyName, $previousException->getMessage()),
$previousException->getCode(),
$previousException
);
Expand All @@ -49,48 +49,48 @@ public static function propertyError(string $className, string $propertyName, \E
public static function propertyTypeError(string $className, string $propertyName, \Exception $previousException): self
{
return new self(
sprintf(self::PROPERTY_TYPE_ERROR, $className, $propertyName, $previousException->getMessage()),
\sprintf(self::PROPERTY_TYPE_ERROR, $className, $propertyName, $previousException->getMessage()),
$previousException->getCode(),
$previousException
);
}

public static function propertyTypeNameNull(string $className, string $propertyName): self
{
return new self(sprintf(self::PROPERTY_TYPE_NAME_NULL, $className, $propertyName));
return new self(\sprintf(self::PROPERTY_TYPE_NAME_NULL, $className, $propertyName));
}

public static function propertyTypeConflict(string $className, string $propertyName, string $typeA, string $typeB, \Exception $previousException): self
{
return new self(
sprintf(self::PROPERTY_TYPE_CONFLICT, $className, $propertyName, $typeA, $typeB),
\sprintf(self::PROPERTY_TYPE_CONFLICT, $className, $propertyName, $typeA, $typeB),
$previousException->getCode(),
$previousException
);
}

public static function unsupportedClassAnnotation(string $className, string $annotation): self
{
return new self(sprintf(self::UNSUPPORTED_CLASS_ANNOTATION, $className, $annotation));
return new self(\sprintf(self::UNSUPPORTED_CLASS_ANNOTATION, $className, $annotation));
}

public static function unsupportedPropertyAnnotation(string $className, string $propertyName, string $annotation): self
{
return new self(sprintf(self::UNSUPPORTED_PROPERTY_ANNOTATION, $className, $propertyName, $annotation));
return new self(\sprintf(self::UNSUPPORTED_PROPERTY_ANNOTATION, $className, $propertyName, $annotation));
}

public static function nonPublicMethod(string $className, string $methodName): self
{
return new self(sprintf(self::NON_PUBLIC_METHOD, $className, $methodName));
return new self(\sprintf(self::NON_PUBLIC_METHOD, $className, $methodName));
}

public static function propertyAlreadyExists(string $propertyName, string $className): self
{
return new self(sprintf(self::PROPERTY_ALREADY_EXISTS, $propertyName, $className));
return new self(\sprintf(self::PROPERTY_ALREADY_EXISTS, $propertyName, $className));
}

public static function classNotParsed(string $notFoundClassName, string $className, string $propertyName): self
{
return new self(sprintf(self::CLASS_NOT_PARSED, $notFoundClassName, $className, $propertyName));
return new self(\sprintf(self::CLASS_NOT_PARSED, $notFoundClassName, $className, $propertyName));
}
}
2 changes: 1 addition & 1 deletion src/Exception/RecursionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class RecursionException extends SchemaException

public static function forClass(string $className, RecursionContext $context): self
{
return new self(sprintf(
return new self(\sprintf(
self::FOR_CLASS,
$className,
(string) $context
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/AbstractPropertyMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function hasCustomInformation(string $key): bool
public function getCustomInformation(string $key): mixed
{
if (!\array_key_exists($key, $this->customInformation)) {
throw new \InvalidArgumentException(sprintf('Property %s has no custom information %s', $this->name, $key));
throw new \InvalidArgumentException(\sprintf('Property %s has no custom information %s', $this->name, $key));
}

return $this->customInformation[$key];
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function getConstructorParameter(string $name): ParameterMetadata
}
}

throw new \InvalidArgumentException(sprintf('Class %s has no constructor parameter called "%s"', $this->className, $name));
throw new \InvalidArgumentException(\sprintf('Class %s has no constructor parameter called "%s"', $this->className, $name));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/ParameterMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function isRequired(): bool
public function getDefaultValue()
{
if ($this->required) {
throw new \BadMethodCallException(sprintf('Parameter %s is required and therefore has no default value', (string) $this));
throw new \BadMethodCallException(\sprintf('Parameter %s is required and therefore has no default value', (string) $this));
}

return $this->defaultValue;
Expand Down
8 changes: 4 additions & 4 deletions src/Metadata/PropertyMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ final class PropertyMetadata extends AbstractPropertyMetadata
public function __construct(
string $serializedName,
string $name,
PropertyType $type = null,
?PropertyType $type = null,
bool $readOnly = true,
bool $public = false,
VersionRange $versionRange = null,
?VersionRange $versionRange = null,
array $groups = [],
PropertyAccessor $accessor = null,
?PropertyAccessor $accessor = null,
array $customInformation = [],
int $maxDepth = null
?int $maxDepth = null,
) {
parent::__construct($name, $readOnly, $public);
$this->serializedName = $serializedName;
Expand Down
6 changes: 3 additions & 3 deletions src/Metadata/PropertyTypeClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(string $className, bool $nullable)
{
parent::__construct($nullable);
if (!self::isTypeCustomClass($className)) {
throw new InvalidTypeException(sprintf('Given type "%s" is not a custom class or interface but another supported type', $className));
throw new InvalidTypeException(\sprintf('Given type "%s" is not a custom class or interface but another supported type', $className));
}
if (!class_exists($className) && !interface_exists($className)) {
throw InvalidTypeException::classNotFound($className);
Expand Down Expand Up @@ -75,10 +75,10 @@ public function merge(PropertyType $other): PropertyType
return $other->merge($this);
}
if (!$other instanceof self) {
throw new \UnexpectedValueException(sprintf('Can\'t merge type %s with %s, they must be the same or unknown', self::class, \get_class($other)));
throw new \UnexpectedValueException(\sprintf('Can\'t merge type %s with %s, they must be the same or unknown', self::class, \get_class($other)));
}
if ($this->getClassName() !== $other->getClassName()) {
throw new \UnexpectedValueException(sprintf('Can\'t merge type %s with %s, they must be equal', self::class, \get_class($other)));
throw new \UnexpectedValueException(\sprintf('Can\'t merge type %s with %s, they must be equal', self::class, \get_class($other)));
}

return new self($this->className, $nullable);
Expand Down
6 changes: 3 additions & 3 deletions src/Metadata/PropertyTypeDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class PropertyTypeDateTime extends AbstractPropertyType
*/
private $dateTimeOptions;

public function __construct(bool $immutable, bool $nullable, DateTimeOptions $dateTimeOptions = null)
public function __construct(bool $immutable, bool $nullable, ?DateTimeOptions $dateTimeOptions = null)
{
parent::__construct($nullable);
$this->immutable = $immutable;
Expand Down Expand Up @@ -108,10 +108,10 @@ public function merge(PropertyType $other): PropertyType
return new self($this->immutable, $nullable, $options);
}

public static function fromDateTimeClass(string $className, bool $nullable, DateTimeOptions $dateTimeOptions = null): self
public static function fromDateTimeClass(string $className, bool $nullable, ?DateTimeOptions $dateTimeOptions = null): self
{
if (!self::isTypeDateTime($className)) {
throw new \UnexpectedValueException(sprintf('Given type "%s" is not date time class or interface', $className));
throw new \UnexpectedValueException(\sprintf('Given type "%s" is not date time class or interface', $className));
}

return new self(\DateTimeImmutable::class === $className, $nullable, $dateTimeOptions);
Expand Down
8 changes: 4 additions & 4 deletions src/Metadata/PropertyTypeIterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class PropertyTypeIterable extends AbstractPropertyType
/**
* @param class-string<\Traversable>|null $traversableClass
*/
public function __construct(PropertyType $subType, bool $hashmap, bool $nullable, string $traversableClass = null)
public function __construct(PropertyType $subType, bool $hashmap, bool $nullable, ?string $traversableClass = null)
{
parent::__construct($nullable);

Expand All @@ -48,7 +48,7 @@ public function __toString(): string
$array = $this->isHashmap() ? '[string]' : '[]';
if ($this->isTraversable()) {
$collectionType = $this->isHashmap() ? ', string' : '';
$array .= sprintf('|\\%s<%s%s>', $this->traversableClass, $this->subType, $collectionType);
$array .= \sprintf('|\%s<%s%s>', $this->traversableClass, $this->subType, $collectionType);
}

return ((string) $this->subType).$array.parent::__toString();
Expand Down Expand Up @@ -109,7 +109,7 @@ public function merge(PropertyType $other): PropertyType
return new self($this->getSubType(), $this->isHashmap(), $nullable, $this->findCommonTraversableClass($thisTraversableClass, $other->getClassName()));
}
if (!$other instanceof self) {
throw new \UnexpectedValueException(sprintf('Can\'t merge type %s with %s, they must be the same or unknown', self::class, \get_class($other)));
throw new \UnexpectedValueException(\sprintf('Can\'t merge type %s with %s, they must be the same or unknown', self::class, \get_class($other)));
}

/*
Expand All @@ -118,7 +118,7 @@ public function merge(PropertyType $other): PropertyType
* PHPDoc has no clear definition for hashmaps with string indexes, but JMS Serializer annotations do.
*/
if ($this->isHashmap() && !$other->isHashmap()) {
throw new \UnexpectedValueException(sprintf('Can\'t merge type %s with %s, can\'t change hashmap into plain array', self::class, \get_class($other)));
throw new \UnexpectedValueException(\sprintf('Can\'t merge type %s with %s, can\'t change hashmap into plain array', self::class, \get_class($other)));
}

$otherTraversableClass = $other->isTraversable() ? $other->getTraversableClass() : null;
Expand Down
6 changes: 3 additions & 3 deletions src/Metadata/PropertyTypePrimitive.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(string $typeName, bool $nullable)
$typeName = self::TYPE_MAP[$typeName];
}
if (!self::isTypePrimitive($typeName)) {
throw new \UnexpectedValueException(sprintf('Given type "%s" is not primitive', $typeName));
throw new \UnexpectedValueException(\sprintf('Given type "%s" is not primitive', $typeName));
}
$this->typeName = $typeName;
}
Expand All @@ -55,10 +55,10 @@ public function merge(PropertyType $other): PropertyType
return new self($this->typeName, $nullable);
}
if (!$other instanceof self) {
throw new \UnexpectedValueException(sprintf('Can\'t merge type %s with %s, they must be the same or unknown', self::class, \get_class($other)));
throw new \UnexpectedValueException(\sprintf('Can\'t merge type %s with %s, they must be the same or unknown', self::class, \get_class($other)));
}
if ($this->getTypeName() !== $other->getTypeName()) {
throw new \UnexpectedValueException(sprintf('Can\'t merge type %s with %s, they must be equal', self::class, \get_class($other)));
throw new \UnexpectedValueException(\sprintf('Can\'t merge type %s with %s, they must be equal', self::class, \get_class($other)));
}

return new self($this->typeName, $nullable);
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/PropertyTypeUnknown.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __toString(): string
public function merge(PropertyType $other): PropertyType
{
if (!$other instanceof self) {
throw new \UnexpectedValueException(sprintf('Can\'t merge type %s with %s, they must be the same', self::class, \get_class($other)));
throw new \UnexpectedValueException(\sprintf('Can\'t merge type %s with %s, they must be the same', self::class, \get_class($other)));
}

return new self($this->isNullable() && $other->isNullable());
Expand Down
2 changes: 1 addition & 1 deletion src/ModelParser/ParserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __toString(): string
return $propertyMetadata->getName();
}, $this->stack);

return sprintf('%s->%s', $this->root, implode('->', $stack));
return \sprintf('%s->%s', $this->root, implode('->', $stack));
}

public function push(PropertyVariationMetadata $property): self
Expand Down
4 changes: 2 additions & 2 deletions src/ModelParser/RawMetadata/PropertyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function serializedName(string $name): string
return $name;
}

return strtolower(preg_replace('/[A-Z]/', '_\\0', $name));
return strtolower(preg_replace('/[A-Z]/', '_\0', $name));
}

public static function useIdenticalNamingStrategy($value = true): void
Expand Down Expand Up @@ -106,7 +106,7 @@ public function getVariation(string $name): PropertyVariationMetadata
{
$property = $this->findVariation($name);
if (null === $property) {
throw new \UnexpectedValueException(sprintf('Property variation %s not found on PropertyCollection %s', $name, $this->serializedName));
throw new \UnexpectedValueException(\sprintf('Property variation %s not found on PropertyCollection %s', $name, $this->serializedName));
}

return $property;
Expand Down
12 changes: 6 additions & 6 deletions src/ModelParser/RawMetadata/RawClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function getPropertyVariation(string $name): PropertyVariationMetadata
{
$property = $this->findPropertyVariation($name);
if (null === $property) {
throw new \UnexpectedValueException(sprintf('Property variation %s not found on class %s', $name, $this->className));
throw new \UnexpectedValueException(\sprintf('Property variation %s not found on class %s', $name, $this->className));
}

return $property;
Expand Down Expand Up @@ -105,22 +105,22 @@ public function addPropertyVariation(string $serializedName, PropertyVariationMe
public function renameProperty(string $propertyName, string $serializedName): void
{
if (!$this->hasPropertyCollection($propertyName)) {
throw new \UnexpectedValueException(sprintf('Property "%s::%s" not found to rename', (string) $this, $propertyName));
throw new \UnexpectedValueException(\sprintf('Property "%s::%s" not found to rename', (string) $this, $propertyName));
}
$prop = $this->getPropertyCollection($propertyName);

if ($this->hasPropertyCollection($serializedName)) {
$target = $this->getPropertyCollection($serializedName);
if ($target === $prop) {
throw new \LogicException(sprintf('You can not rename %s into %s as it is the same property. Did you miss to handle camelCase properties with PropertyCollection::serializedName?', $propertyName, $serializedName));
throw new \LogicException(\sprintf('You can not rename %s into %s as it is the same property. Did you miss to handle camelCase properties with PropertyCollection::serializedName?', $propertyName, $serializedName));
}
foreach ($target->getVariations() as $variation) {
$prop->addVariation($variation);
}

$key = array_search($target, $this->properties, true);
if (false === $key) {
throw new \RuntimeException(sprintf('This should not be possible: Target property %s found but then not found $this->properties. While renaming from %s::%s', $serializedName, $this->getClassName(), $propertyName));
throw new \RuntimeException(\sprintf('This should not be possible: Target property %s found but then not found $this->properties. While renaming from %s::%s', $serializedName, $this->getClassName(), $propertyName));
}
unset($this->properties[$key]);
}
Expand Down Expand Up @@ -174,7 +174,7 @@ public function getPropertyCollection(string $serializedName): PropertyCollectio
{
$property = $this->findPropertyCollection($serializedName);
if (null === $property) {
throw new \UnexpectedValueException(sprintf('Property collection %s not found on class %s', $serializedName, $this->className));
throw new \UnexpectedValueException(\sprintf('Property collection %s not found on class %s', $serializedName, $this->className));
}

return $property;
Expand All @@ -186,7 +186,7 @@ public function getPropertyCollection(string $serializedName): PropertyCollectio
public function addPropertyCollection(PropertyCollection $property): void
{
if ($this->hasPropertyCollection($property->getSerializedName())) {
throw new \UnexpectedValueException(sprintf('Property "%s" is already defined on model %s, cannot add it twice', (string) $property, (string) $this));
throw new \UnexpectedValueException(\sprintf('Property "%s" is already defined on model %s, cannot add it twice', (string) $property, (string) $this));
}

$this->properties[] = $property;
Expand Down
2 changes: 1 addition & 1 deletion src/RawClassMetadataRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class RawClassMetadataRegistry
public function add(RawClassMetadata $classMetadata): void
{
if ($this->contains($classMetadata->getClassName())) {
throw new \BadMethodCallException(sprintf('The model for "%s" is already in the registry', $classMetadata->getClassName()));
throw new \BadMethodCallException(\sprintf('The model for "%s" is already in the registry', $classMetadata->getClassName()));
}

$this->classMetadata[$classMetadata->getClassName()] = $classMetadata;
Expand Down
Loading

0 comments on commit e2bb36f

Please sign in to comment.