diff --git a/.docker/codecept b/.docker/codecept index 6a4eb803..79d34f10 100755 --- a/.docker/codecept +++ b/.docker/codecept @@ -3,4 +3,8 @@ # Get project name from .env file PROJECT_NAME=$(grep PROJECT_NAME .env | cut -d '=' -f2 | tr -d '"') -docker exec -w /var/www/html/wp-content/plugins/"${PROJECT_NAME}" "${PROJECT_NAME}"_test sh -c "vendor/bin/codecept ${*}" \ No newline at end of file +docker exec \ + --user www-data \ + -w /var/www/html/wp-content/plugins/"${PROJECT_NAME}" \ + "${PROJECT_NAME}"_test \ + sh -c "vendor/bin/codecept ${*}" diff --git a/.docker/composer b/.docker/composer index 2d5d5da6..bfb45f3a 100755 --- a/.docker/composer +++ b/.docker/composer @@ -3,4 +3,9 @@ # Get project name from .env file PROJECT_NAME=$(grep PROJECT_NAME .env | cut -d '=' -f2 | tr -d '"') -docker-compose run -w /var/www/html/wp-content/plugins/"${PROJECT_NAME}" --rm wordpress sh -c "composer ${*}" +docker-compose run \ + --user www-data \ + -w /var/www/html/wp-content/plugins/"${PROJECT_NAME}" \ + --rm \ + wordpress \ + sh -c "composer ${*}" diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml index 4ef25bf5..05b4b8c6 100644 --- a/.docker/docker-compose.yml +++ b/.docker/docker-compose.yml @@ -5,6 +5,8 @@ services: args: PHP_VERSION: ${PHP_VERSION} WP_VERSION: ${WP_VERSION} + HOST_UID: ${HOST_UID:-1000} + HOST_GID: ${HOST_GID:-1000} container_name: ${PROJECT_NAME:-wordpress}_test restart: always ports: diff --git a/.docker/wordpress/Dockerfile b/.docker/wordpress/Dockerfile index 4e5757ed..558dc707 100644 --- a/.docker/wordpress/Dockerfile +++ b/.docker/wordpress/Dockerfile @@ -1,8 +1,18 @@ -ARG PHP_VERSION -ARG WP_VERSION +ARG PHP_VERSION=8.2 +ARG WP_VERSION=6 +ARG HOST_UID=1000 +ARG HOST_GID=1000 FROM wordpress:${WP_VERSION}-php${PHP_VERSION} +ARG HOST_UID +ARG HOST_GID + +RUN set -eux; \ + groupmod -o -g "${HOST_GID}" www-data; \ + usermod -o -u "${HOST_UID}" -g "${HOST_GID}" www-data; \ + chown -R www-data:www-data /var/www + # Install pcov for code coverage RUN set -eux; \ pecl install pcov; \ diff --git a/Makefile b/Makefile index 21dfe3a9..1bcd3b3a 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,16 @@ DOCKER_FOLDER = .docker DOCKER_DIR = cd $(DOCKER_FOLDER) && -HOST_OWNER = $(shell id -u):$(shell id -g) +HOST_UID = $(shell id -u) +HOST_GID = $(shell id -g) +HOST_OWNER = $(HOST_UID):$(HOST_GID) FILES_OWNERSHIP = sudo chown -R $(HOST_OWNER) . DB_USER = $(shell cat .docker/.env | grep DB_USER | cut -d '=' -f2) DB_PASSWORD = $(shell cat .docker/.env | grep DB_PASSWORD | cut -d '=' -f2) DB_NAME = $(shell cat .docker/.env | grep DB_NAME | cut -d '=' -f2) +export HOST_UID +export HOST_GID + default: help # https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html diff --git a/composer.json b/composer.json index 04155d25..3d72d26b 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,7 @@ "require-dev": { "lucatume/wp-browser": "^4.5", "phpspec/prophecy-phpunit": "^2.0", + "dg/bypass-finals": "^1.9", "codeception/module-asserts": "^3.0", "codeception/module-phpbrowser": "^3.0", @@ -55,7 +56,7 @@ "phpcompatibility/php-compatibility": "*", "dealerdirect/phpcodesniffer-composer-installer": "^1.0", - "phpstan/phpstan": "^1.12", + "phpstan/phpstan": "^2.1", "phpbench/phpbench": "^1.2", "phpmetrics/phpmetrics": "^2.8", @@ -63,7 +64,8 @@ "infection/infection": "^0.26.6", "infection/codeception-adapter": "^0.4.1", - "rector/rector": "^0.19.0", + "rector/rector": "^2.4", + "rector/swiss-knife": "^2.3", "symplify/easy-coding-standard": "^12.0", "italystrap/debug": "dev-master" diff --git a/namespace-bc-aliases.php b/namespace-bc-aliases.php index b7fda12f..2f206016 100644 --- a/namespace-bc-aliases.php +++ b/namespace-bc-aliases.php @@ -2,7 +2,12 @@ declare(strict_types=1); -\class_alias( - 'ItalyStrap\ThemeJsonGenerator\Api\ThemeJson', - 'ItalyStrap\ThemeJsonGenerator\Application\Config\Blueprint' -); +$aliases = [ + 'ItalyStrap\ThemeJsonGenerator\Api\ThemeJson' => 'ItalyStrap\ThemeJsonGenerator\Application\Config\Blueprint', +]; + +foreach ($aliases as $class => $alias) { + if (!\class_exists($alias)) { + \class_alias($class, $alias); + } +} diff --git a/rector.php b/rector.php index 42dce751..6138090a 100644 --- a/rector.php +++ b/rector.php @@ -4,38 +4,39 @@ use Rector\Config\RectorConfig; use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector; -use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; -use Rector\Strict\Rector\Ternary\DisallowedShortTernaryRuleFixerRector; -return static function (RectorConfig $rectorConfig): void { - $rectorConfig->paths([ +return RectorConfig::configure() + ->withPaths([ __DIR__ . '/bin', __DIR__ . '/functions', __DIR__ . '/src', __DIR__ . '/tests', - ]); - - $rectorConfig->skip([ - DisallowedShortTernaryRuleFixerRector::class, + ]) + ->withSkip([ __DIR__ . '/tests/_data', __DIR__ . '/tests/_output', __DIR__ . '/tests/_support/_generated', __DIR__ . '/tests/integration/Domain/Input/Styles/ProcessBlocksCustomCssTrait.php', - ]); - - // register a single rule - $rectorConfig->rule(StaticDataProviderClassMethodRector::class); - - // define sets of rules - $rectorConfig->sets([ - SetList::CODE_QUALITY, - SetList::CODING_STYLE, -// SetList::DEAD_CODE, - SetList::EARLY_RETURN, - SetList::TYPE_DECLARATION, - SetList::STRICT_BOOLEANS, - SetList::INSTANCEOF, - LevelSetList::UP_TO_PHP_74 - ]); -}; + ]) + ->withRules([ + StaticDataProviderClassMethodRector::class, + ]) + ->withPreparedSets( +// deadCode: true, // Not yet, this removes also some commented code that I need to keep. + codeQuality: true, + codingStyle: true, + typeDeclarations: true, + privatization: true, + instanceOf: true, + earlyReturn: true, + // carbon: true, + phpunitCodeQuality: true, + ) + ->withImportNames( + importDocBlockNames: false, + importShortClasses: false, + removeUnusedImports: true, + ) + ->withPhpSets() + ->withoutParallel(); diff --git a/src/Api/ThemeJson.php b/src/Api/ThemeJson.php index d3093d10..00c73b58 100644 --- a/src/Api/ThemeJson.php +++ b/src/Api/ThemeJson.php @@ -15,11 +15,9 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Typography\FontSize; /** - * @template TKey as array-key - * @template TValue - * @template-extends Config + * @extends Config */ -final class ThemeJson extends Config implements \JsonSerializable +final class ThemeJson extends Config { public function setGlobalCss(string $css): bool { @@ -28,7 +26,9 @@ public function setGlobalCss(string $css): bool public function appendGlobalCss(string $css): bool { - $currentCss = (string)$this->get(SectionNames::STYLES . '.css'); + $currentCss = $this->get(SectionNames::STYLES . '.css'); + $currentCss = \is_string($currentCss) ? $currentCss : ''; + return $this->set(SectionNames::STYLES . '.css', $currentCss . $css); } @@ -76,19 +76,11 @@ public function setPresets(PresetsInterface $presets): bool foreach ($keys as $key => $value) { try { $this->set($key, $presets->toArrayByCategory($value)); - } catch (\Exception $e) { + } catch (\Exception) { continue; } } return true; } - - /** - * @return array - */ - public function jsonSerialize(): array - { - return $this->getArrayCopy(); - } } diff --git a/src/Application/Commands/DumpCommand.php b/src/Application/Commands/DumpCommand.php index e8cae02c..60d4ce46 100644 --- a/src/Application/Commands/DumpCommand.php +++ b/src/Application/Commands/DumpCommand.php @@ -12,7 +12,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Process\Process; #[AsCommand(name: DumpCommand::NAME, description: DumpCommand::DESCRIPTION)] final class DumpCommand extends Command @@ -46,12 +45,9 @@ final class DumpCommand extends Command */ public const FILE = 'file'; - private ConsoleHandler $handler; - public function __construct( - ConsoleHandler $handler + private ConsoleHandler $handler ) { - $this->handler = $handler; parent::__construct(); } diff --git a/src/Application/Commands/InfoCommand.php b/src/Application/Commands/InfoCommand.php index 1a9e3a69..d482650d 100644 --- a/src/Application/Commands/InfoCommand.php +++ b/src/Application/Commands/InfoCommand.php @@ -13,19 +13,17 @@ use Symfony\Component\Console\Output\OutputInterface; #[AsCommand(name: InfoCommand::NAME, description: InfoCommand::DESCRIPTION)] -class InfoCommand extends Command +final class InfoCommand extends Command { use RootFolderTrait; public const NAME = 'info'; - public const DESCRIPTION = 'Show info about JSON theme'; - private ConsoleHandler $handler; + public const DESCRIPTION = 'Show info about JSON theme'; public function __construct( - ConsoleHandler $handler + private ConsoleHandler $handler ) { - $this->handler = $handler; parent::__construct(); } diff --git a/src/Application/Commands/InitCommand.php b/src/Application/Commands/InitCommand.php index 3cd494bd..001c9a61 100644 --- a/src/Application/Commands/InitCommand.php +++ b/src/Application/Commands/InitCommand.php @@ -4,6 +4,7 @@ namespace ItalyStrap\ThemeJsonGenerator\Application\Commands; +use Symfony\Component\Console\Input\InputOption; use ItalyStrap\ThemeJsonGenerator\Application\Commands\Utils\RootFolderTrait; use ItalyStrap\ThemeJsonGenerator\Application\Message; use ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem\DataFromJsonTrait; @@ -14,7 +15,7 @@ use Symfony\Component\Console\Output\OutputInterface; #[AsCommand(name: InitCommand::NAME, description: InitCommand::DESCRIPTION)] -class InitCommand extends Command +final class InitCommand extends Command { use RootFolderTrait; use DataFromJsonTrait; @@ -23,12 +24,9 @@ class InitCommand extends Command public const DESCRIPTION = 'Initialize theme.json file'; - private ConsoleHandler $handler; - public function __construct( - ConsoleHandler $handler, + private readonly ConsoleHandler $handler, ) { - $this->handler = $handler; parent::__construct(); } @@ -40,7 +38,7 @@ protected function configure(): void $this->addOption( 'styles', 's', - \Symfony\Component\Console\Input\InputOption::VALUE_OPTIONAL, + InputOption::VALUE_OPTIONAL, 'Init JSON file inside styles folder' ); } diff --git a/src/Application/Commands/ValidateCommand.php b/src/Application/Commands/ValidateCommand.php index 9a5fadd9..3da55854 100644 --- a/src/Application/Commands/ValidateCommand.php +++ b/src/Application/Commands/ValidateCommand.php @@ -15,19 +15,19 @@ use Symfony\Component\Console\Output\OutputInterface; #[AsCommand(name: ValidateCommand::NAME, description: ValidateCommand::DESCRIPTION)] -class ValidateCommand extends Command +final class ValidateCommand extends Command { use RootFolderTrait; use DataFromJsonTrait; public const NAME = 'validate'; + public const DESCRIPTION = 'Validate theme.json file'; - private ConsoleHandler $handler; + public function __construct( - ConsoleHandler $handler + private readonly ConsoleHandler $handler ) { - $this->handler = $handler; parent::__construct(); } diff --git a/src/Application/DumpMessage.php b/src/Application/DumpMessage.php index 8213928e..71f4bf77 100644 --- a/src/Application/DumpMessage.php +++ b/src/Application/DumpMessage.php @@ -4,25 +4,14 @@ namespace ItalyStrap\ThemeJsonGenerator\Application; -class DumpMessage +final readonly class DumpMessage { - private string $rootFolder = ''; - - private bool $dry_run; - - private string $sassFolder; - private string $file; - public function __construct( - string $rootFolder, - string $sassFolder, - bool $dry_run, - string $file + private string $rootFolder, + private string $sassFolder, + private bool $dry_run, + private string $file ) { - $this->rootFolder = $rootFolder; - $this->dry_run = $dry_run; - $this->sassFolder = $sassFolder; - $this->file = $file; } public function getRootFolder(): string diff --git a/src/Application/Message.php b/src/Application/Message.php index ee2f460b..f62026a0 100644 --- a/src/Application/Message.php +++ b/src/Application/Message.php @@ -4,13 +4,11 @@ namespace ItalyStrap\ThemeJsonGenerator\Application; -class Message +final readonly class Message { - private string $rootFolder = ''; - - public function __construct(string $rootFolder) - { - $this->rootFolder = $rootFolder; + public function __construct( + private string $rootFolder + ) { } public function getRootFolder(): string diff --git a/src/Application/Middlewares/DeleteSchemaJson.php b/src/Application/Middlewares/DeleteSchemaJson.php index 98dade27..c190ce6a 100644 --- a/src/Application/Middlewares/DeleteSchemaJson.php +++ b/src/Application/Middlewares/DeleteSchemaJson.php @@ -9,7 +9,7 @@ use ItalyStrap\ThemeJsonGenerator\Application\ValidateMessage; use ItalyStrap\ThemeJsonGenerator\Infrastructure\Handler\ConsoleHandler; -class DeleteSchemaJson implements MiddlewareInterface +final class DeleteSchemaJson implements MiddlewareInterface { /** * @phpstan-param ValidateMessage $message diff --git a/src/Application/Middlewares/Dump.php b/src/Application/Middlewares/Dump.php index 6ea63ba3..2ab10b83 100644 --- a/src/Application/Middlewares/Dump.php +++ b/src/Application/Middlewares/Dump.php @@ -4,6 +4,7 @@ namespace ItalyStrap\ThemeJsonGenerator\Application\Middlewares; +use Symfony\Component\Console\Output\ConsoleOutput; use ItalyStrap\Pipeline\HandlerInterface; use ItalyStrap\Pipeline\MiddlewareInterface; use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson; @@ -15,7 +16,7 @@ use ItalyStrap\ThemeJsonGenerator\Infrastructure\Handler\ConsoleHandler; use Symfony\Component\Console\Output\OutputInterface; -class Dump implements MiddlewareInterface +final readonly class Dump implements MiddlewareInterface { /** * @var string @@ -24,16 +25,10 @@ class Dump implements MiddlewareInterface public const JSON_FILE_SUFFIX = '.json'; - private FilesFinder $filesFinder; - - private ThemeJsonContainerFactoryInterface $containerFactory; - public function __construct( - FilesFinder $filesFinder, - ThemeJsonContainerFactoryInterface $containerFactory + private FilesFinder $filesFinder, + private ThemeJsonContainerFactoryInterface $containerFactory ) { - $this->filesFinder = $filesFinder; - $this->containerFactory = $containerFactory; } /** @@ -45,7 +40,7 @@ public function process(object $message, HandlerInterface $handler): int /** * OutputInterface $output */ - $output = new \Symfony\Component\Console\Output\ConsoleOutput(); + $output = new ConsoleOutput(); $count = 0; diff --git a/src/Application/Middlewares/Info.php b/src/Application/Middlewares/Info.php index a7a60023..3993ab5d 100644 --- a/src/Application/Middlewares/Info.php +++ b/src/Application/Middlewares/Info.php @@ -13,14 +13,11 @@ /** * @todo Implement the logic */ -class Info implements MiddlewareInterface +final readonly class Info implements MiddlewareInterface { - private FilesFinder $filesFinder; - public function __construct( - FilesFinder $filesFinder + private FilesFinder $filesFinder ) { - $this->filesFinder = $filesFinder; } /** diff --git a/src/Application/Middlewares/Init.php b/src/Application/Middlewares/Init.php index 837de744..270904d0 100644 --- a/src/Application/Middlewares/Init.php +++ b/src/Application/Middlewares/Init.php @@ -4,6 +4,7 @@ namespace ItalyStrap\ThemeJsonGenerator\Application\Middlewares; +use Symfony\Component\Console\Output\ConsoleOutput; use Brick\VarExporter\VarExporter; use ItalyStrap\Pipeline\HandlerInterface; use ItalyStrap\Pipeline\MiddlewareInterface; @@ -21,7 +22,7 @@ use Webimpress\SafeWriter\FileWriter; use Webmozart\Assert\Assert; -class Init implements MiddlewareInterface +final class Init implements MiddlewareInterface { use DataFromJsonTrait; @@ -46,12 +47,8 @@ class Init implements MiddlewareInterface public const ENTRY_POINT_EXTENSION = '.php'; - private FilesFinder $filesFinder; - - public function __construct( - FilesFinder $filesFinder - ) { - $this->filesFinder = $filesFinder; + public function __construct(private FilesFinder $filesFinder) + { } /** @@ -62,7 +59,7 @@ public function process(object $message, HandlerInterface $handler): int /** * OutputInterface $output */ - $output = new \Symfony\Component\Console\Output\ConsoleOutput(); + $output = new ConsoleOutput(); foreach ($this->filesFinder->find($message->getRootFolder(), 'json') as $file) { $this->generateEntryPointDataFile($output, $file); diff --git a/src/Application/Middlewares/SchemaJson.php b/src/Application/Middlewares/SchemaJson.php index e4c5e618..dad0fa1b 100644 --- a/src/Application/Middlewares/SchemaJson.php +++ b/src/Application/Middlewares/SchemaJson.php @@ -10,7 +10,7 @@ use ItalyStrap\ThemeJsonGenerator\Infrastructure\Handler\ConsoleHandler; use Webimpress\SafeWriter\FileWriter; -class SchemaJson implements MiddlewareInterface +final class SchemaJson implements MiddlewareInterface { /** * @phpstan-param ValidateMessage $message diff --git a/src/Application/Middlewares/Validate.php b/src/Application/Middlewares/Validate.php index 3723accd..9b15f9b8 100644 --- a/src/Application/Middlewares/Validate.php +++ b/src/Application/Middlewares/Validate.php @@ -4,6 +4,7 @@ namespace ItalyStrap\ThemeJsonGenerator\Application\Middlewares; +use Symfony\Component\Console\Output\ConsoleOutput; use ItalyStrap\Pipeline\HandlerInterface; use ItalyStrap\Pipeline\MiddlewareInterface; use ItalyStrap\ThemeJsonGenerator\Application\ValidateMessage; @@ -14,24 +15,15 @@ use ScssPhp\ScssPhp\Compiler; use Symfony\Component\Console\Output\OutputInterface; -class Validate implements MiddlewareInterface +final readonly class Validate implements MiddlewareInterface { use DataFromJsonTrait; - private Validator $validator; - - private FilesFinder $filesFinder; - - private Compiler $compiler; - public function __construct( - Validator $validator, - Compiler $compiler, - FilesFinder $filesFinder + private Validator $validator, + private Compiler $compiler, + private FilesFinder $filesFinder ) { - $this->validator = $validator; - $this->filesFinder = $filesFinder; - $this->compiler = $compiler; } /** @@ -43,7 +35,7 @@ public function process(object $message, HandlerInterface $handler): mixed /** * OutputInterface $output */ - $output = new \Symfony\Component\Console\Output\ConsoleOutput(); + $output = new ConsoleOutput(); foreach ($this->filesFinder->find($message->getRootFolder(), 'json') as $file) { $output->writeln('========================'); diff --git a/src/Application/ValidateMessage.php b/src/Application/ValidateMessage.php index 19f52ed4..5b9da8e4 100644 --- a/src/Application/ValidateMessage.php +++ b/src/Application/ValidateMessage.php @@ -4,22 +4,13 @@ namespace ItalyStrap\ThemeJsonGenerator\Application; -class ValidateMessage +final readonly class ValidateMessage { - private string $rootFolder; - - private string $schemaPath; - - private bool $forceRecreate; - public function __construct( - string $rootFolder, - string $schemaPath, - bool $forceRecreate = false + private string $rootFolder, + private string $schemaPath, + private bool $forceRecreate = false ) { - $this->schemaPath = $schemaPath; - $this->rootFolder = $rootFolder; - $this->forceRecreate = $forceRecreate; } public function getSchemaPath(): string diff --git a/src/Bootstrap.php b/src/Bootstrap.php index 6548fb9f..ba242879 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -29,6 +29,7 @@ public function container(): ContainerInterface return $builder->build(); } + public function run(): int { $container = $this->container(); diff --git a/src/Domain/Input/Settings/Color/Duotone.php b/src/Domain/Input/Settings/Color/Duotone.php index b6aca50c..e8bac5a4 100644 --- a/src/Domain/Input/Settings/Color/Duotone.php +++ b/src/Domain/Input/Settings/Color/Duotone.php @@ -7,7 +7,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetTrait; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetInterface; -class Duotone implements PresetInterface +final class Duotone implements PresetInterface { use PresetTrait; @@ -18,15 +18,16 @@ class Duotone implements PresetInterface private string $name; - private string $slug; - /** * @var array $colors */ private array $colors = []; - public function __construct(string $slug, string $name, Palette ...$colors) - { + public function __construct( + private readonly string $slug, + string $name, + Palette ...$colors + ) { if ($name === '') { throw new \InvalidArgumentException('Duotone must have a name.'); } @@ -35,7 +36,6 @@ public function __construct(string $slug, string $name, Palette ...$colors) throw new \InvalidArgumentException('Duotone must have at least two colors.'); } - $this->slug = $slug; $this->name = $name; $this->colors = $this->assertValidColors(...$colors); } diff --git a/src/Domain/Input/Settings/Color/Gradient.php b/src/Domain/Input/Settings/Color/Gradient.php index a6059f58..48d3539f 100644 --- a/src/Domain/Input/Settings/Color/Gradient.php +++ b/src/Domain/Input/Settings/Color/Gradient.php @@ -8,7 +8,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetTrait; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetInterface; -class Gradient implements PresetInterface +final readonly class Gradient implements PresetInterface { use PresetTrait; @@ -17,17 +17,11 @@ class Gradient implements PresetInterface */ public const TYPE = 'gradient'; - private string $slug; - - private string $name; - - private GradientInterface $gradient; - - public function __construct(string $slug, string $name, GradientInterface $gradient) - { - $this->slug = $slug; - $this->name = $name; - $this->gradient = $gradient; + public function __construct( + private string $slug, + private string $name, + private GradientInterface $gradient + ) { } /** diff --git a/src/Domain/Input/Settings/Color/Palette.php b/src/Domain/Input/Settings/Color/Palette.php index f7398c09..bc19b80e 100644 --- a/src/Domain/Input/Settings/Color/Palette.php +++ b/src/Domain/Input/Settings/Color/Palette.php @@ -8,7 +8,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetTrait; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetInterface; -class Palette implements PresetInterface +final readonly class Palette implements PresetInterface { use PresetTrait; @@ -22,17 +22,11 @@ class Palette implements PresetInterface */ public const KEY = 'settings.color.palette'; - private string $slug; - - private string $name; - - private ColorInterface $color; - - public function __construct(string $slug, string $name, ColorInterface $color) - { - $this->slug = $slug; - $this->name = $name; - $this->color = $color; + public function __construct( + private string $slug, + private string $name, + private ColorInterface $color + ) { } /** diff --git a/src/Domain/Input/Settings/Color/Shadow.php b/src/Domain/Input/Settings/Color/Shadow.php index ad885d4f..e9910d3b 100644 --- a/src/Domain/Input/Settings/Color/Shadow.php +++ b/src/Domain/Input/Settings/Color/Shadow.php @@ -8,7 +8,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetInterface; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetTrait; -class Shadow implements PresetInterface +final class Shadow implements PresetInterface { use PresetTrait; @@ -17,18 +17,17 @@ class Shadow implements PresetInterface */ public const TYPE = 'shadow'; - private string $slug; - private string $name; /** * @var BoxShadow[] */ private array $shadow; - public function __construct(string $slug, string $name, BoxShadow ...$shadow) - { - $this->slug = $slug; - $this->name = $name; + public function __construct( + private readonly string $slug, + private readonly string $name, + BoxShadow ...$shadow + ) { $this->shadow = $shadow; } diff --git a/src/Domain/Input/Settings/Color/Utilities/AchromaticColorsExperimental.php b/src/Domain/Input/Settings/Color/Utilities/AchromaticColorsExperimental.php index 4b845b86..a3b340e0 100644 --- a/src/Domain/Input/Settings/Color/Utilities/AchromaticColorsExperimental.php +++ b/src/Domain/Input/Settings/Color/Utilities/AchromaticColorsExperimental.php @@ -4,7 +4,7 @@ namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities; -class AchromaticColorsExperimental implements ColorsGenerator +final class AchromaticColorsExperimental implements ColorsGenerator { public function generate(): array { diff --git a/src/Domain/Input/Settings/Color/Utilities/AnalogousColorsExperimental.php b/src/Domain/Input/Settings/Color/Utilities/AnalogousColorsExperimental.php index 310f6857..d9a66bcf 100644 --- a/src/Domain/Input/Settings/Color/Utilities/AnalogousColorsExperimental.php +++ b/src/Domain/Input/Settings/Color/Utilities/AnalogousColorsExperimental.php @@ -4,13 +4,10 @@ namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities; -class AnalogousColorsExperimental implements ColorsGenerator +final readonly class AnalogousColorsExperimental implements ColorsGenerator { - private ColorModifierInterface $colorModifier; - - public function __construct(ColorModifierInterface $colorModifier) + public function __construct(private ColorModifierInterface $colorModifier) { - $this->colorModifier = $colorModifier; } public function generate(): array diff --git a/src/Domain/Input/Settings/Color/Utilities/BoxShadow.php b/src/Domain/Input/Settings/Color/Utilities/BoxShadow.php index 949873c5..25955919 100644 --- a/src/Domain/Input/Settings/Color/Utilities/BoxShadow.php +++ b/src/Domain/Input/Settings/Color/Utilities/BoxShadow.php @@ -6,13 +6,18 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Palette; -class BoxShadow +final class BoxShadow implements \Stringable { private bool $inset = false; + private string $x = ''; + private string $y = ''; + private string $blur = ''; + private string $spread = ''; + private string $color = ''; public function inset(bool $inset = true): self @@ -91,7 +96,7 @@ public function __toString(): string ]; $this->reset(); - return \trim(\implode(' ', \array_filter($shadow, static fn($value) => $value !== ''))); + return \trim(\implode(' ', \array_filter($shadow, static fn(string $value): bool => $value !== ''))); } public function __clone() diff --git a/src/Domain/Input/Settings/Color/Utilities/Color.php b/src/Domain/Input/Settings/Color/Utilities/Color.php index e0423a4d..5fa6c06c 100644 --- a/src/Domain/Input/Settings/Color/Utilities/Color.php +++ b/src/Domain/Input/Settings/Color/Utilities/Color.php @@ -10,16 +10,13 @@ final class Color implements ColorInterface { - private SpatieColor $spatieColor; + private readonly SpatieColor $spatieColor; - private string $type; + private readonly string $type; - private Hsla $hsla; + private readonly Hsla $hsla; - /** - * @var string|float - */ - private $alpha = 1.0; + private float|string $alpha = 1.0; /** * Luminance of #808080 or rgb(128,128,128) or hsl(0,0%,50%) @@ -35,7 +32,6 @@ public function __construct(string $color) $this->type = $reflected->getShortName(); if ($reflected->hasProperty('alpha')) { $reflectionProperty = $reflected->getProperty('alpha'); - $reflectionProperty->setAccessible(true); $alpha = $reflectionProperty->getValue($this->spatieColor); if (!\is_string($alpha) && !\is_float($alpha) && !\is_int($alpha)) { throw new \RuntimeException(\sprintf( @@ -45,7 +41,6 @@ public function __construct(string $color) } $this->alpha = \is_int($alpha) ? (float)$alpha : $alpha; - $reflectionProperty->setAccessible(false); } $alpha = $this->fromHexToFloat($this->alpha); @@ -101,7 +96,7 @@ public function relativeLuminance(ColorInterface $color): float /** * @return string|int */ - public function red() + public function red(): string|int { $red = $this->spatieColor->red(); if (!\is_string($red) && !\is_int($red)) { @@ -114,7 +109,7 @@ public function red() /** * @return string|int */ - public function green() + public function green(): string|int { $green = $this->spatieColor->green(); if (!\is_string($green) && !\is_int($green)) { @@ -127,7 +122,7 @@ public function green() /** * @return string|int */ - public function blue() + public function blue(): string|int { $blue = $this->spatieColor->blue(); if (!\is_string($blue) && !\is_int($blue)) { @@ -152,7 +147,7 @@ public function lightness(): int return (int)\round($this->hsla->lightness()); } - public function alpha() + public function alpha(): float|string { return $this->alpha; } @@ -174,7 +169,7 @@ public function toHsl(): self public function toHsla(?float $alpha = null): self { - $alpha = $alpha ?? $this->fromHexToFloat($this->alpha); + $alpha ??= $this->fromHexToFloat($this->alpha); return new self((string) $this->spatieColor->toHsla($alpha)); } @@ -185,7 +180,7 @@ public function toRgb(): self public function toRgba(?float $alpha = null): self { - $alpha = $alpha ?? $this->fromHexToFloat($this->alpha); + $alpha ??= $this->fromHexToFloat($this->alpha); return new self((string) $this->spatieColor->toRgba($alpha)); } diff --git a/src/Domain/Input/Settings/Color/Utilities/ColorFactory.php b/src/Domain/Input/Settings/Color/Utilities/ColorFactory.php index 620ddbb0..740132d9 100644 --- a/src/Domain/Input/Settings/Color/Utilities/ColorFactory.php +++ b/src/Domain/Input/Settings/Color/Utilities/ColorFactory.php @@ -27,7 +27,7 @@ public function fromColorString(string $color): ColorInterface */ public function hsla(int $hue, float $saturation, float $lightness, float $alpha = 1): ColorInterface { - return new Color("hsla($hue, $saturation%, $lightness%, $alpha)"); + return new Color(sprintf('hsla(%d, %s%%, %s%%, %s)', $hue, $saturation, $lightness, $alpha)); } /** @@ -35,6 +35,6 @@ public function hsla(int $hue, float $saturation, float $lightness, float $alpha */ public function rgba(int $red, int $green, int $blue, float $alpha = 1): ColorInterface { - return new Color("rgba($red, $green, $blue, $alpha)"); + return new Color(sprintf('rgba(%d, %d, %d, %s)', $red, $green, $blue, $alpha)); } } diff --git a/src/Domain/Input/Settings/Color/Utilities/ColorModifier.php b/src/Domain/Input/Settings/Color/Utilities/ColorModifier.php index 54351346..d7a6b490 100644 --- a/src/Domain/Input/Settings/Color/Utilities/ColorModifier.php +++ b/src/Domain/Input/Settings/Color/Utilities/ColorModifier.php @@ -6,10 +6,8 @@ use Exception; -final class ColorModifier implements ColorModifierInterface +final readonly class ColorModifier implements ColorModifierInterface { - private ColorInterface $color; - private ColorFactoryInterface $color_factory; private string $initialType; @@ -17,9 +15,8 @@ final class ColorModifier implements ColorModifierInterface /** * @throws Exception */ - public function __construct(ColorInterface $color, ?ColorFactoryInterface $factory = null) + public function __construct(private ColorInterface $color, ?ColorFactoryInterface $factory = null) { - $this->color = $color; $this->color_factory = $factory ?? new ColorFactory(); $this->initialType = $this->color->type(); } diff --git a/src/Domain/Input/Settings/Color/Utilities/ComplementaryColorsExperimental.php b/src/Domain/Input/Settings/Color/Utilities/ComplementaryColorsExperimental.php index 65dc9381..daa15b07 100644 --- a/src/Domain/Input/Settings/Color/Utilities/ComplementaryColorsExperimental.php +++ b/src/Domain/Input/Settings/Color/Utilities/ComplementaryColorsExperimental.php @@ -4,13 +4,10 @@ namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities; -class ComplementaryColorsExperimental implements ColorsGenerator +final readonly class ComplementaryColorsExperimental implements ColorsGenerator { - private ColorModifierInterface $color; - - public function __construct(ColorModifierInterface $color) + public function __construct(private ColorModifierInterface $color) { - $this->color = $color; } public function generate(): array diff --git a/src/Domain/Input/Settings/Color/Utilities/LinearGradient.php b/src/Domain/Input/Settings/Color/Utilities/LinearGradient.php index 451d47c6..3400ac9d 100644 --- a/src/Domain/Input/Settings/Color/Utilities/LinearGradient.php +++ b/src/Domain/Input/Settings/Color/Utilities/LinearGradient.php @@ -6,7 +6,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Palette; -class LinearGradient implements GradientInterface +final class LinearGradient implements GradientInterface { private string $direction = ''; diff --git a/src/Domain/Input/Settings/Color/Utilities/MonochromaticColorsExperimental.php b/src/Domain/Input/Settings/Color/Utilities/MonochromaticColorsExperimental.php index 25a3d1dc..1b559b54 100644 --- a/src/Domain/Input/Settings/Color/Utilities/MonochromaticColorsExperimental.php +++ b/src/Domain/Input/Settings/Color/Utilities/MonochromaticColorsExperimental.php @@ -4,22 +4,15 @@ namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities; -class MonochromaticColorsExperimental implements ColorsGenerator +final class MonochromaticColorsExperimental implements ColorsGenerator { - private ColorModifierInterface $colorModifier; - - /** - * @var array - */ - private array $steps = []; - /** * @param array $steps */ - public function __construct(ColorModifierInterface $color, array $steps) - { - $this->colorModifier = $color; - $this->steps = $steps; + public function __construct( + private readonly ColorModifierInterface $colorModifier, + private array $steps + ) { } public function generate(): array diff --git a/src/Domain/Input/Settings/Color/Utilities/ShadesGeneratorExperimental.php b/src/Domain/Input/Settings/Color/Utilities/ShadesGeneratorExperimental.php index b1286cb6..6fd537a7 100644 --- a/src/Domain/Input/Settings/Color/Utilities/ShadesGeneratorExperimental.php +++ b/src/Domain/Input/Settings/Color/Utilities/ShadesGeneratorExperimental.php @@ -6,7 +6,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Palette; -class ShadesGeneratorExperimental +final readonly class ShadesGeneratorExperimental { /** * @var int @@ -23,16 +23,6 @@ class ShadesGeneratorExperimental */ public const INCREMENT_BY = 100; - private ColorInterface $color; - - private string $slug; - - private int $min; - - private int $max; - - private int $increment_by; - public static function fromPalette( Palette $palette, int $min = self::MIN, @@ -65,17 +55,12 @@ public static function fromColorInfo( } public function __construct( - ColorInterface $color, - string $slug, - int $min = self::MIN, - int $max = self::MAX, - int $increment_by = self::INCREMENT_BY + private ColorInterface $color, + private string $slug, + private int $min = self::MIN, + private int $max = self::MAX, + private int $increment_by = self::INCREMENT_BY ) { - $this->color = $color; - $this->slug = $slug; - $this->min = $min; - $this->max = $max; - $this->increment_by = $increment_by; } public function toColors(): array @@ -105,14 +90,14 @@ public function toPalettes(): array } /** - * This functionality create an array of shades of a given color + * This functionality creates an array of shades of a given color * The created shades are from 10% to 100% of the given color * If the color is dark, the shades will be lightened * If the color is light, the shades will be darkened * - * This method create an array of Palette of shades of a color + * This method creates an array of Palette of shades of a color * If the color generated is #000000 or #ffffff it will be skipped, - * and you will get only the shades of the color without duplicates values likes many #000000 or #ffffff + * and you will get only the shades of the color without duplicates values like many #000000 or #ffffff * * @throws \Exception */ diff --git a/src/Domain/Input/Settings/Color/Utilities/SplitComplementaryColorsExperimental.php b/src/Domain/Input/Settings/Color/Utilities/SplitComplementaryColorsExperimental.php index 81813ba4..b2996e14 100644 --- a/src/Domain/Input/Settings/Color/Utilities/SplitComplementaryColorsExperimental.php +++ b/src/Domain/Input/Settings/Color/Utilities/SplitComplementaryColorsExperimental.php @@ -4,13 +4,11 @@ namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities; -class SplitComplementaryColorsExperimental implements ColorsGenerator +final readonly class SplitComplementaryColorsExperimental implements ColorsGenerator { - private ColorModifierInterface $colorModifier; - - public function __construct(ColorModifierInterface $colorModifier) - { - $this->colorModifier = $colorModifier; + public function __construct( + private ColorModifierInterface $colorModifier + ) { } public function generate(): array diff --git a/src/Domain/Input/Settings/Color/Utilities/SquareColorsExperimental.php b/src/Domain/Input/Settings/Color/Utilities/SquareColorsExperimental.php index 5ccc94e1..9db16e56 100644 --- a/src/Domain/Input/Settings/Color/Utilities/SquareColorsExperimental.php +++ b/src/Domain/Input/Settings/Color/Utilities/SquareColorsExperimental.php @@ -4,13 +4,11 @@ namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities; -class SquareColorsExperimental implements ColorsGenerator +final readonly class SquareColorsExperimental implements ColorsGenerator { - private ColorModifierInterface $colorModifier; - - public function __construct(ColorModifierInterface $colorModifier) - { - $this->colorModifier = $colorModifier; + public function __construct( + private ColorModifierInterface $colorModifier + ) { } public function generate(): array diff --git a/src/Domain/Input/Settings/Color/Utilities/TriadicColorsExperimental.php b/src/Domain/Input/Settings/Color/Utilities/TriadicColorsExperimental.php index 2905b733..8c5836a7 100644 --- a/src/Domain/Input/Settings/Color/Utilities/TriadicColorsExperimental.php +++ b/src/Domain/Input/Settings/Color/Utilities/TriadicColorsExperimental.php @@ -4,13 +4,11 @@ namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities; -class TriadicColorsExperimental implements ColorsGenerator +final readonly class TriadicColorsExperimental implements ColorsGenerator { - private ColorModifierInterface $colorModifier; - - public function __construct(ColorModifierInterface $colorModifier) - { - $this->colorModifier = $colorModifier; + public function __construct( + private ColorModifierInterface $colorModifier + ) { } public function generate(): array diff --git a/src/Domain/Input/Settings/Custom/Custom.php b/src/Domain/Input/Settings/Custom/Custom.php index 81e5327a..382f2e99 100644 --- a/src/Domain/Input/Settings/Custom/Custom.php +++ b/src/Domain/Input/Settings/Custom/Custom.php @@ -7,7 +7,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetTrait; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetInterface; -class Custom implements PresetInterface +final class Custom implements PresetInterface { use PresetTrait; @@ -16,19 +16,13 @@ class Custom implements PresetInterface */ public const TYPE = 'custom'; - private string $key; - - private string $value; - private string $name; public function __construct( - string $key, - string $value + private string $key, + private string $value ) { - $this->key = $key; $this->name = \ucfirst(\str_replace('.', ' ', $this->key)); - $this->value = $value; } public function slug(): string diff --git a/src/Domain/Input/Settings/Custom/CustomToPresets.php b/src/Domain/Input/Settings/Custom/CustomToPresets.php index e1f5adee..6e0b4462 100644 --- a/src/Domain/Input/Settings/Custom/CustomToPresets.php +++ b/src/Domain/Input/Settings/Custom/CustomToPresets.php @@ -4,20 +4,13 @@ namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Custom; -class CustomToPresets +final readonly class CustomToPresets { - /** - * @var array - */ - private array $customs = []; - /** * @param array $customs */ - public function __construct( - array $customs = [] - ) { - $this->customs = $customs; + public function __construct(private array $customs = []) + { } /** diff --git a/src/Domain/Input/Settings/NullPresets.php b/src/Domain/Input/Settings/NullPresets.php index 011d4668..f18340b8 100644 --- a/src/Domain/Input/Settings/NullPresets.php +++ b/src/Domain/Input/Settings/NullPresets.php @@ -7,7 +7,7 @@ /** * @infection-ignore-all */ -class NullPresets implements PresetsInterface +final class NullPresets implements PresetsInterface { public function add(PresetInterface $item): PresetsInterface { diff --git a/src/Domain/Input/Settings/Presets.php b/src/Domain/Input/Settings/Presets.php index 093cae85..898a871e 100644 --- a/src/Domain/Input/Settings/Presets.php +++ b/src/Domain/Input/Settings/Presets.php @@ -13,12 +13,12 @@ * @see PresetsTest * @see PresetsIntegrationTest */ -class Presets implements PresetsInterface, \JsonSerializable +final class Presets implements PresetsInterface, \JsonSerializable { use AccessValueInArrayWithNotationTrait; /** - * @var PresetInterface[] + * @var array */ private array $collection = []; diff --git a/src/Domain/Input/Settings/Typography/FontFamily.php b/src/Domain/Input/Settings/Typography/FontFamily.php index 44cbaad6..b479d213 100644 --- a/src/Domain/Input/Settings/Typography/FontFamily.php +++ b/src/Domain/Input/Settings/Typography/FontFamily.php @@ -7,7 +7,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetTrait; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetInterface; -class FontFamily implements PresetInterface +final readonly class FontFamily implements PresetInterface { use PresetTrait; @@ -16,17 +16,11 @@ class FontFamily implements PresetInterface */ public const TYPE = 'fontFamily'; - private string $slug; - - private string $name; - - private string $fontFamily; - - public function __construct(string $slug, string $name, string $fontFamily) - { - $this->slug = $slug; - $this->name = $name; - $this->fontFamily = $fontFamily; + public function __construct( + private string $slug, + private string $name, + private string $fontFamily + ) { } /** diff --git a/src/Domain/Input/Settings/Typography/FontSize.php b/src/Domain/Input/Settings/Typography/FontSize.php index b3968be4..1c786518 100644 --- a/src/Domain/Input/Settings/Typography/FontSize.php +++ b/src/Domain/Input/Settings/Typography/FontSize.php @@ -8,7 +8,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetInterface; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Typography\Utilities\Fluid; -class FontSize implements PresetInterface +final readonly class FontSize implements PresetInterface { use PresetTrait; @@ -17,20 +17,12 @@ class FontSize implements PresetInterface */ public const TYPE = 'fontSize'; - private string $slug; - - private string $name; - - private string $size; - - private ?Fluid $fluid; - - public function __construct(string $slug, string $name, string $size, ?Fluid $fluid = null) - { - $this->slug = $slug; - $this->name = $name; - $this->size = $size; - $this->fluid = $fluid; + public function __construct( + private string $slug, + private string $name, + private string $size, + private ?Fluid $fluid = null + ) { } /** @@ -43,6 +35,6 @@ public function toArray(): array 'name' => $this->name, 'size' => $this->size, 'fluid' => $this->fluid, - ], static fn ($value): bool => null !== $value); + ], static fn (string|Fluid|null $value): bool => null !== $value); } } diff --git a/src/Domain/Input/Settings/Typography/Utilities/Fluid.php b/src/Domain/Input/Settings/Typography/Utilities/Fluid.php index 9a2947fa..c706c32c 100644 --- a/src/Domain/Input/Settings/Typography/Utilities/Fluid.php +++ b/src/Domain/Input/Settings/Typography/Utilities/Fluid.php @@ -4,7 +4,7 @@ namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Typography\Utilities; -class Fluid +final readonly class Fluid { /** * @var string @@ -21,14 +21,10 @@ class Fluid */ public const MAX = 'max'; - private string $min; - - private string $max; - - public function __construct(string $min, string $max) - { - $this->min = $min; - $this->max = $max; + public function __construct( + private string $min, + private string $max + ) { } /** diff --git a/src/Domain/Input/Settings/Typography/Utilities/FontFace.php b/src/Domain/Input/Settings/Typography/Utilities/FontFace.php index fca02c70..dcb96162 100644 --- a/src/Domain/Input/Settings/Typography/Utilities/FontFace.php +++ b/src/Domain/Input/Settings/Typography/Utilities/FontFace.php @@ -4,36 +4,18 @@ namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Typography\Utilities; -class FontFace +final readonly class FontFace { - private string $fontFamily; - - private string $fontWeight; - - private string $fontStyle; - - private string $fontStretch; - - /** - * @var string[] - */ - private array $src; - /** * @param string[] $src */ public function __construct( - string $fontFamily, - string $fontWeight, - string $fontStyle, - string $fontStretch, - array $src + private string $fontFamily, + private string $fontWeight, + private string $fontStyle, + private string $fontStretch, + private array $src ) { - $this->fontFamily = $fontFamily; - $this->fontWeight = $fontWeight; - $this->fontStyle = $fontStyle; - $this->fontStretch = $fontStretch; - $this->src = $src; } /** diff --git a/src/Domain/Input/Settings/Utilities/CalcExperimental.php b/src/Domain/Input/Settings/Utilities/CalcExperimental.php index 75a438cc..5ad06f11 100644 --- a/src/Domain/Input/Settings/Utilities/CalcExperimental.php +++ b/src/Domain/Input/Settings/Utilities/CalcExperimental.php @@ -4,7 +4,7 @@ namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Utilities; -class CalcExperimental +final readonly class CalcExperimental implements \Stringable { private string $value; diff --git a/src/Domain/Input/Settings/Utilities/ClampExperimental.php b/src/Domain/Input/Settings/Utilities/ClampExperimental.php index 4190deb3..9e1841d2 100644 --- a/src/Domain/Input/Settings/Utilities/ClampExperimental.php +++ b/src/Domain/Input/Settings/Utilities/ClampExperimental.php @@ -4,22 +4,10 @@ namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Utilities; -class ClampExperimental +final readonly class ClampExperimental implements \Stringable { - private string $value; - - private string $min; - - private string $max; - - public function __construct( - string $value, - string $min, - string $max - ) { - $this->value = $value; - $this->min = $min; - $this->max = $max; + public function __construct(private string $value, private string $min, private string $max) + { } public function __toString(): string diff --git a/src/Domain/Input/Settings/Utilities/DimensionExperimental.php b/src/Domain/Input/Settings/Utilities/DimensionExperimental.php index 38e55c0a..55a765d9 100644 --- a/src/Domain/Input/Settings/Utilities/DimensionExperimental.php +++ b/src/Domain/Input/Settings/Utilities/DimensionExperimental.php @@ -10,7 +10,7 @@ * https://github.com/PhpUnitsOfMeasure/php-units-of-measure * https://wiki.php.net/rfc/clamp */ -final class DimensionExperimental +final readonly class DimensionExperimental implements \Stringable { private string $value; diff --git a/src/Domain/Input/Settings/Utilities/SupportedUnitsExperimental.php b/src/Domain/Input/Settings/Utilities/SupportedUnitsExperimental.php index a2b64930..ab2a60a4 100644 --- a/src/Domain/Input/Settings/Utilities/SupportedUnitsExperimental.php +++ b/src/Domain/Input/Settings/Utilities/SupportedUnitsExperimental.php @@ -4,7 +4,7 @@ namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Utilities; -class SupportedUnitsExperimental implements UnitInterfaceExperimental +final readonly class SupportedUnitsExperimental implements UnitInterfaceExperimental { private array $units; diff --git a/src/Domain/Input/Styles/Css.php b/src/Domain/Input/Styles/Css.php index 72b53f4d..e8dc5586 100644 --- a/src/Domain/Input/Styles/Css.php +++ b/src/Domain/Input/Styles/Css.php @@ -19,10 +19,12 @@ * * @see CssTest */ -class Css implements CssInterface +final class Css implements CssInterface { - private PresetsInterface $presets; + private readonly PresetsInterface $presets; + private bool $isCompressed = true; + private bool $shouldResolveVariables = true; public function __construct( @@ -101,6 +103,7 @@ public function parse(string $css, string $selector = ''): string $cssBlock .= $space . $rule->getRule() . ': ' . (string)$rule->getValue() . $important . ';' . $newLine; // phpcs:enable } + $cssBlock .= '}' . $newLineAfterBlock; $additionalSelectors[] = $cssBlock; } @@ -180,10 +183,10 @@ private function duplicateRulesForSelectorList(string $css): string $rules = $matches[0]; foreach ($selectorArray as $selector) { - $cssFinal .= \rtrim($selector) . " $rules\n"; + $cssFinal .= \rtrim($selector) . sprintf(' %s%s', $rules, PHP_EOL); } - $cssFinal .= \rtrim($lastSelector) . " $rules\n"; + $cssFinal .= \rtrim($lastSelector) . sprintf(' %s%s', $rules, PHP_EOL); return $cssFinal; } diff --git a/src/Domain/Input/Styles/Outline.php b/src/Domain/Input/Styles/Outline.php index ff80abcb..b8cd2c69 100644 --- a/src/Domain/Input/Styles/Outline.php +++ b/src/Domain/Input/Styles/Outline.php @@ -4,7 +4,7 @@ namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles; -class Outline implements ArrayableInterface, \JsonSerializable +final class Outline implements ArrayableInterface, \JsonSerializable { use CommonTrait; diff --git a/src/Domain/Input/Styles/Scss.php b/src/Domain/Input/Styles/Scss.php index 3af4d1db..e96fb36a 100644 --- a/src/Domain/Input/Styles/Scss.php +++ b/src/Domain/Input/Styles/Scss.php @@ -13,11 +13,9 @@ /** * @see ScssTest */ -class Scss implements CssInterface +final class Scss implements CssInterface { - private Css $css; - private Compiler $compiler; - private PresetsInterface $presets; + private readonly PresetsInterface $presets; /** * @var 'compressed'|'expanded' @@ -25,12 +23,10 @@ class Scss implements CssInterface private string $outputStyle = OutputStyle::COMPRESSED; public function __construct( - Css $css, - Compiler $compiler, + private readonly Css $css, + private readonly Compiler $compiler, ?PresetsInterface $presets = null ) { - $this->css = $css; - $this->compiler = $compiler; $this->presets = $presets ?? new NullPresets(); } diff --git a/src/Domain/Input/Styles/Spacing.php b/src/Domain/Input/Styles/Spacing.php index 2711cbbb..01a04963 100644 --- a/src/Domain/Input/Styles/Spacing.php +++ b/src/Domain/Input/Styles/Spacing.php @@ -62,33 +62,28 @@ public function left(string $value): self */ public function shorthand(array $values): self { - switch (\count($values)) { - case 1: - return $this->setProperty(self::TOP, (string)$values[0]) - ->setProperty(self::RIGHT, (string)$values[0]) - ->setProperty(self::BOTTOM, (string)$values[0]) - ->setProperty(self::LEFT, (string)$values[0]); - case 2: - return $this->setProperty(self::TOP, (string)$values[0]) - ->setProperty(self::RIGHT, (string)$values[1]) - ->setProperty(self::BOTTOM, (string)$values[0]) - ->setProperty(self::LEFT, (string)$values[1]); - case 3: - return $this->setProperty(self::TOP, (string)$values[0]) - ->setProperty(self::RIGHT, (string)$values[1]) - ->setProperty(self::BOTTOM, (string)$values[2]) - ->setProperty(self::LEFT, (string)$values[1]); - case 4: - return $this->setProperty(self::TOP, (string)$values[0]) - ->setProperty(self::RIGHT, (string)$values[1]) - ->setProperty(self::BOTTOM, (string)$values[2]) - ->setProperty(self::LEFT, (string)$values[3]); - default: - throw new \InvalidArgumentException(\sprintf( - 'The shorthand method accept only 1, 2, 3 or 4 values, %d given', - \count($values) - )); - } + return match (\count($values)) { + 1 => $this->setProperty(self::TOP, (string)$values[0]) + ->setProperty(self::RIGHT, (string)$values[0]) + ->setProperty(self::BOTTOM, (string)$values[0]) + ->setProperty(self::LEFT, (string)$values[0]), + 2 => $this->setProperty(self::TOP, (string)$values[0]) + ->setProperty(self::RIGHT, (string)$values[1]) + ->setProperty(self::BOTTOM, (string)$values[0]) + ->setProperty(self::LEFT, (string)$values[1]), + 3 => $this->setProperty(self::TOP, (string)$values[0]) + ->setProperty(self::RIGHT, (string)$values[1]) + ->setProperty(self::BOTTOM, (string)$values[2]) + ->setProperty(self::LEFT, (string)$values[1]), + 4 => $this->setProperty(self::TOP, (string)$values[0]) + ->setProperty(self::RIGHT, (string)$values[1]) + ->setProperty(self::BOTTOM, (string)$values[2]) + ->setProperty(self::LEFT, (string)$values[3]), + default => throw new \InvalidArgumentException(\sprintf( + 'The shorthand method accept only 1, 2, 3 or 4 values, %d given', + \count($values) + )), + }; } public function vertical(string $value): self diff --git a/src/Infrastructure/Filesystem/DataFromJsonTrait.php b/src/Infrastructure/Filesystem/DataFromJsonTrait.php index 70e76dc1..b4ee68a7 100644 --- a/src/Infrastructure/Filesystem/DataFromJsonTrait.php +++ b/src/Infrastructure/Filesystem/DataFromJsonTrait.php @@ -22,7 +22,7 @@ private function objectFromPath(string $path): object /** * @return array|object */ - private function fromPath(string $path, ?bool $isAssociative) + private function fromPath(string $path, ?bool $isAssociative): object|array { $json = \file_get_contents($path); if ($json === false) { diff --git a/src/Infrastructure/Filesystem/FilesFinder.php b/src/Infrastructure/Filesystem/FilesFinder.php index f51c0e67..0a8545c9 100644 --- a/src/Infrastructure/Filesystem/FilesFinder.php +++ b/src/Infrastructure/Filesystem/FilesFinder.php @@ -6,7 +6,7 @@ use ItalyStrap\Finder\FinderInterface; -class FilesFinder +final readonly class FilesFinder { public const ROOT_FILE_NAME = 'theme'; @@ -14,12 +14,8 @@ class FilesFinder public const JSON_FILE_SUFFIX = '.json'; - private FinderInterface $finder; - - public function __construct( - FinderInterface $finder - ) { - $this->finder = $finder; + public function __construct(private FinderInterface $finder) + { } /** @@ -88,7 +84,7 @@ public function resolveJsonFile(\SplFileInfo $file): string throw new \RuntimeException('Unable to read the style.css file'); } - if (\strpos($styleCssContent, 'Theme Name:') === false) { + if (!str_contains($styleCssContent, 'Theme Name:')) { throw new \RuntimeException('The style.css file is not a valid WordPress theme'); } diff --git a/src/Infrastructure/Filesystem/JsonFileWriter.php b/src/Infrastructure/Filesystem/JsonFileWriter.php index a4ba15a0..35795911 100644 --- a/src/Infrastructure/Filesystem/JsonFileWriter.php +++ b/src/Infrastructure/Filesystem/JsonFileWriter.php @@ -7,16 +7,14 @@ use ItalyStrap\Config\ConfigInterface; use Webimpress\SafeWriter; -class JsonFileWriter implements FileWriter +final readonly class JsonFileWriter implements FileWriter { - private string $path; - /** * @param string $path */ - public function __construct(string $path) - { - $this->path = $path; + public function __construct( + private string $path + ) { } /** diff --git a/src/Infrastructure/Filesystem/ScssFileWriter.php b/src/Infrastructure/Filesystem/ScssFileWriter.php index bcb740ec..282ccda2 100644 --- a/src/Infrastructure/Filesystem/ScssFileWriter.php +++ b/src/Infrastructure/Filesystem/ScssFileWriter.php @@ -7,18 +7,15 @@ use ItalyStrap\Config\ConfigInterface; use Webimpress\SafeWriter; -class ScssFileWriter implements FileWriter +final class ScssFileWriter implements FileWriter { use ConvertCase; - private string $path; - /** * @param string $path */ - public function __construct(string $path) + public function __construct(private string $path) { - $this->path = $path; } /** diff --git a/src/ModuleApplication.php b/src/ModuleApplication.php index 43a16205..3ce20f65 100644 --- a/src/ModuleApplication.php +++ b/src/ModuleApplication.php @@ -21,7 +21,7 @@ use ItalyStrap\ThemeJsonGenerator\Infrastructure\Handler\ConsoleHandler; use Psr\Container\ContainerInterface; -class ModuleApplication implements ModuleInterface +final class ModuleApplication implements ModuleInterface { /** * @return array @@ -33,28 +33,28 @@ public function __invoke(): array ThemeJsonContainerFactoryInterface::class => ThemeJsonContainerFactory::class, ], AurynConfig::FACTORIES => [ - InitCommand::class => function (ContainerInterface $container): InitCommand { - return new InitCommand(new ConsoleHandler( - $container->get(Init::class) - )); - }, - DumpCommand::class => function (ContainerInterface $container): DumpCommand { - return new DumpCommand(new ConsoleHandler( - $container->get(Dump::class), - )); - }, - ValidateCommand::class => function (ContainerInterface $container): ValidateCommand { - return new ValidateCommand(new ConsoleHandler( - new DeleteSchemaJson(), - new SchemaJson(), - $container->get(Validate::class) - )); - }, - InfoCommand::class => function (ContainerInterface $container): InfoCommand { - return new InfoCommand(new ConsoleHandler( - $container->get(Info::class) - )); - }, + InitCommand::class + => fn(ContainerInterface $container): InitCommand + => new InitCommand(new ConsoleHandler( + $container->get(Init::class) + )), + DumpCommand::class + => fn(ContainerInterface $container): DumpCommand + => new DumpCommand(new ConsoleHandler( + $container->get(Dump::class), + )), + ValidateCommand::class + => fn(ContainerInterface $container): ValidateCommand + => new ValidateCommand(new ConsoleHandler( + new DeleteSchemaJson(), + new SchemaJson(), + $container->get(Validate::class) + )), + InfoCommand::class + => fn(ContainerInterface $container): InfoCommand + => new InfoCommand(new ConsoleHandler( + $container->get(Info::class) + )), ], ]; } diff --git a/src/ModuleInfrastructure.php b/src/ModuleInfrastructure.php index 84bd9990..1fb8f33d 100644 --- a/src/ModuleInfrastructure.php +++ b/src/ModuleInfrastructure.php @@ -4,13 +4,15 @@ namespace ItalyStrap\ThemeJsonGenerator; +use ItalyStrap\Empress\ModuleInterface; +use Symfony\Component\EventDispatcher\EventDispatcher; use ItalyStrap\Empress\AurynConfig; use ItalyStrap\Finder\Finder; use ItalyStrap\Finder\FinderFactory; use ItalyStrap\Finder\FinderInterface; use Psr\EventDispatcher\EventDispatcherInterface; -class ModuleInfrastructure implements \ItalyStrap\Empress\ModuleInterface +final class ModuleInfrastructure implements ModuleInterface { /** * @return array @@ -20,11 +22,11 @@ public function __invoke(): array return [ AurynConfig::ALIASES => [ FinderInterface::class => Finder::class, - EventDispatcherInterface::class => \Symfony\Component\EventDispatcher\EventDispatcher::class, + EventDispatcherInterface::class => EventDispatcher::class, ], AurynConfig::SHARING => [ EventDispatcherInterface::class, - \Symfony\Component\EventDispatcher\EventDispatcher::class + EventDispatcher::class ], AurynConfig::FACTORIES => [ Finder::class => static fn (): FinderInterface => (new FinderFactory())->make(), diff --git a/tests/_support/FunctionalTester.php b/tests/_support/FunctionalTester.php index 3ffe4c21..1d759e7c 100644 --- a/tests/_support/FunctionalTester.php +++ b/tests/_support/FunctionalTester.php @@ -2,6 +2,9 @@ declare(strict_types=1); +use Codeception\Actor; +use _generated\FunctionalTesterActions; + /** * Inherited Methods @@ -18,9 +21,9 @@ * * @SuppressWarnings(PHPMD) */ -class FunctionalTester extends \Codeception\Actor +final class FunctionalTester extends Actor { - use _generated\FunctionalTesterActions; + use FunctionalTesterActions; /** * Define custom actions here diff --git a/tests/_support/Helper/Functional.php b/tests/_support/Helper/Functional.php index 6d6d5e23..1ff87bb6 100644 --- a/tests/_support/Helper/Functional.php +++ b/tests/_support/Helper/Functional.php @@ -4,9 +4,10 @@ namespace Helper; +use Codeception\Module; + // here you can define custom actions // all public methods declared in helper class will be available in $I - -class Functional extends \Codeception\Module +final class Functional extends Module { } diff --git a/tests/_support/Helper/Integration.php b/tests/_support/Helper/Integration.php index 5f17c156..a6477ff1 100644 --- a/tests/_support/Helper/Integration.php +++ b/tests/_support/Helper/Integration.php @@ -1,10 +1,14 @@ tester->deleteFile($schemaPath); } + $this->tester->writeToFile($schemaPath, '{}'); $actual = $this->makeInstance(); diff --git a/tests/unit/Domain/Input/Settings/Color/DuotoneTest.php b/tests/unit/Domain/Input/Settings/Color/DuotoneTest.php index 91d1c36a..abb61b36 100644 --- a/tests/unit/Domain/Input/Settings/Color/DuotoneTest.php +++ b/tests/unit/Domain/Input/Settings/Color/DuotoneTest.php @@ -8,7 +8,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Duotone; -class DuotoneTest extends UnitTestCase +final class DuotoneTest extends UnitTestCase { use PresetCommonTrait; diff --git a/tests/unit/Domain/Input/Settings/Color/GradientTest.php b/tests/unit/Domain/Input/Settings/Color/GradientTest.php index a36bf765..b15c195c 100644 --- a/tests/unit/Domain/Input/Settings/Color/GradientTest.php +++ b/tests/unit/Domain/Input/Settings/Color/GradientTest.php @@ -8,7 +8,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Gradient; -class GradientTest extends UnitTestCase +final class GradientTest extends UnitTestCase { use PresetCommonTrait; diff --git a/tests/unit/Domain/Input/Settings/Color/PaletteTest.php b/tests/unit/Domain/Input/Settings/Color/PaletteTest.php index 8fcf7f38..f43580d9 100644 --- a/tests/unit/Domain/Input/Settings/Color/PaletteTest.php +++ b/tests/unit/Domain/Input/Settings/Color/PaletteTest.php @@ -8,7 +8,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Palette; -class PaletteTest extends UnitTestCase +final class PaletteTest extends UnitTestCase { use PresetCommonTrait; diff --git a/tests/unit/Domain/Input/Settings/Color/ShadowTest.php b/tests/unit/Domain/Input/Settings/Color/ShadowTest.php index 0c771133..a98c013b 100644 --- a/tests/unit/Domain/Input/Settings/Color/ShadowTest.php +++ b/tests/unit/Domain/Input/Settings/Color/ShadowTest.php @@ -8,7 +8,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Shadow; -class ShadowTest extends UnitTestCase +final class ShadowTest extends UnitTestCase { use PresetCommonTrait; diff --git a/tests/unit/Domain/Input/Settings/Color/Utilities/AchromaticColorsTest.php b/tests/unit/Domain/Input/Settings/Color/Utilities/AchromaticColorsTest.php index 1c378d55..66f930f5 100644 --- a/tests/unit/Domain/Input/Settings/Color/Utilities/AchromaticColorsTest.php +++ b/tests/unit/Domain/Input/Settings/Color/Utilities/AchromaticColorsTest.php @@ -8,7 +8,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities\AchromaticColorsExperimental; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities\ColorInterface; -class AchromaticColorsTest extends UnitTestCase +final class AchromaticColorsTest extends UnitTestCase { protected function makeInstance(): AchromaticColorsExperimental { diff --git a/tests/unit/Domain/Input/Settings/Color/Utilities/AnalogousColorsTest.php b/tests/unit/Domain/Input/Settings/Color/Utilities/AnalogousColorsTest.php index dfd1baeb..e45ee35a 100644 --- a/tests/unit/Domain/Input/Settings/Color/Utilities/AnalogousColorsTest.php +++ b/tests/unit/Domain/Input/Settings/Color/Utilities/AnalogousColorsTest.php @@ -10,7 +10,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities\ColorInterface; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities\ColorModifier; -class AnalogousColorsTest extends UnitTestCase +final class AnalogousColorsTest extends UnitTestCase { protected function makeInstance(string $color): AnalogousColorsExperimental { diff --git a/tests/unit/Domain/Input/Settings/Color/Utilities/BoxShadowTest.php b/tests/unit/Domain/Input/Settings/Color/Utilities/BoxShadowTest.php index 35f6bc57..4bf68155 100644 --- a/tests/unit/Domain/Input/Settings/Color/Utilities/BoxShadowTest.php +++ b/tests/unit/Domain/Input/Settings/Color/Utilities/BoxShadowTest.php @@ -7,7 +7,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities\BoxShadow; -class BoxShadowTest extends UnitTestCase +final class BoxShadowTest extends UnitTestCase { private function makeInstance(): BoxShadow { diff --git a/tests/unit/Domain/Input/Settings/Color/Utilities/ColorFactoryTest.php b/tests/unit/Domain/Input/Settings/Color/Utilities/ColorFactoryTest.php index 889d46a0..23e0cbbe 100644 --- a/tests/unit/Domain/Input/Settings/Color/Utilities/ColorFactoryTest.php +++ b/tests/unit/Domain/Input/Settings/Color/Utilities/ColorFactoryTest.php @@ -8,7 +8,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities\Color; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities\ColorFactory; -class ColorFactoryTest extends UnitTestCase +final class ColorFactoryTest extends UnitTestCase { protected function makeInstance(): ColorFactory { diff --git a/tests/unit/Domain/Input/Settings/Color/Utilities/ColorModifiertTest.php b/tests/unit/Domain/Input/Settings/Color/Utilities/ColorModifiertTest.php index 7e3222d8..3178550f 100644 --- a/tests/unit/Domain/Input/Settings/Color/Utilities/ColorModifiertTest.php +++ b/tests/unit/Domain/Input/Settings/Color/Utilities/ColorModifiertTest.php @@ -8,7 +8,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities\Color; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities\ColorModifier; -class ColorModifiertTest extends UnitTestCase +final class ColorModifiertTest extends UnitTestCase { protected function makeInstance(string $color): ColorModifier { diff --git a/tests/unit/Domain/Input/Settings/Color/Utilities/ColorTest.php b/tests/unit/Domain/Input/Settings/Color/Utilities/ColorTest.php index 51803146..2edd395b 100644 --- a/tests/unit/Domain/Input/Settings/Color/Utilities/ColorTest.php +++ b/tests/unit/Domain/Input/Settings/Color/Utilities/ColorTest.php @@ -7,7 +7,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities\Color; -class ColorTest extends UnitTestCase +final class ColorTest extends UnitTestCase { protected function makeInstance(string $color): Color { @@ -137,7 +137,7 @@ public static function colorProvider(): \Generator /** * @dataProvider colorProvider */ - public function testItShouldGerRed(string $color, $r, $g, $b): void + public function testItShouldGerRed(string $color, string|int $r, string|int $g, string|int $b): void { $sut = $this->makeInstance($color); @@ -265,30 +265,30 @@ public function testItShouldReturnLuminanceValue(): void { $sut = $this->makeInstance('#ff0000'); - $this->assertSame(0.2126, $sut->luminance(), ''); + $this->assertEqualsWithDelta(0.2126, $sut->luminance(), PHP_FLOAT_EPSILON, ''); } public function testItShouldReturnRelativeLuminanceValue(): void { $sut = $this->makeInstance('#000000'); $color = $this->makeInstance('#ffffff'); - $this->assertSame(21.0, $sut->relativeLuminance($color), ''); + $this->assertEqualsWithDelta(21.0, $sut->relativeLuminance($color), PHP_FLOAT_EPSILON, ''); $sut = $this->makeInstance('#000000'); $color = $this->makeInstance('#bada55'); - $this->assertTrue($sut->relativeLuminance($color) >= 4.5, ''); + $this->assertGreaterThanOrEqual(4.5, $sut->relativeLuminance($color), ''); } public function testConversionToDifferentFormat(): void { $sut = $this->makeInstance('rgba(0,0,0,0.25)'); - $this->assertSame(0.25, $sut->alpha(), ''); + $this->assertEqualsWithDelta(0.25, $sut->alpha(), PHP_FLOAT_EPSILON, ''); $sut = $this->makeInstance('#000000'); $this->assertSame('ff', $sut->alpha(), ''); $sut = $this->makeInstance('hsla(0,0,0,0.25)'); - $this->assertSame(0.25, $sut->alpha(), ''); + $this->assertEqualsWithDelta(0.25, $sut->alpha(), PHP_FLOAT_EPSILON, ''); $this->assertStringMatchesFormat('#000000', (string)$sut->toHex(), ''); $this->assertStringMatchesFormat('rgb(0,0,0)', (string)$sut->toRgb(), ''); diff --git a/tests/unit/Domain/Input/Settings/Color/Utilities/LinearGradientTest.php b/tests/unit/Domain/Input/Settings/Color/Utilities/LinearGradientTest.php index f182aece..a29677ac 100644 --- a/tests/unit/Domain/Input/Settings/Color/Utilities/LinearGradientTest.php +++ b/tests/unit/Domain/Input/Settings/Color/Utilities/LinearGradientTest.php @@ -7,7 +7,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities\LinearGradient; -class LinearGradientTest extends UnitTestCase +final class LinearGradientTest extends UnitTestCase { private function makeInstance(): LinearGradient { diff --git a/tests/unit/Domain/Input/Settings/Color/Utilities/MonochromaticColorsTest.php b/tests/unit/Domain/Input/Settings/Color/Utilities/MonochromaticColorsTest.php index 4aaff065..6c082fae 100644 --- a/tests/unit/Domain/Input/Settings/Color/Utilities/MonochromaticColorsTest.php +++ b/tests/unit/Domain/Input/Settings/Color/Utilities/MonochromaticColorsTest.php @@ -10,7 +10,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities\ColorModifier; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities\MonochromaticColorsExperimental; -class MonochromaticColorsTest extends UnitTestCase +final class MonochromaticColorsTest extends UnitTestCase { protected function makeInstance(ColorInterface $color, array $steps): MonochromaticColorsExperimental { diff --git a/tests/unit/Domain/Input/Settings/CommonTest.php b/tests/unit/Domain/Input/Settings/CommonTest.php index 4f0f79fc..b2e0a0e8 100644 --- a/tests/unit/Domain/Input/Settings/CommonTest.php +++ b/tests/unit/Domain/Input/Settings/CommonTest.php @@ -7,7 +7,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetTrait; -class CommonTest extends UnitTestCase +final class CommonTest extends UnitTestCase { use PresetTrait; diff --git a/tests/unit/Domain/Input/Settings/Custom/CollectionAdapterTest.php b/tests/unit/Domain/Input/Settings/Custom/CollectionAdapterTest.php index 3bc9df88..54c5d729 100644 --- a/tests/unit/Domain/Input/Settings/Custom/CollectionAdapterTest.php +++ b/tests/unit/Domain/Input/Settings/Custom/CollectionAdapterTest.php @@ -7,7 +7,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Custom\CustomToPresets; -class CollectionAdapterTest extends UnitTestCase +final class CollectionAdapterTest extends UnitTestCase { private array $items = []; diff --git a/tests/unit/Domain/Input/Settings/Custom/CustomTest.php b/tests/unit/Domain/Input/Settings/Custom/CustomTest.php index 122446ed..539d3a25 100644 --- a/tests/unit/Domain/Input/Settings/Custom/CustomTest.php +++ b/tests/unit/Domain/Input/Settings/Custom/CustomTest.php @@ -8,7 +8,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Custom\Custom; -class CustomTest extends UnitTestCase +final class CustomTest extends UnitTestCase { use PresetCommonTrait; @@ -23,12 +23,4 @@ private function makeInstance(): Custom $this->name ); } - - public function testSlug() - { - } - - public function testProp() - { - } } diff --git a/tests/unit/Domain/Input/Settings/PresetsIntegrationTest.php b/tests/unit/Domain/Input/Settings/PresetsIntegrationTest.php index a21f835a..b598d88e 100644 --- a/tests/unit/Domain/Input/Settings/PresetsIntegrationTest.php +++ b/tests/unit/Domain/Input/Settings/PresetsIntegrationTest.php @@ -4,6 +4,8 @@ namespace ItalyStrap\Tests\Unit\Domain\Input\Settings; +use FontLib\Font; +use FontLib\TrueType\File; use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Presets; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Palette; @@ -13,7 +15,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Typography\FontSize; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\Typography; -class PresetsIntegrationTest extends UnitTestCase +final class PresetsIntegrationTest extends UnitTestCase { private function makeInstance(): Presets { @@ -266,8 +268,8 @@ public function testFonts(): void $files = \glob(\codecept_data_dir($relativePath . '**/*'), GLOB_BRACE); foreach ($files as $file) { break; - $font = \FontLib\Font::load($file); - if (!$font instanceof \FontLib\TrueType\File) { + $font = Font::load($file); + if (!$font instanceof File) { continue; } @@ -280,7 +282,7 @@ public function testFonts(): void // codecept_debug($font->getFontWeight()); $fontFace[] = [ 'fontFamily' => $font->getFontName(), - 'fontStyle' => \mb_strtolower($font->getFontSubfamily()), + 'fontStyle' => \mb_strtolower((string) $font->getFontSubfamily()), 'fontWeight' => $font->getFontWeight(), 'src' => [ \sprintf( diff --git a/tests/unit/Domain/Input/Settings/PresetsTest.php b/tests/unit/Domain/Input/Settings/PresetsTest.php index 1c8d6ad4..cb52ab4e 100644 --- a/tests/unit/Domain/Input/Settings/PresetsTest.php +++ b/tests/unit/Domain/Input/Settings/PresetsTest.php @@ -6,10 +6,9 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Presets; -use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Palette; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetInterface; -class PresetsTest extends UnitTestCase +final class PresetsTest extends UnitTestCase { private function makeInstance(): Presets { @@ -81,11 +80,8 @@ public function testItShouldBeJsonSerializableByTag(): void private function prepareFakeItem(string $val = ''): PresetInterface { return new class ($val) implements PresetInterface { - private string $val; - - public function __construct(string $val = '') + public function __construct(private readonly string $val = '') { - $this->val = $val; } public function slug(): string diff --git a/tests/unit/Domain/Input/Settings/Typography/FontFamilyTest.php b/tests/unit/Domain/Input/Settings/Typography/FontFamilyTest.php index 4dcc52f9..4fd460b1 100644 --- a/tests/unit/Domain/Input/Settings/Typography/FontFamilyTest.php +++ b/tests/unit/Domain/Input/Settings/Typography/FontFamilyTest.php @@ -8,7 +8,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Typography\FontFamily; -class FontFamilyTest extends UnitTestCase +final class FontFamilyTest extends UnitTestCase { use PresetCommonTrait; diff --git a/tests/unit/Domain/Input/Settings/Typography/FontSizeTest.php b/tests/unit/Domain/Input/Settings/Typography/FontSizeTest.php index f966376c..95db0c5e 100644 --- a/tests/unit/Domain/Input/Settings/Typography/FontSizeTest.php +++ b/tests/unit/Domain/Input/Settings/Typography/FontSizeTest.php @@ -8,7 +8,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Typography\FontSize; -class FontSizeTest extends UnitTestCase +final class FontSizeTest extends UnitTestCase { use PresetCommonTrait; diff --git a/tests/unit/Domain/Input/Styles/BorderTest.php b/tests/unit/Domain/Input/Styles/BorderTest.php index db666374..9a8058e3 100644 --- a/tests/unit/Domain/Input/Styles/BorderTest.php +++ b/tests/unit/Domain/Input/Styles/BorderTest.php @@ -7,7 +7,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\Border; -class BorderTest extends UnitTestCase +final class BorderTest extends UnitTestCase { use CommonTests; diff --git a/tests/unit/Domain/Input/Styles/ColorTest.php b/tests/unit/Domain/Input/Styles/ColorTest.php index 40e309b5..8d162a2a 100644 --- a/tests/unit/Domain/Input/Styles/ColorTest.php +++ b/tests/unit/Domain/Input/Styles/ColorTest.php @@ -7,7 +7,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\Color; -class ColorTest extends UnitTestCase +final class ColorTest extends UnitTestCase { use CommonTests; diff --git a/tests/unit/Domain/Input/Styles/CssTest.php b/tests/unit/Domain/Input/Styles/CssTest.php index 40ccab00..4a7507f5 100644 --- a/tests/unit/Domain/Input/Styles/CssTest.php +++ b/tests/unit/Domain/Input/Styles/CssTest.php @@ -8,10 +8,8 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\Css; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\CssInterface; -use ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\Scss; -use ScssPhp\ScssPhp\Compiler; -class CssTest extends UnitTestCase +final class CssTest extends UnitTestCase { use CssStyleStringProviderTrait { CssStyleStringProviderTrait::styleProvider as styleProviderTrait; diff --git a/tests/unit/Domain/Input/Styles/OnlyCtorPresetsParamTest.php b/tests/unit/Domain/Input/Styles/OnlyCtorPresetsParamTest.php index aa93f3d2..7bf90e74 100644 --- a/tests/unit/Domain/Input/Styles/OnlyCtorPresetsParamTest.php +++ b/tests/unit/Domain/Input/Styles/OnlyCtorPresetsParamTest.php @@ -13,7 +13,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\Spacing; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\Typography; -class OnlyCtorPresetsParamTest extends UnitTestCase +final class OnlyCtorPresetsParamTest extends UnitTestCase { public static function classNameDataProvider(): iterable { @@ -50,7 +50,7 @@ public function testClassesThatNeedPresetsAsParameter(string $class): void \sprintf( "The constructor of %s does not have a parameter named \$preset, found: %s", $class, - \implode(', ', \array_map(fn(\ReflectionParameter $p) => '$' . $p->getName(), $parameters)) + \implode(', ', \array_map(fn(\ReflectionParameter $p): string => '$' . $p->getName(), $parameters)) ) ); } diff --git a/tests/unit/Domain/Input/Styles/OutlineTest.php b/tests/unit/Domain/Input/Styles/OutlineTest.php index 5469284e..be86030f 100644 --- a/tests/unit/Domain/Input/Styles/OutlineTest.php +++ b/tests/unit/Domain/Input/Styles/OutlineTest.php @@ -7,7 +7,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\Outline; -class OutlineTest extends UnitTestCase +final class OutlineTest extends UnitTestCase { use CommonTests; diff --git a/tests/unit/Domain/Input/Styles/ScssTest.php b/tests/unit/Domain/Input/Styles/ScssTest.php index bc90fd9d..7376f6c2 100644 --- a/tests/unit/Domain/Input/Styles/ScssTest.php +++ b/tests/unit/Domain/Input/Styles/ScssTest.php @@ -10,7 +10,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\Scss; use ScssPhp\ScssPhp\Compiler; -class ScssTest extends UnitTestCase +final class ScssTest extends UnitTestCase { use CssStyleStringProviderTrait { CssStyleStringProviderTrait::newStyleProvider as newStyleProviderTrait; diff --git a/tests/unit/Domain/Input/Styles/SpacingTest.php b/tests/unit/Domain/Input/Styles/SpacingTest.php index ad4e591d..bb0db448 100644 --- a/tests/unit/Domain/Input/Styles/SpacingTest.php +++ b/tests/unit/Domain/Input/Styles/SpacingTest.php @@ -7,7 +7,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\Spacing; -class SpacingTest extends UnitTestCase +final class SpacingTest extends UnitTestCase { use CommonTests; @@ -140,7 +140,7 @@ public function testItShouldReturnTheCorrectValue(): void ->bottom('50px') ->left('5rem'); - $this->assertEquals( + $this->assertSame( [ 'top' => '25px', 'right' => '25px', diff --git a/tests/unit/Domain/Input/Styles/TypographyTest.php b/tests/unit/Domain/Input/Styles/TypographyTest.php index f9b8388e..c5c1fff9 100644 --- a/tests/unit/Domain/Input/Styles/TypographyTest.php +++ b/tests/unit/Domain/Input/Styles/TypographyTest.php @@ -7,7 +7,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\Typography; -class TypographyTest extends UnitTestCase +final class TypographyTest extends UnitTestCase { use CommonTests; diff --git a/tests/unit/Domain/Output/DumpTest.php b/tests/unit/Domain/Output/DumpTest.php index ef235445..efb4b6fb 100644 --- a/tests/unit/Domain/Output/DumpTest.php +++ b/tests/unit/Domain/Output/DumpTest.php @@ -11,7 +11,7 @@ use ItalyStrap\ThemeJsonGenerator\Infrastructure\Container\ThemeJsonContainerFactory; use Prophecy\Argument; -class DumpTest extends UnitTestCase +final class DumpTest extends UnitTestCase { private function makeInstance(): Dump { diff --git a/tests/unit/Domain/Output/InitTest.php b/tests/unit/Domain/Output/InitTest.php index 10ea58c8..ed13cbf5 100644 --- a/tests/unit/Domain/Output/InitTest.php +++ b/tests/unit/Domain/Output/InitTest.php @@ -10,7 +10,7 @@ use ItalyStrap\ThemeJsonGenerator\Application\Middlewares\Init; use Prophecy\Argument; -class InitTest extends UnitTestCase +final class InitTest extends UnitTestCase { private function makeInstance(): Init { diff --git a/tests/unit/Domain/Output/ValidateTest.php b/tests/unit/Domain/Output/ValidateTest.php index f1edabd7..1cf8d4f8 100644 --- a/tests/unit/Domain/Output/ValidateTest.php +++ b/tests/unit/Domain/Output/ValidateTest.php @@ -10,7 +10,7 @@ use ItalyStrap\ThemeJsonGenerator\Application\ValidateMessage; use Prophecy\Argument; -class ValidateTest extends UnitTestCase +final class ValidateTest extends UnitTestCase { private function makeInstance(): Validate { diff --git a/tests/unit/Infrastructure/Filesystem/FilesFinderIntegrationTest.php b/tests/unit/Infrastructure/Filesystem/FilesFinderIntegrationTest.php index 61cfaa22..b0faf6ac 100644 --- a/tests/unit/Infrastructure/Filesystem/FilesFinderIntegrationTest.php +++ b/tests/unit/Infrastructure/Filesystem/FilesFinderIntegrationTest.php @@ -8,7 +8,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem\FilesFinder; -class FilesFinderIntegrationTest extends UnitTestCase +final class FilesFinderIntegrationTest extends UnitTestCase { private function makeInstance(): FilesFinder { diff --git a/tests/unit/Infrastructure/Filesystem/JsonFileWriterIntegrationTest.php b/tests/unit/Infrastructure/Filesystem/JsonFileWriterIntegrationTest.php index c42c0eaf..2f1f7d76 100644 --- a/tests/unit/Infrastructure/Filesystem/JsonFileWriterIntegrationTest.php +++ b/tests/unit/Infrastructure/Filesystem/JsonFileWriterIntegrationTest.php @@ -14,7 +14,7 @@ use ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\Typography; use ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem\JsonFileWriter; -class JsonFileWriterIntegrationTest extends UnitTestCase +final class JsonFileWriterIntegrationTest extends UnitTestCase { public const COLOR_HEADING_TEXT = Palette::TYPE . '.headingColor'; @@ -30,7 +30,7 @@ class JsonFileWriterIntegrationTest extends UnitTestCase private ?\ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\Color $colorIntegration = null; - private ?\ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\Typography $typographyIntegration = null; + private ?Typography $typographyIntegration = null; protected function makeInstance(): JsonFileWriter { diff --git a/tests/unit/Infrastructure/Filesystem/JsonFileWriterTest.php b/tests/unit/Infrastructure/Filesystem/JsonFileWriterTest.php index b694455a..bb41738b 100644 --- a/tests/unit/Infrastructure/Filesystem/JsonFileWriterTest.php +++ b/tests/unit/Infrastructure/Filesystem/JsonFileWriterTest.php @@ -8,7 +8,7 @@ use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson; use ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem\JsonFileWriter; -class JsonFileWriterTest extends UnitTestCase +final class JsonFileWriterTest extends UnitTestCase { private string $theme_json_path; diff --git a/tests/unit/Infrastructure/Filesystem/SassFileWriterTest.php b/tests/unit/Infrastructure/Filesystem/SassFileWriterTest.php index 12f0b1f8..0aed521a 100644 --- a/tests/unit/Infrastructure/Filesystem/SassFileWriterTest.php +++ b/tests/unit/Infrastructure/Filesystem/SassFileWriterTest.php @@ -8,7 +8,7 @@ use ItalyStrap\Tests\UnitTestCase; use ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem\ScssFileWriter; -class SassFileWriterTest extends UnitTestCase +final class SassFileWriterTest extends UnitTestCase { /** * @var string diff --git a/tests/unit/bootstrap.php b/tests/unit/bootstrap.php new file mode 100644 index 00000000..8bc0c325 --- /dev/null +++ b/tests/unit/bootstrap.php @@ -0,0 +1,9 @@ +