chore: run php-cs-fixer

This commit is contained in:
Younes ENNAJI
2024-09-19 06:42:10 +01:00
parent 51dd7dc6fb
commit d59e37812d
38 changed files with 221 additions and 85 deletions
+4 -4
View File
@@ -90,12 +90,12 @@ final class InstallCommand extends Command
$this->publishConfig($plugin, $configFile); $this->publishConfig($plugin, $configFile);
} }
$status = sprintf('<fg=green;options=bold>%s</>', '\\' === \DIRECTORY_SEPARATOR ? 'OK' : "\xE2\x9C\x94" /* HEAVY CHECK MARK (U+2714) */); $status = \sprintf('<fg=green;options=bold>%s</>', '\\' === \DIRECTORY_SEPARATOR ? 'OK' : "\xE2\x9C\x94" /* HEAVY CHECK MARK (U+2714) */);
$output->writeln(sprintf(' %s <fg=blue;options=bold>%s</>', $status, $plugin->getAlias())); $output->writeln(\sprintf(' %s <fg=blue;options=bold>%s</>', $status, $plugin->getAlias()));
} catch (\Exception $e) { } catch (\Exception $e) {
$exitCode = self::FAILURE; $exitCode = self::FAILURE;
$status = sprintf('<fg=red;options=bold>%s</>', '\\' === \DIRECTORY_SEPARATOR ? 'ERROR' : "\xE2\x9C\x98" /* HEAVY BALLOT X (U+2718) */); $status = \sprintf('<fg=red;options=bold>%s</>', '\\' === \DIRECTORY_SEPARATOR ? 'ERROR' : "\xE2\x9C\x98" /* HEAVY BALLOT X (U+2718) */);
$output->writeln(sprintf(' %s <fg=blue;options=bold>%s</> <error>%s</error>', $status, $plugin->getAlias(), $e->getMessage())); $output->writeln(\sprintf(' %s <fg=blue;options=bold>%s</> <error>%s</error>', $status, $plugin->getAlias(), $e->getMessage()));
} }
} }
+1 -1
View File
@@ -210,7 +210,7 @@ final class FlasherServiceProvider extends PluginServiceProvider
AboutCommand::add('PHPFlasher', [ AboutCommand::add('PHPFlasher', [
'Version' => Flasher::VERSION, 'Version' => Flasher::VERSION,
'Factories' => implode(' <fg=gray;options=bold>/</> ', array_map(fn ($factory) => sprintf('<fg=yellow;options=bold>%s</>', $factory), $factories)), 'Factories' => implode(' <fg=gray;options=bold>/</> ', array_map(fn ($factory) => \sprintf('<fg=yellow;options=bold>%s</>', $factory), $factories)),
]); ]);
} }
+2 -2
View File
@@ -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))) { 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); $entries = json_decode($content ?: '', true);
if (!\is_array($entries)) { 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 return $this->entries = $entries; // @phpstan-ignore-line
+3 -3
View File
@@ -57,13 +57,13 @@ final class FlasherContainer
public static function create(string $id): FlasherInterface|NotificationFactoryInterface public static function create(string $id): FlasherInterface|NotificationFactoryInterface
{ {
if (!self::has($id)) { 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); $factory = self::getContainer()->get($id);
if (!$factory instanceof FlasherInterface && !$factory instanceof NotificationFactoryInterface) { 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; return $factory;
@@ -93,7 +93,7 @@ final class FlasherContainer
$resolved = $container instanceof \Closure || \is_callable($container) ? $container() : $container; $resolved = $container instanceof \Closure || \is_callable($container) ? $container() : $container;
if (!$resolved instanceof ContainerInterface) { 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; return $resolved;
@@ -34,7 +34,7 @@ final class EventDispatcher implements EventDispatcherInterface
} }
if (!\is_callable($listener)) { 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); $listener($event);
@@ -66,7 +66,7 @@ final readonly class TranslationListener implements EventListenerInterface
foreach ($preset->getParameters() as $key => $value) { foreach ($preset->getParameters() as $key => $value) {
if (!\is_string($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); $parameters[$key] = $this->translator->translate($value, $parameters, $locale);
@@ -11,10 +11,10 @@ final class CriteriaNotRegisteredException extends \Exception
*/ */
public static function create(string $alias, array $availableCriteria = []): self 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) { if ([] !== $availableCriteria) {
$message .= sprintf(' Available criteria: [%s]', implode(', ', $availableCriteria)); $message .= \sprintf(' Available criteria: [%s]', implode(', ', $availableCriteria));
} }
return new self($message); return new self($message);
@@ -11,10 +11,10 @@ final class FactoryNotFoundException extends \Exception
*/ */
public static function create(string $alias, array $availableFactories = []): self 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) { if ([] !== $availableFactories) {
$message .= sprintf(' Available factories: [%s]', implode(', ', $availableFactories)); $message .= \sprintf(' Available factories: [%s]', implode(', ', $availableFactories));
} }
return new self($message); return new self($message);
@@ -11,10 +11,10 @@ final class PresenterNotFoundException extends \Exception
*/ */
public static function create(string $alias, array $availablePresenters = []): self 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) { if ([] !== $availablePresenters) {
$message .= sprintf(' Available presenters: [%s]', implode(', ', $availablePresenters)); $message .= \sprintf(' Available presenters: [%s]', implode(', ', $availablePresenters));
} }
return new self($message); return new self($message);
@@ -12,10 +12,10 @@ final class PresetNotFoundException extends \Exception
*/ */
public static function create(string $preset, array $availablePresets = []): self 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) { if ([] !== $availablePresets) {
$message .= sprintf(' Available presets: "%s"', implode('", "', $availablePresets)); $message .= \sprintf(' Available presets: "%s"', implode('", "', $availablePresets));
} }
return new self($message); return new self($message);
@@ -136,7 +136,7 @@ final class ContentSecurityPolicyHandler implements ContentSecurityPolicyHandler
if (!\in_array('\'unsafe-inline\'', $headers[$header][$type], true)) { if (!\in_array('\'unsafe-inline\'', $headers[$header][$type], true)) {
$headers[$header][$type][] = '\'unsafe-inline\''; $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 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])), '');
} }
/** /**
+1 -1
View File
@@ -55,7 +55,7 @@ final readonly class ResponseExtension implements ResponseExtensionInterface
} }
if ($alreadyRendered) { if ($alreadyRendered) {
$htmlResponse = sprintf('options.push(%s);', $htmlResponse); $htmlResponse = \sprintf('options.push(%s);', $htmlResponse);
} }
// $htmlResponse = "\n".str_replace("\n", '', (string) $htmlResponse)."\n"; // $htmlResponse = "\n".str_replace("\n", '', (string) $htmlResponse)."\n";
@@ -160,7 +160,7 @@ trait NotificationBuilderMethods
if (!\is_bool($condition)) { if (!\is_bool($condition)) {
$type = \gettype($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; return $condition;
+1 -1
View File
@@ -9,7 +9,7 @@ final readonly class PresenterStamp implements StampInterface
public function __construct(private string $pattern) public function __construct(private string $pattern)
{ {
if (false === @preg_match($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));
} }
} }
@@ -17,13 +17,13 @@ final class FilterCriteria implements CriteriaInterface
public function __construct(mixed $criteria) public function __construct(mixed $criteria)
{ {
if (!$criteria instanceof \Closure && !\is_array($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; $criteria = $criteria instanceof \Closure ? [$criteria] : $criteria;
foreach ($criteria as $callback) { foreach ($criteria as $callback) {
if (!$callback instanceof \Closure) { 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; $this->callbacks[] = $callback;
@@ -49,7 +49,7 @@ final class OrderByCriteria implements CriteriaInterface
public function __construct(mixed $criteria) public function __construct(mixed $criteria)
{ {
if (!\is_string($criteria) && !\is_array($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) { foreach ((array) $criteria as $field => $direction) {
@@ -59,22 +59,22 @@ final class OrderByCriteria implements CriteriaInterface
} }
if (!\is_string($field)) { 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)) { 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); $direction = strtoupper($direction);
if (!\in_array($direction, [self::ASC, self::DESC], true)) { 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; $field = $this->aliases[$field] ?? $field;
if (!is_a($field, StampInterface::class, true)) { 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; $this->orderings[$field] = $direction;
@@ -19,7 +19,7 @@ trait RangeExtractor
private function extractRange(string $name, mixed $criteria): array private function extractRange(string $name, mixed $criteria): array
{ {
if (!\is_int($criteria) && !\is_array($criteria)) { 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)) { if (\is_int($criteria)) {
@@ -30,11 +30,11 @@ trait RangeExtractor
$max = $criteria['max'] ?? null; $max = $criteria['max'] ?? null;
if (null !== $min && !\is_int($min)) { 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)) { 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]; return ['min' => $min, 'max' => $max];
+1 -1
View File
@@ -71,7 +71,7 @@ final class FilterFactory implements FilterFactoryInterface
$criteria = \is_callable($criteria) ? $criteria($value) : $criteria; $criteria = \is_callable($criteria) ? $criteria($value) : $criteria;
if (!$criteria instanceof CriteriaInterface) { 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; return $criteria;
+1 -1
View File
@@ -70,6 +70,6 @@ trait ForwardsCalls
*/ */
protected static function throwBadMethodCallException(string $method): never 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));
} }
} }
+5 -5
View File
@@ -56,7 +56,7 @@ trait Macroable
$macro = $method->invoke($mixin); $macro = $method->invoke($mixin);
if (!\is_callable($macro) && !\is_object($macro)) { 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)) { if ($replace || !static::hasMacro($method->name)) {
@@ -83,7 +83,7 @@ trait Macroable
public static function __callStatic(string $method, array $parameters): mixed public static function __callStatic(string $method, array $parameters): mixed
{ {
if (!static::hasMacro($method)) { 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]; $macro = static::$macros[$method];
@@ -93,7 +93,7 @@ trait Macroable
} }
if (!\is_callable($macro)) { 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); return $macro(...$parameters);
@@ -109,7 +109,7 @@ trait Macroable
public function __call(string $method, array $parameters): mixed public function __call(string $method, array $parameters): mixed
{ {
if (!static::hasMacro($method)) { 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]; $macro = static::$macros[$method];
@@ -119,7 +119,7 @@ trait Macroable
} }
if (!\is_callable($macro)) { 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); return $macro(...$parameters);
+1 -1
View File
@@ -9,7 +9,7 @@ final class PHPTemplateEngine implements TemplateEngineInterface
public function render(string $name, array $context = []): string public function render(string $name, array $context = []): string
{ {
if (!file_exists($name) || !is_readable($name)) { 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(); ob_start();
+5 -5
View File
@@ -32,15 +32,15 @@ final class Notification extends Constraint
public function toString(): string public function toString(): string
{ {
$details = [ $details = [
sprintf('type: "%s"', $this->expectedType), \sprintf('type: "%s"', $this->expectedType),
]; ];
if (null !== $this->expectedMessage) { if (null !== $this->expectedMessage) {
$details[] = sprintf('message: "%s"', $this->expectedMessage); $details[] = \sprintf('message: "%s"', $this->expectedMessage);
} }
if (null !== $this->expectedTitle) { if (null !== $this->expectedTitle) {
$details[] = sprintf('title: "%s"', $this->expectedTitle); $details[] = \sprintf('title: "%s"', $this->expectedTitle);
} }
if (!empty($this->expectedOptions)) { if (!empty($this->expectedOptions)) {
@@ -82,7 +82,7 @@ final class Notification extends Constraint
protected function failureDescription(mixed $other): string protected function failureDescription(mixed $other): string
{ {
$foundNotifications = array_map(function (NotificationInterface $notification) { $foundNotifications = array_map(function (NotificationInterface $notification) {
return sprintf( return \sprintf(
'type: "%s", title: "%s", message: "%s", options: [%s]', 'type: "%s", title: "%s", message: "%s", options: [%s]',
$notification->getType(), $notification->getType(),
$notification->getTitle(), $notification->getTitle(),
@@ -95,7 +95,7 @@ final class Notification extends Constraint
$foundNotifications[] = 'No notifications found'; $foundNotifications[] = 'No notifications found';
} }
return sprintf( return \sprintf(
'Failed asserting that NotificationEvents %s. Found: [%s].', 'Failed asserting that NotificationEvents %s. Found: [%s].',
$this->toString(), $this->toString(),
implode('; ', $foundNotifications) implode('; ', $foundNotifications)
@@ -15,7 +15,7 @@ final class NotificationCount extends Constraint
public function toString(): string 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); $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);
} }
/** /**
@@ -19,7 +19,7 @@ final class NotificationMessage extends Constraint
public function toString(): string 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 protected function matches(mixed $other): bool
@@ -44,17 +44,17 @@ final class NotificationMessage extends Constraint
} }
$foundMessages = array_map(function (NotificationInterface $notification) { $foundMessages = array_map(function (NotificationInterface $notification) {
return sprintf('"%s"', $notification->getMessage()); return \sprintf('"%s"', $notification->getMessage());
}, $other->getNotifications()); }, $other->getNotifications());
if (empty($foundMessages)) { if (empty($foundMessages)) {
return sprintf( return \sprintf(
'Expected to find a notification with a message containing "%s", but no notifications were found.', 'Expected to find a notification with a message containing "%s", but no notifications were found.',
$this->expectedMessage $this->expectedMessage
); );
} }
return sprintf( return \sprintf(
'Expected to find a notification with a message containing "%s". Found messages: %s.', 'Expected to find a notification with a message containing "%s". Found messages: %s.',
$this->expectedMessage, $this->expectedMessage,
implode(', ', $foundMessages) implode(', ', $foundMessages)
@@ -23,10 +23,10 @@ final class NotificationOption extends Constraint
public function toString(): string 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) { 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; return $description;
@@ -50,7 +50,7 @@ final class NotificationOptions extends Constraint
$actualOptionsString = implode('; ', $actualOptions) ?: 'none found'; $actualOptionsString = implode('; ', $actualOptions) ?: 'none found';
return sprintf( return \sprintf(
'Failed asserting that NotificationEvents %s. Actual options in notifications: [%s].', 'Failed asserting that NotificationEvents %s. Actual options in notifications: [%s].',
$this->toString(), $this->toString(),
$actualOptionsString $actualOptionsString
@@ -22,7 +22,7 @@ final class NotificationTitle extends Constraint
public function toString(): string 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 protected function matches(mixed $other): bool
@@ -47,17 +47,17 @@ final class NotificationTitle extends Constraint
} }
$foundTitles = array_map(function (NotificationInterface $notification) { $foundTitles = array_map(function (NotificationInterface $notification) {
return sprintf('"%s"', $notification->getTitle()); return \sprintf('"%s"', $notification->getTitle());
}, $other->getNotifications()); }, $other->getNotifications());
if (empty($foundTitles)) { if (empty($foundTitles)) {
return sprintf( return \sprintf(
'Expected to find a notification with a title containing "%s", but no notifications were found.', 'Expected to find a notification with a title containing "%s", but no notifications were found.',
$this->expectedTitle $this->expectedTitle
); );
} }
return sprintf( return \sprintf(
'Expected to find a notification with a title containing "%s". Found titles: %s.', 'Expected to find a notification with a title containing "%s". Found titles: %s.',
$this->expectedTitle, $this->expectedTitle,
implode(', ', $foundTitles) implode(', ', $foundTitles)
@@ -23,7 +23,7 @@ final class NotificationType extends Constraint
public function toString(): string 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); $uniqueTypes = array_unique($actualTypes);
$typesList = implode(', ', $uniqueTypes); $typesList = implode(', ', $uniqueTypes);
return sprintf( return \sprintf(
'Expected the NotificationEvents to contain a notification of type "%s", but found types: %s.', 'Expected the NotificationEvents to contain a notification of type "%s", but found types: %s.',
$this->expectedType, $this->expectedType,
$typesList ?: 'none' $typesList ?: 'none'
+4 -4
View File
@@ -93,12 +93,12 @@ final class InstallCommand extends Command
$this->publishConfig($plugin, $configDir, $configFile); $this->publishConfig($plugin, $configDir, $configFile);
} }
$status = sprintf('<fg=green;options=bold>%s</>', '\\' === \DIRECTORY_SEPARATOR ? 'OK' : "\xE2\x9C\x94" /* HEAVY CHECK MARK (U+2714) */); $status = \sprintf('<fg=green;options=bold>%s</>', '\\' === \DIRECTORY_SEPARATOR ? 'OK' : "\xE2\x9C\x94" /* HEAVY CHECK MARK (U+2714) */);
$output->writeln(sprintf(' %s <fg=blue;options=bold>%s</>', $status, $plugin->getAlias())); $output->writeln(\sprintf(' %s <fg=blue;options=bold>%s</>', $status, $plugin->getAlias()));
} catch (\Exception $e) { } catch (\Exception $e) {
$exitCode = self::FAILURE; $exitCode = self::FAILURE;
$status = sprintf('<fg=red;options=bold>%s</>', '\\' === \DIRECTORY_SEPARATOR ? 'ERROR' : "\xE2\x9C\x98" /* HEAVY BALLOT X (U+2718) */); $status = \sprintf('<fg=red;options=bold>%s</>', '\\' === \DIRECTORY_SEPARATOR ? 'ERROR' : "\xE2\x9C\x98" /* HEAVY BALLOT X (U+2718) */);
$output->writeln(sprintf(' %s <fg=blue;options=bold>%s</> <error>%s</error>', $status, $plugin->getAlias(), $e->getMessage())); $output->writeln(\sprintf(' %s <fg=blue;options=bold>%s</> <error>%s</error>', $status, $plugin->getAlias(), $e->getMessage()));
} }
} }
+69 -1
View File
@@ -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;
}));
+69 -1
View File
@@ -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;
}));
+1 -1
View File
@@ -30,7 +30,7 @@ tasks:
desc: "🔍 Run various linting tools to ensure code quality." desc: "🔍 Run various linting tools to ensure code quality."
cmds: cmds:
- vendor/bin/php-cs-fixer fix --dry-run - vendor/bin/php-cs-fixer fix --dry-run
- vendor/bin/phpstan analyse - vendor/bin/phpstan analyse --memory-limit=-1
- composer validate --strict - composer validate --strict
- vendor/bin/phplint - vendor/bin/phplint
- find src/ -name "composer.json" -exec composer validate --strict {} \; - find src/ -name "composer.json" -exec composer validate --strict {} \;
@@ -55,7 +55,7 @@ final class FlasherContainerTest extends TestCase
$container->method('get')->willReturn($invalidService); $container->method('get')->willReturn($invalidService);
$this->expectException(\InvalidArgumentException::class); $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::from($container);
FlasherContainer::create('invalid_service'); FlasherContainer::create('invalid_service');
@@ -68,7 +68,7 @@ final class EventDispatcherTest extends TestCase
public function testDispatchWithNonCallableListener(): void public function testDispatchWithNonCallableListener(): void
{ {
$event = new class() {}; $event = new class {};
$eventName = $event::class; $eventName = $event::class;
$listener = new NonCallableListener($eventName); $listener = new NonCallableListener($eventName);
+1 -1
View File
@@ -149,7 +149,7 @@ final class ResponseExtensionTest extends TestCase
$responseExtension = new ResponseExtension($flasher, $cspHandler); $responseExtension = new ResponseExtension($flasher, $cspHandler);
$responseExtension->render($request, $response); $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); $expectedContent = str_replace($placeholder, "{$htmlInjection}\n{$placeholder}", $contentBefore);
$response->shouldHaveReceived('setContent')->with($expectedContent)->once(); $response->shouldHaveReceived('setContent')->with($expectedContent)->once();
@@ -70,7 +70,7 @@ final class FilterFactoryTest extends TestCase
$reflect = new \ReflectionClass(FilterFactory::class); $reflect = new \ReflectionClass(FilterFactory::class);
$reflectValue = $reflect->getProperty('criteria'); $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 public function apply(array $envelopes): array
{ {
return $envelopes; return $envelopes;
@@ -11,11 +11,11 @@ final class ForwardsCallsTest extends TestCase
{ {
public function testSuccessfulMethodForwarding(): void public function testSuccessfulMethodForwarding(): void
{ {
$testable = new class() { $testable = new class {
use ForwardsCalls; use ForwardsCalls;
}; };
$secondary = new class() { $secondary = new class {
public function someMethod(): string public function someMethod(): string
{ {
return 'method result'; return 'method result';
@@ -31,11 +31,11 @@ final class ForwardsCallsTest extends TestCase
public function testForwardingAndReturningThis(): void public function testForwardingAndReturningThis(): void
{ {
$testable = new class() { $testable = new class {
use ForwardsCalls; use ForwardsCalls;
}; };
$secondary = new class() { $secondary = new class {
public function selfReturningMethod(): self public function selfReturningMethod(): self
{ {
return $this; return $this;
@@ -52,11 +52,11 @@ final class ForwardsCallsTest extends TestCase
public function testUndefinedMethodCall(): void public function testUndefinedMethodCall(): void
{ {
$testable = new class() { $testable = new class {
use ForwardsCalls; use ForwardsCalls;
}; };
$secondary = new class() { $secondary = new class {
// This class intentionally left blank to simulate an undefined method call. // This class intentionally left blank to simulate an undefined method call.
}; };
+5 -5
View File
@@ -11,7 +11,7 @@ final class MacroableTest extends TestCase
{ {
public function testMacroRegistrationAndExecution(): void public function testMacroRegistrationAndExecution(): void
{ {
$macroableClass = new class() { $macroableClass = new class {
use Macroable; use Macroable;
}; };
@@ -25,11 +25,11 @@ final class MacroableTest extends TestCase
public function testMixin(): void public function testMixin(): void
{ {
$macroableClass = new class() { $macroableClass = new class {
use Macroable; use Macroable;
}; };
$mixin = new class() { $mixin = new class {
public function mixedInMethod(): callable public function mixedInMethod(): callable
{ {
return static function () { return static function () {
@@ -46,7 +46,7 @@ final class MacroableTest extends TestCase
public function testExceptionForNonExistingMacro(): void public function testExceptionForNonExistingMacro(): void
{ {
$macroableClass = new class() { $macroableClass = new class {
use Macroable; use Macroable;
}; };
@@ -56,7 +56,7 @@ final class MacroableTest extends TestCase
public function testExceptionForNonCallableMacro(): void public function testExceptionForNonCallableMacro(): void
{ {
$macroableClass = new class() { $macroableClass = new class {
use Macroable; use Macroable;
}; };