Skip to content

Commit

Permalink
minor #152 apply code style fixes (xabbuh)
Browse files Browse the repository at this point in the history
This PR was merged into the 0.3-dev branch.

Discussion
----------

apply code style fixes

Commits
-------

9dd89ab apply code style fixes
  • Loading branch information
xabbuh committed Sep 16, 2024
2 parents a24418d + 9dd89ab commit 1f77828
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Qossmic/DataMapper/DataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function mapFormsToData(\Traversable $forms, mixed &$data): void
if (1 === \count($forms)) {
$this->propertyAccessor->setValue($data, $writePropertyPath, reset($forms)->getData());
} elseif (!\is_object($data)) {
throw new LogicException(sprintf('Mapping multiple forms to a single method requires the form data to be an object but is "%s".', \gettype($data)));
throw new LogicException(\sprintf('Mapping multiple forms to a single method requires the form data to be an object but is "%s".', \gettype($data)));
} else {
$formData = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Qossmic/ExceptionHandling/ExceptionHandlerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function has(string $strategy): bool
public function get(string $strategy): ExceptionHandlerInterface
{
if (!isset($this->strategies[$strategy])) {
throw new \InvalidArgumentException(sprintf('The exception handling strategy "%s" is not registered (use one of ["%s"]).', $strategy, implode(', ', array_keys($this->strategies))));
throw new \InvalidArgumentException(\sprintf('The exception handling strategy "%s" is not registered (use one of ["%s"]).', $strategy, implode(', ', array_keys($this->strategies))));
}

/* @phpstan-ignore-next-line */
Expand Down
4 changes: 2 additions & 2 deletions src/Qossmic/Extension/RichModelFormsTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function configureOptions(OptionsResolver $resolver): void

foreach ($value as $strategy) {
if (!$this->exceptionHandlerRegistry->has($strategy)) {
throw new InvalidConfigurationException(sprintf('The "%s" error handling strategy is not registered.', $strategy));
throw new InvalidConfigurationException(\sprintf('The "%s" error handling strategy is not registered.', $strategy));
}
}

Expand All @@ -134,7 +134,7 @@ public function configureOptions(OptionsResolver $resolver): void
$resolver->setAllowedTypes('factory', ['string', 'array', 'null', \Closure::class]);
$resolver->setNormalizer('factory', function (Options $options, $value) {
if (\is_string($value) && !class_exists($value)) {
throw new InvalidConfigurationException(sprintf('The configured value for the "factory" option is not a valid class name ("%s" given).', $value));
throw new InvalidConfigurationException(\sprintf('The configured value for the "factory" option is not a valid class name ("%s" given).', $value));
}

if (\is_array($value) && !\is_callable($value)) {
Expand Down
6 changes: 3 additions & 3 deletions src/Qossmic/Instantiator/ObjectInstantiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ public function instantiateObject(): ?object
$factoryMethod = (new \ReflectionClass($this->factory))->getConstructor();

if (null === $factoryMethod) {
throw new TransformationFailedException(sprintf('The class "%s" used as a factory does not have a constructor.', $this->factory));
throw new TransformationFailedException(\sprintf('The class "%s" used as a factory does not have a constructor.', $this->factory));
}

$factoryMethodAsString = $this->factory.'::__construct';
if (!$factoryMethod->isPublic()) {
throw new TransformationFailedException(sprintf('The factory method %s() is not public.', $factoryMethodAsString));
throw new TransformationFailedException(\sprintf('The factory method %s() is not public.', $factoryMethodAsString));
}
} elseif (\is_array($this->factory) && \is_callable($this->factory)) {
$class = \is_object($this->factory[0]) ? \get_class($this->factory[0]) : $this->factory[0];
$factoryMethod = (new \ReflectionMethod($class, $this->factory[1]));
$factoryMethodAsString = $class.'::'.$this->factory[1];
if (!$factoryMethod->isPublic()) {
throw new TransformationFailedException(sprintf('The factory method %s() is not public.', $factoryMethodAsString));
throw new TransformationFailedException(\sprintf('The factory method %s() is not public.', $factoryMethodAsString));
}
} elseif ($this->factory instanceof \Closure) {
$factoryMethod = new \ReflectionFunction($this->factory);
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/DependencyInjection/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public function registerContainerConfiguration(LoaderInterface $loader): void

public function getCacheDir(): string
{
return sprintf('%s/RichModelForms/%d/cache', sys_get_temp_dir(), self::VERSION_ID);
return \sprintf('%s/RichModelForms/%d/cache', sys_get_temp_dir(), self::VERSION_ID);
}

public function getLogDir(): string
{
return sprintf('%s/RichModelForms/%d/log', sys_get_temp_dir(), self::VERSION_ID);
return \sprintf('%s/RichModelForms/%d/log', sys_get_temp_dir(), self::VERSION_ID);
}
}
2 changes: 1 addition & 1 deletion tests/Fixtures/Form/ChangeProductStockType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('stock', IntegerType::class, [
'handle_exception' => $options['expected_stock_exception'],
])
->setDataMapper(new class() implements DataMapperInterface {
->setDataMapper(new class implements DataMapperInterface {
public function mapDataToForms($data, $forms): void
{
foreach ($forms as $form) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Form/GrossPriceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GrossPriceType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
if (null === $options['factory']) {
throw new InvalidConfigurationException(sprintf('The %s requires a configured value for the "factory" option.', self::class));
throw new InvalidConfigurationException(\sprintf('The %s requires a configured value for the "factory" option.', self::class));
}

$builder
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Form/PriceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PriceType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
if (null === $options['factory']) {
throw new InvalidConfigurationException(sprintf('The %s requires a configured value for the "factory" option.', self::class));
throw new InvalidConfigurationException(\sprintf('The %s requires a configured value for the "factory" option.', self::class));
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function moveTo(self $parent): void
private function validateName(string $name): void
{
if (\strlen($name) < 3) {
throw new \LengthException(sprintf('The name must have a length of at least three characters ("%s" given).', $name));
throw new \LengthException(\sprintf('The name must have a length of at least three characters ("%s" given).', $name));
}
}
}
4 changes: 2 additions & 2 deletions tests/Fixtures/Model/GrossPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ final class GrossPrice
public function __construct(int $amount, int $taxRate)
{
if ($amount < 0) {
throw new \InvalidArgumentException(sprintf('A price cannot be less than 0 (%d given).', $amount));
throw new \InvalidArgumentException(\sprintf('A price cannot be less than 0 (%d given).', $amount));
}

if (!\in_array($taxRate, [7, 19], true)) {
throw new \InvalidArgumentException(sprintf('The tax rate must be 7%% or 19%% (%d%% given).', $taxRate));
throw new \InvalidArgumentException(\sprintf('The tax rate must be 7%% or 19%% (%d%% given).', $taxRate));
}

$this->amount = $amount;
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Model/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class Price
public function __construct(int $amount)
{
if ($amount < 0) {
throw new \InvalidArgumentException(sprintf('A price cannot be less than 0 (%d given).', $amount));
throw new \InvalidArgumentException(\sprintf('A price cannot be less than 0 (%d given).', $amount));
}

$this->amount = $amount;
Expand Down

0 comments on commit 1f77828

Please sign in to comment.