From d59e37812d8066911c7ed2946e78dc9af249add5 Mon Sep 17 00:00:00 2001 From: Younes ENNAJI Date: Thu, 19 Sep 2024 06:42:10 +0100 Subject: [PATCH] chore: run php-cs-fixer --- src/Laravel/Command/InstallCommand.php | 8 +-- src/Laravel/FlasherServiceProvider.php | 2 +- src/Prime/Asset/AssetManager.php | 4 +- src/Prime/Container/FlasherContainer.php | 6 +- src/Prime/EventDispatcher/EventDispatcher.php | 2 +- .../EventListener/TranslationListener.php | 2 +- .../CriteriaNotRegisteredException.php | 4 +- .../Exception/FactoryNotFoundException.php | 4 +- .../Exception/PresenterNotFoundException.php | 4 +- .../Exception/PresetNotFoundException.php | 4 +- .../Http/Csp/ContentSecurityPolicyHandler.php | 4 +- src/Prime/Http/ResponseExtension.php | 2 +- .../NotificationBuilderMethods.php | 2 +- src/Prime/Stamp/PresenterStamp.php | 2 +- .../Filter/Criteria/FilterCriteria.php | 4 +- .../Filter/Criteria/OrderByCriteria.php | 10 +-- .../Filter/Criteria/RangeExtractor.php | 6 +- src/Prime/Storage/Filter/FilterFactory.php | 2 +- src/Prime/Support/Traits/ForwardsCalls.php | 2 +- src/Prime/Support/Traits/Macroable.php | 10 +-- src/Prime/Template/PHPTemplateEngine.php | 2 +- src/Prime/Test/Constraint/Notification.php | 10 +-- .../Test/Constraint/NotificationCount.php | 4 +- .../Test/Constraint/NotificationMessage.php | 8 +-- .../Test/Constraint/NotificationOption.php | 4 +- .../Test/Constraint/NotificationOptions.php | 2 +- .../Test/Constraint/NotificationTitle.php | 8 +-- .../Test/Constraint/NotificationType.php | 4 +- src/Symfony/Command/InstallCommand.php | 8 +-- .../Resources/dist/flasher-toastr.min.js | 70 ++++++++++++++++++- .../Resources/public/flasher-toastr.min.js | 70 ++++++++++++++++++- taskfile.dist.yml | 2 +- .../Prime/Container/FlasherContainerTest.php | 2 +- .../EventDispatcher/EventDispatcherTest.php | 2 +- tests/Prime/Http/ResponseExtensionTest.php | 2 +- .../Storage/Filter/FilterFactoryTest.php | 2 +- .../Support/Traits/ForwardsCallsTest.php | 12 ++-- tests/Prime/Support/Traits/MacroableTest.php | 10 +-- 38 files changed, 221 insertions(+), 85 deletions(-) diff --git a/src/Laravel/Command/InstallCommand.php b/src/Laravel/Command/InstallCommand.php index e573116b..f8657526 100644 --- a/src/Laravel/Command/InstallCommand.php +++ b/src/Laravel/Command/InstallCommand.php @@ -90,12 +90,12 @@ final class InstallCommand extends Command $this->publishConfig($plugin, $configFile); } - $status = sprintf('%s', '\\' === \DIRECTORY_SEPARATOR ? 'OK' : "\xE2\x9C\x94" /* HEAVY CHECK MARK (U+2714) */); - $output->writeln(sprintf(' %s %s', $status, $plugin->getAlias())); + $status = \sprintf('%s', '\\' === \DIRECTORY_SEPARATOR ? 'OK' : "\xE2\x9C\x94" /* HEAVY CHECK MARK (U+2714) */); + $output->writeln(\sprintf(' %s %s', $status, $plugin->getAlias())); } catch (\Exception $e) { $exitCode = self::FAILURE; - $status = sprintf('%s', '\\' === \DIRECTORY_SEPARATOR ? 'ERROR' : "\xE2\x9C\x98" /* HEAVY BALLOT X (U+2718) */); - $output->writeln(sprintf(' %s %s %s', $status, $plugin->getAlias(), $e->getMessage())); + $status = \sprintf('%s', '\\' === \DIRECTORY_SEPARATOR ? 'ERROR' : "\xE2\x9C\x98" /* HEAVY BALLOT X (U+2718) */); + $output->writeln(\sprintf(' %s %s %s', $status, $plugin->getAlias(), $e->getMessage())); } } diff --git a/src/Laravel/FlasherServiceProvider.php b/src/Laravel/FlasherServiceProvider.php index 80deb5da..95243e3d 100644 --- a/src/Laravel/FlasherServiceProvider.php +++ b/src/Laravel/FlasherServiceProvider.php @@ -210,7 +210,7 @@ final class FlasherServiceProvider extends PluginServiceProvider AboutCommand::add('PHPFlasher', [ 'Version' => Flasher::VERSION, - 'Factories' => implode(' / ', array_map(fn ($factory) => sprintf('%s', $factory), $factories)), + 'Factories' => implode(' / ', array_map(fn ($factory) => \sprintf('%s', $factory), $factories)), ]); } diff --git a/src/Prime/Asset/AssetManager.php b/src/Prime/Asset/AssetManager.php index ca2a4a03..3927e17d 100644 --- a/src/Prime/Asset/AssetManager.php +++ b/src/Prime/Asset/AssetManager.php @@ -44,7 +44,7 @@ final class AssetManager implements AssetManagerInterface } if (false === file_put_contents($this->manifestPath, json_encode($this->entries, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES))) { - throw new \RuntimeException(sprintf('Failed to write manifest file to "%s"', $this->manifestPath)); + throw new \RuntimeException(\sprintf('Failed to write manifest file to "%s"', $this->manifestPath)); } } @@ -67,7 +67,7 @@ final class AssetManager implements AssetManagerInterface $entries = json_decode($content ?: '', true); if (!\is_array($entries)) { - throw new \InvalidArgumentException(sprintf('There was a problem JSON decoding the "%s" file.', $this->manifestPath)); + throw new \InvalidArgumentException(\sprintf('There was a problem JSON decoding the "%s" file.', $this->manifestPath)); } return $this->entries = $entries; // @phpstan-ignore-line diff --git a/src/Prime/Container/FlasherContainer.php b/src/Prime/Container/FlasherContainer.php index 400d93a2..1ce090b9 100644 --- a/src/Prime/Container/FlasherContainer.php +++ b/src/Prime/Container/FlasherContainer.php @@ -57,13 +57,13 @@ final class FlasherContainer public static function create(string $id): FlasherInterface|NotificationFactoryInterface { if (!self::has($id)) { - throw new \InvalidArgumentException(sprintf('The container does not have the requested service "%s".', $id)); + throw new \InvalidArgumentException(\sprintf('The container does not have the requested service "%s".', $id)); } $factory = self::getContainer()->get($id); if (!$factory instanceof FlasherInterface && !$factory instanceof NotificationFactoryInterface) { - throw new \InvalidArgumentException(sprintf('Expected an instance of "%s" or "%s", got "%s".', FlasherInterface::class, NotificationFactoryInterface::class, get_debug_type($factory))); + throw new \InvalidArgumentException(\sprintf('Expected an instance of "%s" or "%s", got "%s".', FlasherInterface::class, NotificationFactoryInterface::class, get_debug_type($factory))); } return $factory; @@ -93,7 +93,7 @@ final class FlasherContainer $resolved = $container instanceof \Closure || \is_callable($container) ? $container() : $container; if (!$resolved instanceof ContainerInterface) { - throw new \InvalidArgumentException(sprintf('Expected an instance of "%s", got "%s".', ContainerInterface::class, get_debug_type($resolved))); + throw new \InvalidArgumentException(\sprintf('Expected an instance of "%s", got "%s".', ContainerInterface::class, get_debug_type($resolved))); } return $resolved; diff --git a/src/Prime/EventDispatcher/EventDispatcher.php b/src/Prime/EventDispatcher/EventDispatcher.php index 11b9da96..46d620ad 100644 --- a/src/Prime/EventDispatcher/EventDispatcher.php +++ b/src/Prime/EventDispatcher/EventDispatcher.php @@ -34,7 +34,7 @@ final class EventDispatcher implements EventDispatcherInterface } if (!\is_callable($listener)) { - throw new \InvalidArgumentException(sprintf('Listener "%s" is not callable. Listeners must implement __invoke method.', $listener::class)); + throw new \InvalidArgumentException(\sprintf('Listener "%s" is not callable. Listeners must implement __invoke method.', $listener::class)); } $listener($event); diff --git a/src/Prime/EventDispatcher/EventListener/TranslationListener.php b/src/Prime/EventDispatcher/EventListener/TranslationListener.php index 7e640413..9d166f9d 100644 --- a/src/Prime/EventDispatcher/EventListener/TranslationListener.php +++ b/src/Prime/EventDispatcher/EventListener/TranslationListener.php @@ -66,7 +66,7 @@ final readonly class TranslationListener implements EventListenerInterface foreach ($preset->getParameters() as $key => $value) { if (!\is_string($value)) { - throw new \InvalidArgumentException(sprintf('Value must be "string", got "%s".', get_debug_type($value))); + throw new \InvalidArgumentException(\sprintf('Value must be "string", got "%s".', get_debug_type($value))); } $parameters[$key] = $this->translator->translate($value, $parameters, $locale); diff --git a/src/Prime/Exception/CriteriaNotRegisteredException.php b/src/Prime/Exception/CriteriaNotRegisteredException.php index 57ada20a..ddbba3e7 100644 --- a/src/Prime/Exception/CriteriaNotRegisteredException.php +++ b/src/Prime/Exception/CriteriaNotRegisteredException.php @@ -11,10 +11,10 @@ final class CriteriaNotRegisteredException extends \Exception */ public static function create(string $alias, array $availableCriteria = []): self { - $message = sprintf('Criteria "%s" is not found, did you forget to register it?', $alias); + $message = \sprintf('Criteria "%s" is not found, did you forget to register it?', $alias); if ([] !== $availableCriteria) { - $message .= sprintf(' Available criteria: [%s]', implode(', ', $availableCriteria)); + $message .= \sprintf(' Available criteria: [%s]', implode(', ', $availableCriteria)); } return new self($message); diff --git a/src/Prime/Exception/FactoryNotFoundException.php b/src/Prime/Exception/FactoryNotFoundException.php index 950a8d98..fcf9793f 100644 --- a/src/Prime/Exception/FactoryNotFoundException.php +++ b/src/Prime/Exception/FactoryNotFoundException.php @@ -11,10 +11,10 @@ final class FactoryNotFoundException extends \Exception */ public static function create(string $alias, array $availableFactories = []): self { - $message = sprintf('Factory "%s" not found, did you forget to register it?', $alias); + $message = \sprintf('Factory "%s" not found, did you forget to register it?', $alias); if ([] !== $availableFactories) { - $message .= sprintf(' Available factories: [%s]', implode(', ', $availableFactories)); + $message .= \sprintf(' Available factories: [%s]', implode(', ', $availableFactories)); } return new self($message); diff --git a/src/Prime/Exception/PresenterNotFoundException.php b/src/Prime/Exception/PresenterNotFoundException.php index 1d101a28..0b1fbfa4 100644 --- a/src/Prime/Exception/PresenterNotFoundException.php +++ b/src/Prime/Exception/PresenterNotFoundException.php @@ -11,10 +11,10 @@ final class PresenterNotFoundException extends \Exception */ public static function create(string $alias, array $availablePresenters = []): self { - $message = sprintf('Presenter "%s" not found, did you forget to register it?', $alias); + $message = \sprintf('Presenter "%s" not found, did you forget to register it?', $alias); if ([] !== $availablePresenters) { - $message .= sprintf(' Available presenters: [%s]', implode(', ', $availablePresenters)); + $message .= \sprintf(' Available presenters: [%s]', implode(', ', $availablePresenters)); } return new self($message); diff --git a/src/Prime/Exception/PresetNotFoundException.php b/src/Prime/Exception/PresetNotFoundException.php index e48c5e25..55a6f8af 100644 --- a/src/Prime/Exception/PresetNotFoundException.php +++ b/src/Prime/Exception/PresetNotFoundException.php @@ -12,10 +12,10 @@ final class PresetNotFoundException extends \Exception */ public static function create(string $preset, array $availablePresets = []): self { - $message = sprintf('Preset "%s" not found, did you forget to register it?', $preset); + $message = \sprintf('Preset "%s" not found, did you forget to register it?', $preset); if ([] !== $availablePresets) { - $message .= sprintf(' Available presets: "%s"', implode('", "', $availablePresets)); + $message .= \sprintf(' Available presets: "%s"', implode('", "', $availablePresets)); } return new self($message); diff --git a/src/Prime/Http/Csp/ContentSecurityPolicyHandler.php b/src/Prime/Http/Csp/ContentSecurityPolicyHandler.php index 8c75a491..041255c6 100644 --- a/src/Prime/Http/Csp/ContentSecurityPolicyHandler.php +++ b/src/Prime/Http/Csp/ContentSecurityPolicyHandler.php @@ -136,7 +136,7 @@ final class ContentSecurityPolicyHandler implements ContentSecurityPolicyHandler if (!\in_array('\'unsafe-inline\'', $headers[$header][$type], true)) { $headers[$header][$type][] = '\'unsafe-inline\''; } - $headers[$header][$type][] = sprintf('\'nonce-%s\'', $nonces[$tokenName]); + $headers[$header][$type][] = \sprintf('\'nonce-%s\'', $nonces[$tokenName]); } } @@ -166,7 +166,7 @@ final class ContentSecurityPolicyHandler implements ContentSecurityPolicyHandler */ private function generateCspHeader(array $directives): string { - return array_reduce(array_keys($directives), fn ($res, $name) => ('' !== $res ? $res.'; ' : '').sprintf('%s %s', $name, implode(' ', $directives[$name])), ''); + return array_reduce(array_keys($directives), fn ($res, $name) => ('' !== $res ? $res.'; ' : '').\sprintf('%s %s', $name, implode(' ', $directives[$name])), ''); } /** diff --git a/src/Prime/Http/ResponseExtension.php b/src/Prime/Http/ResponseExtension.php index 02de15e8..89cc9492 100644 --- a/src/Prime/Http/ResponseExtension.php +++ b/src/Prime/Http/ResponseExtension.php @@ -55,7 +55,7 @@ final readonly class ResponseExtension implements ResponseExtensionInterface } if ($alreadyRendered) { - $htmlResponse = sprintf('options.push(%s);', $htmlResponse); + $htmlResponse = \sprintf('options.push(%s);', $htmlResponse); } // $htmlResponse = "\n".str_replace("\n", '', (string) $htmlResponse)."\n"; diff --git a/src/Prime/Notification/NotificationBuilderMethods.php b/src/Prime/Notification/NotificationBuilderMethods.php index cfa7522e..a0c37733 100644 --- a/src/Prime/Notification/NotificationBuilderMethods.php +++ b/src/Prime/Notification/NotificationBuilderMethods.php @@ -160,7 +160,7 @@ trait NotificationBuilderMethods if (!\is_bool($condition)) { $type = \gettype($condition); - throw new \InvalidArgumentException(sprintf('The condition must be a boolean or a closure that returns a boolean. Got: %s', $type)); + throw new \InvalidArgumentException(\sprintf('The condition must be a boolean or a closure that returns a boolean. Got: %s', $type)); } return $condition; diff --git a/src/Prime/Stamp/PresenterStamp.php b/src/Prime/Stamp/PresenterStamp.php index 2a4dd2a1..3ed9da94 100644 --- a/src/Prime/Stamp/PresenterStamp.php +++ b/src/Prime/Stamp/PresenterStamp.php @@ -9,7 +9,7 @@ final readonly class PresenterStamp implements StampInterface public function __construct(private string $pattern) { if (false === @preg_match($pattern, '')) { - throw new \InvalidArgumentException(sprintf("The provided regex pattern '%s' is invalid for the presenter stamp. Please ensure it is a valid regex expression.", $pattern)); + throw new \InvalidArgumentException(\sprintf("The provided regex pattern '%s' is invalid for the presenter stamp. Please ensure it is a valid regex expression.", $pattern)); } } diff --git a/src/Prime/Storage/Filter/Criteria/FilterCriteria.php b/src/Prime/Storage/Filter/Criteria/FilterCriteria.php index 9b1babb4..d22caa22 100644 --- a/src/Prime/Storage/Filter/Criteria/FilterCriteria.php +++ b/src/Prime/Storage/Filter/Criteria/FilterCriteria.php @@ -17,13 +17,13 @@ final class FilterCriteria implements CriteriaInterface public function __construct(mixed $criteria) { if (!$criteria instanceof \Closure && !\is_array($criteria)) { - throw new \InvalidArgumentException(sprintf('Invalid type for criteria "filter". Expect a closure or array of closure, got "%s".', get_debug_type($criteria))); + throw new \InvalidArgumentException(\sprintf('Invalid type for criteria "filter". Expect a closure or array of closure, got "%s".', get_debug_type($criteria))); } $criteria = $criteria instanceof \Closure ? [$criteria] : $criteria; foreach ($criteria as $callback) { if (!$callback instanceof \Closure) { - throw new \InvalidArgumentException(sprintf('Each element must be a closure, got got "%s".', get_debug_type($callback))); + throw new \InvalidArgumentException(\sprintf('Each element must be a closure, got got "%s".', get_debug_type($callback))); } $this->callbacks[] = $callback; diff --git a/src/Prime/Storage/Filter/Criteria/OrderByCriteria.php b/src/Prime/Storage/Filter/Criteria/OrderByCriteria.php index a9b1624d..2ac3af4b 100644 --- a/src/Prime/Storage/Filter/Criteria/OrderByCriteria.php +++ b/src/Prime/Storage/Filter/Criteria/OrderByCriteria.php @@ -49,7 +49,7 @@ final class OrderByCriteria implements CriteriaInterface public function __construct(mixed $criteria) { if (!\is_string($criteria) && !\is_array($criteria)) { - throw new \InvalidArgumentException(sprintf('Invalid type for criteria "order_by". Expect a "string" or an "array", got "%s".', get_debug_type($criteria))); + throw new \InvalidArgumentException(\sprintf('Invalid type for criteria "order_by". Expect a "string" or an "array", got "%s".', get_debug_type($criteria))); } foreach ((array) $criteria as $field => $direction) { @@ -59,22 +59,22 @@ final class OrderByCriteria implements CriteriaInterface } if (!\is_string($field)) { - throw new \InvalidArgumentException(sprintf('Invalid Field value, must be "string", got "%s".', get_debug_type($field))); + throw new \InvalidArgumentException(\sprintf('Invalid Field value, must be "string", got "%s".', get_debug_type($field))); } if (!\is_string($direction)) { - throw new \InvalidArgumentException(sprintf('Invalid Direction value, must be "string", got "%s".', get_debug_type($direction))); + throw new \InvalidArgumentException(\sprintf('Invalid Direction value, must be "string", got "%s".', get_debug_type($direction))); } $direction = strtoupper($direction); if (!\in_array($direction, [self::ASC, self::DESC], true)) { - throw new \InvalidArgumentException(sprintf('Invalid ordering direction: must be "ASC" or "DESC", got "%s".', $direction)); + throw new \InvalidArgumentException(\sprintf('Invalid ordering direction: must be "ASC" or "DESC", got "%s".', $direction)); } $field = $this->aliases[$field] ?? $field; if (!is_a($field, StampInterface::class, true)) { - throw new \InvalidArgumentException(sprintf('Field "%s" is not a valid class-string of "%s".', $field, StampInterface::class)); + throw new \InvalidArgumentException(\sprintf('Field "%s" is not a valid class-string of "%s".', $field, StampInterface::class)); } $this->orderings[$field] = $direction; diff --git a/src/Prime/Storage/Filter/Criteria/RangeExtractor.php b/src/Prime/Storage/Filter/Criteria/RangeExtractor.php index 7c1ed9f4..1b390001 100644 --- a/src/Prime/Storage/Filter/Criteria/RangeExtractor.php +++ b/src/Prime/Storage/Filter/Criteria/RangeExtractor.php @@ -19,7 +19,7 @@ trait RangeExtractor private function extractRange(string $name, mixed $criteria): array { if (!\is_int($criteria) && !\is_array($criteria)) { - throw new \InvalidArgumentException(sprintf('Invalid type for criteria "%s". Expected int or array, got "%s".', $name, get_debug_type($criteria))); + throw new \InvalidArgumentException(\sprintf('Invalid type for criteria "%s". Expected int or array, got "%s".', $name, get_debug_type($criteria))); } if (\is_int($criteria)) { @@ -30,11 +30,11 @@ trait RangeExtractor $max = $criteria['max'] ?? null; if (null !== $min && !\is_int($min)) { - throw new \InvalidArgumentException(sprintf('Invalid type for "min" in criteria "%s". Expected int, got "%s".', $name, get_debug_type($min))); + throw new \InvalidArgumentException(\sprintf('Invalid type for "min" in criteria "%s". Expected int, got "%s".', $name, get_debug_type($min))); } if (null !== $max && !\is_int($max)) { - throw new \InvalidArgumentException(sprintf('Invalid type for "max" in criteria "%s". Expected int, got "%s".', $name, get_debug_type($max))); + throw new \InvalidArgumentException(\sprintf('Invalid type for "max" in criteria "%s". Expected int, got "%s".', $name, get_debug_type($max))); } return ['min' => $min, 'max' => $max]; diff --git a/src/Prime/Storage/Filter/FilterFactory.php b/src/Prime/Storage/Filter/FilterFactory.php index b64e2ae8..83f9ddc0 100644 --- a/src/Prime/Storage/Filter/FilterFactory.php +++ b/src/Prime/Storage/Filter/FilterFactory.php @@ -71,7 +71,7 @@ final class FilterFactory implements FilterFactoryInterface $criteria = \is_callable($criteria) ? $criteria($value) : $criteria; if (!$criteria instanceof CriteriaInterface) { - throw new \UnexpectedValueException(sprintf('Expected an instance of "%s", got "%s" instead.', CriteriaInterface::class, get_debug_type($criteria))); + throw new \UnexpectedValueException(\sprintf('Expected an instance of "%s", got "%s" instead.', CriteriaInterface::class, get_debug_type($criteria))); } return $criteria; diff --git a/src/Prime/Support/Traits/ForwardsCalls.php b/src/Prime/Support/Traits/ForwardsCalls.php index cba5d435..f96114d2 100644 --- a/src/Prime/Support/Traits/ForwardsCalls.php +++ b/src/Prime/Support/Traits/ForwardsCalls.php @@ -70,6 +70,6 @@ trait ForwardsCalls */ protected static function throwBadMethodCallException(string $method): never { - throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', static::class, $method)); + throw new \BadMethodCallException(\sprintf('Call to undefined method %s::%s()', static::class, $method)); } } diff --git a/src/Prime/Support/Traits/Macroable.php b/src/Prime/Support/Traits/Macroable.php index 5c7ce868..02c57101 100644 --- a/src/Prime/Support/Traits/Macroable.php +++ b/src/Prime/Support/Traits/Macroable.php @@ -56,7 +56,7 @@ trait Macroable $macro = $method->invoke($mixin); if (!\is_callable($macro) && !\is_object($macro)) { - throw new \InvalidArgumentException(sprintf('Expect the result of method %s::%s from the mixin object to be be a callable or an object, got "%s".', $mixin::class, $method->name, get_debug_type($macro))); + throw new \InvalidArgumentException(\sprintf('Expect the result of method %s::%s from the mixin object to be be a callable or an object, got "%s".', $mixin::class, $method->name, get_debug_type($macro))); } if ($replace || !static::hasMacro($method->name)) { @@ -83,7 +83,7 @@ trait Macroable public static function __callStatic(string $method, array $parameters): mixed { if (!static::hasMacro($method)) { - throw new \BadMethodCallException(sprintf('Method %s::%s does not exist.', static::class, $method)); + throw new \BadMethodCallException(\sprintf('Method %s::%s does not exist.', static::class, $method)); } $macro = static::$macros[$method]; @@ -93,7 +93,7 @@ trait Macroable } if (!\is_callable($macro)) { - throw new \BadMethodCallException(sprintf('Macro %s is not callable.', $method)); + throw new \BadMethodCallException(\sprintf('Macro %s is not callable.', $method)); } return $macro(...$parameters); @@ -109,7 +109,7 @@ trait Macroable public function __call(string $method, array $parameters): mixed { if (!static::hasMacro($method)) { - throw new \BadMethodCallException(sprintf('Method %s::%s does not exist.', static::class, $method)); + throw new \BadMethodCallException(\sprintf('Method %s::%s does not exist.', static::class, $method)); } $macro = static::$macros[$method]; @@ -119,7 +119,7 @@ trait Macroable } if (!\is_callable($macro)) { - throw new \BadMethodCallException(sprintf('Macro %s is not callable.', $method)); + throw new \BadMethodCallException(\sprintf('Macro %s is not callable.', $method)); } return $macro(...$parameters); diff --git a/src/Prime/Template/PHPTemplateEngine.php b/src/Prime/Template/PHPTemplateEngine.php index 9a667608..46e9b85b 100644 --- a/src/Prime/Template/PHPTemplateEngine.php +++ b/src/Prime/Template/PHPTemplateEngine.php @@ -9,7 +9,7 @@ final class PHPTemplateEngine implements TemplateEngineInterface public function render(string $name, array $context = []): string { if (!file_exists($name) || !is_readable($name)) { - throw new \InvalidArgumentException(sprintf('Template file "%s" does not exist or is not readable.', $name)); + throw new \InvalidArgumentException(\sprintf('Template file "%s" does not exist or is not readable.', $name)); } ob_start(); diff --git a/src/Prime/Test/Constraint/Notification.php b/src/Prime/Test/Constraint/Notification.php index d28ed6c2..429754c5 100644 --- a/src/Prime/Test/Constraint/Notification.php +++ b/src/Prime/Test/Constraint/Notification.php @@ -32,15 +32,15 @@ final class Notification extends Constraint public function toString(): string { $details = [ - sprintf('type: "%s"', $this->expectedType), + \sprintf('type: "%s"', $this->expectedType), ]; if (null !== $this->expectedMessage) { - $details[] = sprintf('message: "%s"', $this->expectedMessage); + $details[] = \sprintf('message: "%s"', $this->expectedMessage); } if (null !== $this->expectedTitle) { - $details[] = sprintf('title: "%s"', $this->expectedTitle); + $details[] = \sprintf('title: "%s"', $this->expectedTitle); } if (!empty($this->expectedOptions)) { @@ -82,7 +82,7 @@ final class Notification extends Constraint protected function failureDescription(mixed $other): string { $foundNotifications = array_map(function (NotificationInterface $notification) { - return sprintf( + return \sprintf( 'type: "%s", title: "%s", message: "%s", options: [%s]', $notification->getType(), $notification->getTitle(), @@ -95,7 +95,7 @@ final class Notification extends Constraint $foundNotifications[] = 'No notifications found'; } - return sprintf( + return \sprintf( 'Failed asserting that NotificationEvents %s. Found: [%s].', $this->toString(), implode('; ', $foundNotifications) diff --git a/src/Prime/Test/Constraint/NotificationCount.php b/src/Prime/Test/Constraint/NotificationCount.php index 81a61d2d..d92f2442 100644 --- a/src/Prime/Test/Constraint/NotificationCount.php +++ b/src/Prime/Test/Constraint/NotificationCount.php @@ -15,7 +15,7 @@ final class NotificationCount extends Constraint public function toString(): string { - return sprintf('matches the expected notification count of %d.', $this->expectedValue); + return \sprintf('matches the expected notification count of %d.', $this->expectedValue); } /** @@ -45,7 +45,7 @@ final class NotificationCount extends Constraint { $actualCount = $this->countNotifications($other); - return sprintf('Expected the notification count to be %d, but got %d instead.', $this->expectedValue, $actualCount); + return \sprintf('Expected the notification count to be %d, but got %d instead.', $this->expectedValue, $actualCount); } /** diff --git a/src/Prime/Test/Constraint/NotificationMessage.php b/src/Prime/Test/Constraint/NotificationMessage.php index 1b3e39b7..a18cbd84 100644 --- a/src/Prime/Test/Constraint/NotificationMessage.php +++ b/src/Prime/Test/Constraint/NotificationMessage.php @@ -19,7 +19,7 @@ final class NotificationMessage extends Constraint public function toString(): string { - return sprintf('contains a notification with message "%s"', $this->expectedMessage); + return \sprintf('contains a notification with message "%s"', $this->expectedMessage); } protected function matches(mixed $other): bool @@ -44,17 +44,17 @@ final class NotificationMessage extends Constraint } $foundMessages = array_map(function (NotificationInterface $notification) { - return sprintf('"%s"', $notification->getMessage()); + return \sprintf('"%s"', $notification->getMessage()); }, $other->getNotifications()); if (empty($foundMessages)) { - return sprintf( + return \sprintf( 'Expected to find a notification with a message containing "%s", but no notifications were found.', $this->expectedMessage ); } - return sprintf( + return \sprintf( 'Expected to find a notification with a message containing "%s". Found messages: %s.', $this->expectedMessage, implode(', ', $foundMessages) diff --git a/src/Prime/Test/Constraint/NotificationOption.php b/src/Prime/Test/Constraint/NotificationOption.php index f7140532..0f2eaa4a 100644 --- a/src/Prime/Test/Constraint/NotificationOption.php +++ b/src/Prime/Test/Constraint/NotificationOption.php @@ -23,10 +23,10 @@ final class NotificationOption extends Constraint public function toString(): string { - $description = sprintf('contains a notification with an option "%s"', $this->expectedKey); + $description = \sprintf('contains a notification with an option "%s"', $this->expectedKey); if ($this->expectedValue) { - $description .= sprintf(' having the value "%s"', json_encode($this->expectedValue)); + $description .= \sprintf(' having the value "%s"', json_encode($this->expectedValue)); } return $description; diff --git a/src/Prime/Test/Constraint/NotificationOptions.php b/src/Prime/Test/Constraint/NotificationOptions.php index 077f9972..93b492fd 100644 --- a/src/Prime/Test/Constraint/NotificationOptions.php +++ b/src/Prime/Test/Constraint/NotificationOptions.php @@ -50,7 +50,7 @@ final class NotificationOptions extends Constraint $actualOptionsString = implode('; ', $actualOptions) ?: 'none found'; - return sprintf( + return \sprintf( 'Failed asserting that NotificationEvents %s. Actual options in notifications: [%s].', $this->toString(), $actualOptionsString diff --git a/src/Prime/Test/Constraint/NotificationTitle.php b/src/Prime/Test/Constraint/NotificationTitle.php index d977d58b..f3fb9acd 100644 --- a/src/Prime/Test/Constraint/NotificationTitle.php +++ b/src/Prime/Test/Constraint/NotificationTitle.php @@ -22,7 +22,7 @@ final class NotificationTitle extends Constraint public function toString(): string { - return sprintf('contains a notification with a title containing "%s"', $this->expectedTitle); + return \sprintf('contains a notification with a title containing "%s"', $this->expectedTitle); } protected function matches(mixed $other): bool @@ -47,17 +47,17 @@ final class NotificationTitle extends Constraint } $foundTitles = array_map(function (NotificationInterface $notification) { - return sprintf('"%s"', $notification->getTitle()); + return \sprintf('"%s"', $notification->getTitle()); }, $other->getNotifications()); if (empty($foundTitles)) { - return sprintf( + return \sprintf( 'Expected to find a notification with a title containing "%s", but no notifications were found.', $this->expectedTitle ); } - return sprintf( + return \sprintf( 'Expected to find a notification with a title containing "%s". Found titles: %s.', $this->expectedTitle, implode(', ', $foundTitles) diff --git a/src/Prime/Test/Constraint/NotificationType.php b/src/Prime/Test/Constraint/NotificationType.php index 3ef538e7..c0ebe8e9 100644 --- a/src/Prime/Test/Constraint/NotificationType.php +++ b/src/Prime/Test/Constraint/NotificationType.php @@ -23,7 +23,7 @@ final class NotificationType extends Constraint public function toString(): string { - return sprintf('contains a notification of type "%s".', $this->expectedType); + return \sprintf('contains a notification of type "%s".', $this->expectedType); } /** @@ -65,7 +65,7 @@ final class NotificationType extends Constraint $uniqueTypes = array_unique($actualTypes); $typesList = implode(', ', $uniqueTypes); - return sprintf( + return \sprintf( 'Expected the NotificationEvents to contain a notification of type "%s", but found types: %s.', $this->expectedType, $typesList ?: 'none' diff --git a/src/Symfony/Command/InstallCommand.php b/src/Symfony/Command/InstallCommand.php index e3e9c006..27a29e25 100644 --- a/src/Symfony/Command/InstallCommand.php +++ b/src/Symfony/Command/InstallCommand.php @@ -93,12 +93,12 @@ final class InstallCommand extends Command $this->publishConfig($plugin, $configDir, $configFile); } - $status = sprintf('%s', '\\' === \DIRECTORY_SEPARATOR ? 'OK' : "\xE2\x9C\x94" /* HEAVY CHECK MARK (U+2714) */); - $output->writeln(sprintf(' %s %s', $status, $plugin->getAlias())); + $status = \sprintf('%s', '\\' === \DIRECTORY_SEPARATOR ? 'OK' : "\xE2\x9C\x94" /* HEAVY CHECK MARK (U+2714) */); + $output->writeln(\sprintf(' %s %s', $status, $plugin->getAlias())); } catch (\Exception $e) { $exitCode = self::FAILURE; - $status = sprintf('%s', '\\' === \DIRECTORY_SEPARATOR ? 'ERROR' : "\xE2\x9C\x98" /* HEAVY BALLOT X (U+2718) */); - $output->writeln(sprintf(' %s %s %s', $status, $plugin->getAlias(), $e->getMessage())); + $status = \sprintf('%s', '\\' === \DIRECTORY_SEPARATOR ? 'ERROR' : "\xE2\x9C\x98" /* HEAVY BALLOT X (U+2718) */); + $output->writeln(\sprintf(' %s %s %s', $status, $plugin->getAlias(), $e->getMessage())); } } diff --git a/src/Toastr/Prime/Resources/dist/flasher-toastr.min.js b/src/Toastr/Prime/Resources/dist/flasher-toastr.min.js index 06f5c9ba..72f36bbf 100644 --- a/src/Toastr/Prime/Resources/dist/flasher-toastr.min.js +++ b/src/Toastr/Prime/Resources/dist/flasher-toastr.min.js @@ -1 +1,69 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@flasher/flasher"),require("toastr")):"function"==typeof define&&define.amd?define(["@flasher/flasher","toastr"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).toastr=t(e.flasher,e.toastr)}(this,(function(e,t){"use strict";class s{success(e,t,s){this.flash("success",e,t,s)}error(e,t,s){this.flash("error",e,t,s)}info(e,t,s){this.flash("info",e,t,s)}warning(e,t,s){this.flash("warning",e,t,s)}flash(e,t,s,r){if("object"==typeof e?(e=(r=e).type,t=r.message,s=r.title):"object"==typeof t?(t=(r=t).message,s=r.title):"object"==typeof s&&(s=(r=s).title),void 0===t)throw new Error("message option is required");const o={type:e,message:t,title:s||e,options:r||{},metadata:{plugin:""}};this.renderOptions(r||{}),this.renderEnvelopes([o])}}const r=new class extends s{renderEnvelopes(e){e.forEach((e=>{const{message:s,title:r,type:o,options:i}=e,n=t[o](s,r,i);n&&n.parent().attr("data-turbo-temporary","")}))}renderOptions(e){t.options=Object.assign({timeOut:e.timeOut||5e3,progressBar:e.progressBar||!0},e)}};return e.addPlugin("toastr",r),r})); +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@flasher/flasher'), require('toastr')) : + typeof define === 'function' && define.amd ? define(['@flasher/flasher', 'toastr'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.toastr = factory(global.flasher, global.toastr)); +})(this, (function (flasher, toastr$1) { 'use strict'; + + class AbstractPlugin { + success(message, title, options) { + this.flash('success', message, title, options); + } + error(message, title, options) { + this.flash('error', message, title, options); + } + info(message, title, options) { + this.flash('info', message, title, options); + } + warning(message, title, options) { + this.flash('warning', message, title, options); + } + flash(type, message, title, options) { + if (typeof type === 'object') { + options = type; + type = options.type; + message = options.message; + title = options.title; + } else if (typeof message === 'object') { + options = message; + message = options.message; + title = options.title; + } else if (typeof title === 'object') { + options = title; + title = options.title; + } + if (undefined === message) { + throw new Error('message option is required'); + } + const envelope = { + type, + message, + title: title || type, + options: options || {}, + metadata: { + plugin: '' + } + }; + this.renderOptions(options || {}); + this.renderEnvelopes([envelope]); + } + } + + class ToastrPlugin extends AbstractPlugin { + renderEnvelopes(envelopes) { + envelopes.forEach((envelope) => { + const { message, title, type, options } = envelope; + const instance = toastr$1[type](message, title, options); + instance && instance.parent().attr('data-turbo-temporary', ''); + }); + } + renderOptions(options) { + toastr$1.options = Object.assign({ timeOut: (options.timeOut || 5000), progressBar: (options.progressBar || true) }, options); + } + } + + const toastr = new ToastrPlugin(); + flasher.addPlugin('toastr', toastr); + + return toastr; + +})); diff --git a/src/Toastr/Prime/Resources/public/flasher-toastr.min.js b/src/Toastr/Prime/Resources/public/flasher-toastr.min.js index 06f5c9ba..72f36bbf 100644 --- a/src/Toastr/Prime/Resources/public/flasher-toastr.min.js +++ b/src/Toastr/Prime/Resources/public/flasher-toastr.min.js @@ -1 +1,69 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@flasher/flasher"),require("toastr")):"function"==typeof define&&define.amd?define(["@flasher/flasher","toastr"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).toastr=t(e.flasher,e.toastr)}(this,(function(e,t){"use strict";class s{success(e,t,s){this.flash("success",e,t,s)}error(e,t,s){this.flash("error",e,t,s)}info(e,t,s){this.flash("info",e,t,s)}warning(e,t,s){this.flash("warning",e,t,s)}flash(e,t,s,r){if("object"==typeof e?(e=(r=e).type,t=r.message,s=r.title):"object"==typeof t?(t=(r=t).message,s=r.title):"object"==typeof s&&(s=(r=s).title),void 0===t)throw new Error("message option is required");const o={type:e,message:t,title:s||e,options:r||{},metadata:{plugin:""}};this.renderOptions(r||{}),this.renderEnvelopes([o])}}const r=new class extends s{renderEnvelopes(e){e.forEach((e=>{const{message:s,title:r,type:o,options:i}=e,n=t[o](s,r,i);n&&n.parent().attr("data-turbo-temporary","")}))}renderOptions(e){t.options=Object.assign({timeOut:e.timeOut||5e3,progressBar:e.progressBar||!0},e)}};return e.addPlugin("toastr",r),r})); +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@flasher/flasher'), require('toastr')) : + typeof define === 'function' && define.amd ? define(['@flasher/flasher', 'toastr'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.toastr = factory(global.flasher, global.toastr)); +})(this, (function (flasher, toastr$1) { 'use strict'; + + class AbstractPlugin { + success(message, title, options) { + this.flash('success', message, title, options); + } + error(message, title, options) { + this.flash('error', message, title, options); + } + info(message, title, options) { + this.flash('info', message, title, options); + } + warning(message, title, options) { + this.flash('warning', message, title, options); + } + flash(type, message, title, options) { + if (typeof type === 'object') { + options = type; + type = options.type; + message = options.message; + title = options.title; + } else if (typeof message === 'object') { + options = message; + message = options.message; + title = options.title; + } else if (typeof title === 'object') { + options = title; + title = options.title; + } + if (undefined === message) { + throw new Error('message option is required'); + } + const envelope = { + type, + message, + title: title || type, + options: options || {}, + metadata: { + plugin: '' + } + }; + this.renderOptions(options || {}); + this.renderEnvelopes([envelope]); + } + } + + class ToastrPlugin extends AbstractPlugin { + renderEnvelopes(envelopes) { + envelopes.forEach((envelope) => { + const { message, title, type, options } = envelope; + const instance = toastr$1[type](message, title, options); + instance && instance.parent().attr('data-turbo-temporary', ''); + }); + } + renderOptions(options) { + toastr$1.options = Object.assign({ timeOut: (options.timeOut || 5000), progressBar: (options.progressBar || true) }, options); + } + } + + const toastr = new ToastrPlugin(); + flasher.addPlugin('toastr', toastr); + + return toastr; + +})); diff --git a/taskfile.dist.yml b/taskfile.dist.yml index 405e3369..e1ab42eb 100644 --- a/taskfile.dist.yml +++ b/taskfile.dist.yml @@ -30,7 +30,7 @@ tasks: desc: "🔍 Run various linting tools to ensure code quality." cmds: - vendor/bin/php-cs-fixer fix --dry-run - - vendor/bin/phpstan analyse + - vendor/bin/phpstan analyse --memory-limit=-1 - composer validate --strict - vendor/bin/phplint - find src/ -name "composer.json" -exec composer validate --strict {} \; diff --git a/tests/Prime/Container/FlasherContainerTest.php b/tests/Prime/Container/FlasherContainerTest.php index 765cd45f..123487ca 100644 --- a/tests/Prime/Container/FlasherContainerTest.php +++ b/tests/Prime/Container/FlasherContainerTest.php @@ -55,7 +55,7 @@ final class FlasherContainerTest extends TestCase $container->method('get')->willReturn($invalidService); $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage(sprintf('Expected an instance of "%s" or "%s", got "%s".', FlasherInterface::class, NotificationFactoryInterface::class, get_debug_type($invalidService))); + $this->expectExceptionMessage(\sprintf('Expected an instance of "%s" or "%s", got "%s".', FlasherInterface::class, NotificationFactoryInterface::class, get_debug_type($invalidService))); FlasherContainer::from($container); FlasherContainer::create('invalid_service'); diff --git a/tests/Prime/EventDispatcher/EventDispatcherTest.php b/tests/Prime/EventDispatcher/EventDispatcherTest.php index 05a3ab6d..26b84286 100644 --- a/tests/Prime/EventDispatcher/EventDispatcherTest.php +++ b/tests/Prime/EventDispatcher/EventDispatcherTest.php @@ -68,7 +68,7 @@ final class EventDispatcherTest extends TestCase public function testDispatchWithNonCallableListener(): void { - $event = new class() {}; + $event = new class {}; $eventName = $event::class; $listener = new NonCallableListener($eventName); diff --git a/tests/Prime/Http/ResponseExtensionTest.php b/tests/Prime/Http/ResponseExtensionTest.php index 546afdfd..75e908f8 100644 --- a/tests/Prime/Http/ResponseExtensionTest.php +++ b/tests/Prime/Http/ResponseExtensionTest.php @@ -149,7 +149,7 @@ final class ResponseExtensionTest extends TestCase $responseExtension = new ResponseExtension($flasher, $cspHandler); $responseExtension->render($request, $response); - $htmlInjection = HtmlPresenter::FLASHER_REPLACE_ME === $placeholder ? sprintf('options.push(%s);', $htmlResponse) : $htmlResponse; + $htmlInjection = HtmlPresenter::FLASHER_REPLACE_ME === $placeholder ? \sprintf('options.push(%s);', $htmlResponse) : $htmlResponse; $expectedContent = str_replace($placeholder, "{$htmlInjection}\n{$placeholder}", $contentBefore); $response->shouldHaveReceived('setContent')->with($expectedContent)->once(); diff --git a/tests/Prime/Storage/Filter/FilterFactoryTest.php b/tests/Prime/Storage/Filter/FilterFactoryTest.php index 32bdd54e..e9715c64 100644 --- a/tests/Prime/Storage/Filter/FilterFactoryTest.php +++ b/tests/Prime/Storage/Filter/FilterFactoryTest.php @@ -70,7 +70,7 @@ final class FilterFactoryTest extends TestCase $reflect = new \ReflectionClass(FilterFactory::class); $reflectValue = $reflect->getProperty('criteria'); - $this->filterFactory->addCriteria('custom_criteria', fn () => new class() implements CriteriaInterface { + $this->filterFactory->addCriteria('custom_criteria', fn () => new class implements CriteriaInterface { public function apply(array $envelopes): array { return $envelopes; diff --git a/tests/Prime/Support/Traits/ForwardsCallsTest.php b/tests/Prime/Support/Traits/ForwardsCallsTest.php index 2c01b2dd..7c13a3c2 100644 --- a/tests/Prime/Support/Traits/ForwardsCallsTest.php +++ b/tests/Prime/Support/Traits/ForwardsCallsTest.php @@ -11,11 +11,11 @@ final class ForwardsCallsTest extends TestCase { public function testSuccessfulMethodForwarding(): void { - $testable = new class() { + $testable = new class { use ForwardsCalls; }; - $secondary = new class() { + $secondary = new class { public function someMethod(): string { return 'method result'; @@ -31,11 +31,11 @@ final class ForwardsCallsTest extends TestCase public function testForwardingAndReturningThis(): void { - $testable = new class() { + $testable = new class { use ForwardsCalls; }; - $secondary = new class() { + $secondary = new class { public function selfReturningMethod(): self { return $this; @@ -52,11 +52,11 @@ final class ForwardsCallsTest extends TestCase public function testUndefinedMethodCall(): void { - $testable = new class() { + $testable = new class { use ForwardsCalls; }; - $secondary = new class() { + $secondary = new class { // This class intentionally left blank to simulate an undefined method call. }; diff --git a/tests/Prime/Support/Traits/MacroableTest.php b/tests/Prime/Support/Traits/MacroableTest.php index cd3fb478..22c4058e 100644 --- a/tests/Prime/Support/Traits/MacroableTest.php +++ b/tests/Prime/Support/Traits/MacroableTest.php @@ -11,7 +11,7 @@ final class MacroableTest extends TestCase { public function testMacroRegistrationAndExecution(): void { - $macroableClass = new class() { + $macroableClass = new class { use Macroable; }; @@ -25,11 +25,11 @@ final class MacroableTest extends TestCase public function testMixin(): void { - $macroableClass = new class() { + $macroableClass = new class { use Macroable; }; - $mixin = new class() { + $mixin = new class { public function mixedInMethod(): callable { return static function () { @@ -46,7 +46,7 @@ final class MacroableTest extends TestCase public function testExceptionForNonExistingMacro(): void { - $macroableClass = new class() { + $macroableClass = new class { use Macroable; }; @@ -56,7 +56,7 @@ final class MacroableTest extends TestCase public function testExceptionForNonCallableMacro(): void { - $macroableClass = new class() { + $macroableClass = new class { use Macroable; };