diff --git a/.docker/.env b/.docker/.env
index b1cbae62..8bbb1634 100644
--- a/.docker/.env
+++ b/.docker/.env
@@ -1,7 +1,7 @@
# Docker only
PROJECT_NAME="theme-json-generator"
-PHP_VERSION="7.4"
-WP_VERSION="6.0"
+PHP_VERSION="8.2"
+WP_VERSION="6"
WP_PORT=8888
DB_PORT=8889
diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml
index d76891fa..4ef25bf5 100644
--- a/.docker/docker-compose.yml
+++ b/.docker/docker-compose.yml
@@ -21,7 +21,8 @@ services:
- ../tests/_output/:/var/www/html/wp-content/plugins/${PROJECT_NAME:-wordpress}/tests/_output/
- ./mu-plugins/:/var/www/html/wp-content/mu-plugins/
depends_on:
- - mysql
+ mysql:
+ condition: service_healthy
networks:
integration_test_networks:
@@ -37,12 +38,18 @@ services:
MYSQL_PASSWORD: ${DB_PASSWORD:-root}
#MYSQL_RANDOM_ROOT_PASSWORD: '1'
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-root}
+ healthcheck:
+ test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-p${DB_PASSWORD:-root}"]
+ interval: 5s
+ timeout: 5s
+ retries: 30
networks:
- integration_test_networks
phpmyadmin:
depends_on:
- - mysql
+ mysql:
+ condition: service_healthy
image: phpmyadmin/phpmyadmin:${PMA_VERSION:-latest}
container_name: ${PROJECT_NAME}_phpmyadmin_test
restart: always
diff --git a/.docker/wordpress/Dockerfile b/.docker/wordpress/Dockerfile
index f2014b35..4e5757ed 100644
--- a/.docker/wordpress/Dockerfile
+++ b/.docker/wordpress/Dockerfile
@@ -21,7 +21,10 @@ RUN set -eux; \
apt-get update && apt-get install -y \
git \
nano \
- less # Needed for the WP-CLI \
+ less \
+ unzip \
+ zip \
+ ; \
rm -rf /var/lib/apt/lists/*
# Git add safe directory for the working directory
@@ -32,7 +35,9 @@ RUN set -eux; \
RUN docker-php-ext-install \
pdo_mysql
-COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
+RUN curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php && \
+ php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer && \
+ rm /tmp/composer-setup.php
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \
chmod +x wp-cli.phar && \
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 6e39329a..cd0ae64a 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -18,12 +18,12 @@ jobs:
steps:
- name: Checkout
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
- php-version: '7.4'
+ php-version: '8.2'
- name: Validate composer.json and composer.lock
run: composer validate --strict
@@ -31,7 +31,7 @@ jobs:
- name: Validate php files
run: find ./src/ ./tests/ -type f -name '*.php' -print0 | xargs -0 -L 1 -P 4 -- php -l
- - uses: ramsey/composer-install@v2
+ - uses: ramsey/composer-install@v3
- name: Coding standard
- run: composer run cs
\ No newline at end of file
+ run: composer run cs
diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml
index fe814ae9..69c9e843 100644
--- a/.github/workflows/static-analysis.yml
+++ b/.github/workflows/static-analysis.yml
@@ -6,7 +6,7 @@ on:
paths:
- '**workflows/static-analysis.yml'
- '**.php'
- - '**psalm.xml'
+ - '**phpstan.neon'
- '**composer.json'
jobs:
@@ -18,14 +18,14 @@ jobs:
steps:
- name: Checkout
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
- php-version: 7.4
+ php-version: '8.2'
- - uses: ramsey/composer-install@v2
+ - uses: ramsey/composer-install@v3
- - name: Psalm
- run: vendor/bin/psalm
\ No newline at end of file
+ - name: PHPStan
+ run: composer stan
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 98a08e26..47244e27 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -1,8 +1,8 @@
-name: CI
+name: Test
env:
PROJECT_KIND: plugins
- DB_HOST: localhost
+ DB_HOST: 127.0.0.1
DB_NAME: test
DB_USER: root
DB_PASSWORD: root
@@ -28,19 +28,18 @@ on:
jobs:
tests:
- name: 🐘 Tests on PHP ${{matrix.php_versions}} & APP version ${{matrix.app_versions}}
+ name: Tests on PHP ${{ matrix.php_versions }} & WordPress ${{ matrix.app_versions }}
strategy:
matrix:
- php_versions: ['7.4', '8.0']
- app_versions: ['6.0']
+ php_versions: ['8.2']
+ app_versions: ['6.9']
runs-on: ubuntu-latest
- continue-on-error: ${{ matrix.php_versions == '8.0' }}
if: "!contains(github.event.head_commit.message, '--skip ci') && !github.event.pull_request.draft"
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
@@ -74,7 +73,7 @@ jobs:
pwd
ls -la ${{env.APP_FOLDER_PATH}}/wp-includes
- - uses: "ramsey/composer-install@v2"
+ - uses: "ramsey/composer-install@v3"
with:
working-directory: "${{env.APP_FOLDER_PATH}}/wp-content/${{env.PROJECT_KIND}}/${{ github.event.repository.name }}"
@@ -92,6 +91,10 @@ jobs:
- name: Verify MySQL is Running
run: sudo systemctl status mysql.service
+ - name: Configure Codeception database host
+ working-directory: ${{env.APP_FOLDER_PATH}}/wp-content/${{env.PROJECT_KIND}}/${{ github.event.repository.name }}
+ run: sed -i 's/DB_HOST="mysql"/DB_HOST="${{ env.DB_HOST }}"/' tests/.env
+
- name: Build codeception
working-directory: ${{env.APP_FOLDER_PATH}}/wp-content/${{env.PROJECT_KIND}}/${{ github.event.repository.name }}
run: ./vendor/bin/codecept build
diff --git a/Makefile b/Makefile
index 4ee3e968..21dfe3a9 100644
--- a/Makefile
+++ b/Makefile
@@ -94,12 +94,12 @@ cs/fix: up ### Run the code sniffer and fix the errors
@$(DOCKER_DIR) ./composer cs:fix
@$(FILES_OWNERSHIP)
-# Psalm commands
-
-.PHONY: psalm
-psalm: up ### Run the psalm
- @echo "Running the psalm"
- @$(DOCKER_DIR) ./composer psalm
+# PHPStan commands
+
+.PHONY: stan
+stan: up ### Run PHPStan
+ @echo "Running PHPStan"
+ @$(DOCKER_DIR) ./composer stan
# Codeception commands
@@ -137,8 +137,8 @@ acceptance: up ### Run the acceptance tests
.PHONY: tests
tests: unit integration functional ### Run unit and integration tests
-.PHONY: qa
-qa: cs psalm unit integration functional ### Run all the tests
+.PHONY: qa
+qa: cs stan unit integration functional ### Run all the tests
# Infection commands
@@ -180,9 +180,9 @@ docker/metrics: ### Run the phpmetrics
# PhpMetrics commands from composer
.PHONY: metrics
-metrics: up ### Run the composer/metrics
- @echo "Running the psalm"
- @$(DOCKER_DIR) ./composer metrics
+metrics: up ### Run the composer/metrics
+ @echo "Running phpmetrics"
+ @$(DOCKER_DIR) ./composer metrics
# Generate commands
diff --git a/README.md b/README.md
index 3cb33ca2..5c04432d 100644
--- a/README.md
+++ b/README.md
@@ -63,6 +63,8 @@ This package adheres to the [SemVer](http://semver.org/) specification and will
Until the first stable version is released, BC breaks may occur.
+`ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson` to `\ItalyStrap\ThemeJsonGenerator\Domain\ThemeJson\ThemeJson`
+
[🆙](#table-of-contents)
## Contributing
diff --git a/bin/theme-json.php b/bin/theme-json.php
index e8e3389f..4a87ccb6 100644
--- a/bin/theme-json.php
+++ b/bin/theme-json.php
@@ -8,7 +8,6 @@
namespace ItalyStrap\ThemeJsonGenerator;
-/** @psalm-suppress UnresolvableInclude */
require $_composer_autoload_path ?? __DIR__ . '/../vendor/autoload.php';
$bootstrap = new Bootstrap();
diff --git a/bus/Bus.php b/bus/Bus.php
deleted file mode 100644
index ca48418a..00000000
--- a/bus/Bus.php
+++ /dev/null
@@ -1,45 +0,0 @@
-handler = $handler;
- }
-
- public function addMiddleware(MiddlewareInterface ...$middleware): void
- {
- $this->middleware = \array_merge($this->middleware, $middleware);
- }
-
- public function handle(object $message)
- {
- if ($this->middleware === []) {
- return $this->handler->handle($message);
- }
-
- /** @var MiddlewareInterface $middleware */
- $middleware = array_shift($this->middleware);
- return $middleware->process($message, $this);
- }
-}
diff --git a/bus/DecorateBus.php b/bus/DecorateBus.php
deleted file mode 100644
index caa98410..00000000
--- a/bus/DecorateBus.php
+++ /dev/null
@@ -1,25 +0,0 @@
-middleware = $middleware;
- $this->nextHandler = $nextHandler;
- }
-
- public function handle(object $message)
- {
- return $this->middleware->process($message, $this->nextHandler);
- }
-}
diff --git a/bus/HandlerInterface.php b/bus/HandlerInterface.php
deleted file mode 100644
index db84c8fe..00000000
--- a/bus/HandlerInterface.php
+++ /dev/null
@@ -1,13 +0,0 @@
-=7.4",
+ "php" : ">=8.2",
"ext-json": "*",
"italystrap/config": "^2.4",
- "italystrap/empress": "^2.0",
+ "italystrap/empress": "dev-modularized as 2.0.x-dev",
"italystrap/finder": "dev-master",
+ "italystrap/pipeline": "dev-main",
"mexitek/phpcolors": "^1.0",
"spatie/color": "~1.5.0",
@@ -36,24 +37,25 @@
"symfony/process": "^v5.4",
"symfony/polyfill-php80": "^1.22",
"symfony/event-dispatcher": "^5.4",
- "webmozart/assert": "^1.11"
+ "webmozart/assert": "^1.11",
+ "overclokk/auryn": "dev-master"
},
"require-dev": {
- "lucatume/wp-browser": "<3.5",
+ "lucatume/wp-browser": "^4.5",
"phpspec/prophecy-phpunit": "^2.0",
- "codeception/module-asserts": "^1.0",
- "codeception/module-phpbrowser": "^1.0",
- "codeception/module-db": "^1.0",
- "codeception/module-filesystem": "^1.0",
- "codeception/module-cli": "^1.0",
+ "codeception/module-asserts": "^3.0",
+ "codeception/module-phpbrowser": "^3.0",
+ "codeception/module-db": "^3.0",
+ "codeception/module-filesystem": "^3.0",
+ "codeception/module-cli": "^2.0",
"codeception/util-universalframework": "^1.0",
"squizlabs/php_codesniffer": "*",
"phpcompatibility/php-compatibility": "*",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
- "vimeo/psalm": "^5.6",
+ "phpstan/phpstan": "^1.12",
"phpbench/phpbench": "^1.2",
"phpmetrics/phpmetrics": "^2.8",
@@ -68,7 +70,6 @@
},
"autoload": {
"psr-4": {
- "ItalyStrap\\Bus\\": "bus/",
"ItalyStrap\\ThemeJsonGenerator\\": "src/"
},
"files": [
@@ -96,8 +97,8 @@
"cs:fix": [
"@php ./vendor/bin/phpcbf -p"
],
- "psalm": [
- "@php ./vendor/bin/psalm --no-cache"
+ "stan": [
+ "@php ./vendor/bin/phpstan analyse --debug --no-progress"
],
"unit": [
"@php ./vendor/bin/codecept run unit"
@@ -124,7 +125,7 @@
],
"qa": [
"@cs",
- "@psalm",
+ "@stan",
"@rector",
"@unit"
],
@@ -144,7 +145,7 @@
"scripts-descriptions": {
"cs": "Run Code Sniffer",
"cs:fix": "Run Code Sniffer and fix errors",
- "psalm": "Run Psalm",
+ "stan": "Run PHPStan",
"unit": "Run Unit tests",
"integration": "Run Integration tests",
"infection": "Run Infection",
diff --git a/docs/01-basic-usage.md b/docs/01-basic-usage.md
index 96978d3c..aee2b396 100644
--- a/docs/01-basic-usage.md
+++ b/docs/01-basic-usage.md
@@ -213,7 +213,7 @@ declare(strict_types=1);
namespace YourVendor\YourProject;
-use ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson;
+use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson;
return static function (ThemeJson $themeJson): void {
// Your configuration code goes here
@@ -229,7 +229,7 @@ declare(strict_types=1);
namespace YourVendor\YourProject;
-use ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson;
+use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson;
return static function (ThemeJson $themeJson): void {
$themeJson->merge([
@@ -248,9 +248,7 @@ declare(strict_types=1);
namespace YourVendor\YourProject;
-use ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson;
-use ItalyStrap\ThemeJsonGenerator\Domain\Input\SectionNames;
-use Psr\Container\ContainerInterface;
+use ItalyStrap\ThemeJsonGenerator\Api\SectionNames;use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson;
return static function (ThemeJson $themeJson): void {
$themeJson->merge([
diff --git a/docs/02-advanced-usage.md b/docs/02-advanced-usage.md
index 58ccda5d..528bf277 100644
--- a/docs/02-advanced-usage.md
+++ b/docs/02-advanced-usage.md
@@ -43,8 +43,7 @@ declare(strict_types=1);
namespace YourVendor\YourProject;
-use ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson;
-use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Presets;
+use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson;use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Presets;
return static function (ThemeJson $themeJson, Presets $presets): void {
// ...
@@ -297,9 +296,7 @@ declare(strict_types=1);
namespace YourVendor\YourProject;
-use ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson;
-use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Presets;
-use Psr\Container\ContainerInterface;
+use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson;use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Presets;use Psr\Container\ContainerInterface;
return static function (ThemeJson $themeJson, Presets $presets, ContainerInterface $container): void {
// ...
@@ -444,8 +441,7 @@ declare(strict_types=1);
namespace YourVendor\YourProject;
-use ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson;
-use Psr\Container\ContainerInterface;
+use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson;use Psr\Container\ContainerInterface;
return static function (ThemeJson $themeJson, ContainerInterface $container): void {
// Utilize the $themeJson and $container for your configuration
@@ -465,8 +461,7 @@ declare(strict_types=1);
namespace YourVendor\YourProject;
-use ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson;
-use Psr\Container\ContainerInterface;
+use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson;use Psr\Container\ContainerInterface;
return static function (ThemeJson $themeJson, ContainerInterface $container): void {
/** @var SomeService $someService */
diff --git a/docs/todo.md b/docs/todo.md
index 8fbf84a3..2b5af7d1 100644
--- a/docs/todo.md
+++ b/docs/todo.md
@@ -160,9 +160,7 @@ declare(strict_types=1);
namespace YourVendor\YourProject;
-use ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson;
-use ItalyStrap\ThemeJsonGenerator\Domain\Input\SectionNames;
-use Psr\Container\ContainerInterface;
+use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson;
return static function (ThemeJson $themeJson, PresetsInterface $presets): void {
diff --git a/ecs.php b/ecs.php
index c60bea93..97f4ca27 100644
--- a/ecs.php
+++ b/ecs.php
@@ -12,7 +12,6 @@
return function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
- __DIR__ . '/bus',
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__ . '/functions',
diff --git a/namespace-bc-aliases.php b/namespace-bc-aliases.php
index 020cec11..174d7fd7 100644
--- a/namespace-bc-aliases.php
+++ b/namespace-bc-aliases.php
@@ -1,23 +1,3 @@
-
+
./bin/
- ./bus/
./functions/
./src/
./tests/
diff --git a/phpstan.neon b/phpstan.neon
new file mode 100644
index 00000000..85808fdd
--- /dev/null
+++ b/phpstan.neon
@@ -0,0 +1,13 @@
+parameters:
+ level: 9
+ paths:
+ - bin
+ - functions
+ - src
+ stubFiles:
+ - stubs/auryn-injector.stub
+ excludePaths:
+ analyse:
+ - src/**/*Experimental*.php
+ parallel:
+ maximumNumberOfProcesses: 1
diff --git a/psalm.xml b/psalm.xml
deleted file mode 100644
index 955e3ecb..00000000
--- a/psalm.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Domain/Input/SectionNames.php b/src/Api/SectionNames.php
similarity index 90%
rename from src/Domain/Input/SectionNames.php
rename to src/Api/SectionNames.php
index 884a05e3..7ce2a01c 100644
--- a/src/Domain/Input/SectionNames.php
+++ b/src/Api/SectionNames.php
@@ -2,11 +2,8 @@
declare(strict_types=1);
-namespace ItalyStrap\ThemeJsonGenerator\Domain\Input;
+namespace ItalyStrap\ThemeJsonGenerator\Api;
-/**
- * @psalm-api
- */
final class SectionNames
{
/**
diff --git a/src/Application/Config/ThemeJson.php b/src/Api/ThemeJson.php
similarity index 90%
rename from src/Application/Config/ThemeJson.php
rename to src/Api/ThemeJson.php
index 0b07dc4d..d3093d10 100644
--- a/src/Application/Config/ThemeJson.php
+++ b/src/Api/ThemeJson.php
@@ -2,25 +2,22 @@
declare(strict_types=1);
-namespace ItalyStrap\ThemeJsonGenerator\Application\Config;
+namespace ItalyStrap\ThemeJsonGenerator\Api;
use ItalyStrap\Config\Config;
-use ItalyStrap\ThemeJsonGenerator\Domain\Input\SectionNames;
-use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Shadow;
-use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetsInterface;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Duotone;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Gradient;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Palette;
+use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Shadow;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Custom\Custom;
+use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetsInterface;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Typography\FontFamily;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Typography\FontSize;
/**
- * @psalm-api
* @template TKey as array-key
* @template TValue
* @template-extends Config
- * @psalm-suppress DeprecatedInterface
*/
final class ThemeJson extends Config implements \JsonSerializable
{
@@ -35,16 +32,25 @@ public function appendGlobalCss(string $css): bool
return $this->set(SectionNames::STYLES . '.css', $currentCss . $css);
}
+ /**
+ * @param array $config
+ */
public function setElementStyle(string $elementName, array $config): bool
{
return $this->set(SectionNames::STYLES . '.elements.' . $elementName, $config);
}
+ /**
+ * @param array $config
+ */
public function setBlockSettings(string $blockName, array $config): bool
{
return $this->set(SectionNames::SETTINGS . '.blocks.' . $blockName, $config);
}
+ /**
+ * @param array $config
+ */
public function setBlockStyle(string $blockName, array $config): bool
{
return $this->set(SectionNames::STYLES . '.blocks.' . $blockName, $config);
@@ -69,7 +75,6 @@ public function setPresets(PresetsInterface $presets): bool
foreach ($keys as $key => $value) {
try {
- /** @psalm-suppress UndefinedInterfaceMethod */
$this->set($key, $presets->toArrayByCategory($value));
} catch (\Exception $e) {
continue;
@@ -79,6 +84,9 @@ public function setPresets(PresetsInterface $presets): bool
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 8f3e376d..e8cae02c 100644
--- a/src/Application/Commands/DumpCommand.php
+++ b/src/Application/Commands/DumpCommand.php
@@ -6,19 +6,15 @@
use ItalyStrap\ThemeJsonGenerator\Application\Commands\Utils\RootFolderTrait;
use ItalyStrap\ThemeJsonGenerator\Application\DumpMessage;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Dump;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\GeneratedFile;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\GeneratingFile;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\NoFileFound;
+use ItalyStrap\ThemeJsonGenerator\Infrastructure\Handler\ConsoleHandler;
+use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;
-/**
- * @psalm-api
- */
+#[AsCommand(name: DumpCommand::NAME, description: DumpCommand::DESCRIPTION)]
final class DumpCommand extends Command
{
use RootFolderTrait;
@@ -28,6 +24,8 @@ final class DumpCommand extends Command
*/
public const NAME = 'dump';
+ public const DESCRIPTION = 'Generate theme.json file';
+
/**
* @var string
*/
@@ -48,23 +46,19 @@ final class DumpCommand extends Command
*/
public const FILE = 'file';
- private Dump $dump;
-
- private \Symfony\Component\EventDispatcher\EventDispatcher $subscriber;
+ private ConsoleHandler $handler;
public function __construct(
- \Symfony\Component\EventDispatcher\EventDispatcher $subscriber,
- Dump $dump
+ ConsoleHandler $handler
) {
- $this->subscriber = $subscriber;
- $this->dump = $dump;
+ $this->handler = $handler;
parent::__construct();
}
protected function configure(): void
{
$this->setName(self::NAME);
- $this->setDescription('Generate theme.json file');
+ $this->setDescription(self::DESCRIPTION);
$this->setHelp('This command generate theme.json file');
$this->addOption(
@@ -119,56 +113,34 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
+ $path = $input->getOption('path');
+ $file = $input->getOption(self::FILE);
- $this->subscriber->addListener(
- GeneratingFile::class,
- static function (GeneratingFile $event) use ($output): void {
- $output->writeln(\sprintf(
- 'Generating %s file',
- $event->getFileName()
- ));
- }
- );
-
- $this->subscriber->addListener(
- GeneratedFile ::class,
- static function (GeneratedFile $event) use ($output): void {
- $output->writeln(\sprintf(
- 'Generated %s file',
- $event->getFileName()
- ));
- $output->writeln('========================');
- }
- );
-
- $this->subscriber->addListener(
- NoFileFound::class,
- /** @psalm-suppress UnusedClosureParam */
- static function (NoFileFound $event) use ($output): void {
- $output->writeln(NoFileFound::M_NO_FILE_FOUND);
- }
- );
-
- $rootFolder = $this->rootFolder((string)$input->getOption('path'));
+ $rootFolder = $this->rootFolder(\is_string($path) ? $path : '');
$message = new DumpMessage(
$rootFolder,
'',
- (bool)$input->getOption('dry-run'),
- (string)$input->getOption(self::FILE)
+ $input->getOption('dry-run') === true,
+ \is_string($file) ? $file : ''
);
- $this->dump->handle($message);
-
- if ($input->getOption(ValidateCommand::NAME)) {
- $process = new Process(['php', 'vendor/bin/theme-json', ValidateCommand::NAME]);
- $process->run();
-
- $output->write($process->getOutput());
-
- return (int)$process->getExitCode();
+ try {
+ return $this->handler->handle($message);
+ } catch (\Exception $exception) {
+ $output->writeln('Error: ' . $exception->getMessage() . '');
+ return Command::FAILURE;
}
- return Command::SUCCESS;
+// if ($input->getOption(ValidateCommand::NAME)) {
+// $process = new Process(['php', 'vendor/bin/theme-json', ValidateCommand::NAME]);
+// $process->run();
+//
+// $output->write($process->getOutput());
+//
+// return (int)$process->getExitCode();
+// }
+
+// return Command::SUCCESS;
}
}
diff --git a/src/Application/Commands/InfoCommand.php b/src/Application/Commands/InfoCommand.php
index dd1b6a09..1a9e3a69 100644
--- a/src/Application/Commands/InfoCommand.php
+++ b/src/Application/Commands/InfoCommand.php
@@ -5,24 +5,25 @@
namespace ItalyStrap\ThemeJsonGenerator\Application\Commands;
use ItalyStrap\ThemeJsonGenerator\Application\Commands\Utils\RootFolderTrait;
-use ItalyStrap\ThemeJsonGenerator\Application\InfoMessage;
+use ItalyStrap\ThemeJsonGenerator\Application\Message;
+use ItalyStrap\ThemeJsonGenerator\Infrastructure\Handler\ConsoleHandler;
+use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-/**
- * @psalm-api
- */
+#[AsCommand(name: InfoCommand::NAME, description: InfoCommand::DESCRIPTION)]
class InfoCommand extends Command
{
use RootFolderTrait;
public const NAME = 'info';
+ public const DESCRIPTION = 'Show info about JSON theme';
- private \ItalyStrap\Bus\HandlerInterface $handler;
+ private ConsoleHandler $handler;
public function __construct(
- \ItalyStrap\Bus\HandlerInterface $handler
+ ConsoleHandler $handler
) {
$this->handler = $handler;
parent::__construct();
@@ -31,17 +32,17 @@ public function __construct(
protected function configure(): void
{
$this->setName(self::NAME);
- $this->setDescription('Show info about JSON theme');
+ $this->setDescription(self::DESCRIPTION);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$rootFolder = $this->rootFolder();
- $message = new InfoMessage($rootFolder);
+ $message = new Message($rootFolder);
try {
- return (int)$this->handler->handle($message);
+ return $this->handler->handle($message);
} catch (\Exception $exception) {
$output->writeln('Error: ' . $exception->getMessage() . '');
return Command::FAILURE;
diff --git a/src/Application/Commands/InitCommand.php b/src/Application/Commands/InitCommand.php
index db36fac9..3cd494bd 100644
--- a/src/Application/Commands/InitCommand.php
+++ b/src/Application/Commands/InitCommand.php
@@ -4,20 +4,16 @@
namespace ItalyStrap\ThemeJsonGenerator\Application\Commands;
-use ItalyStrap\ThemeJsonGenerator\Application\Commands\Utils\DataFromJsonTrait;
use ItalyStrap\ThemeJsonGenerator\Application\Commands\Utils\RootFolderTrait;
-use ItalyStrap\ThemeJsonGenerator\Application\InitMessage;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\EntryPointCanNotBeCreated;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\EntryPointCreated;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\EntryPointDoesNotExist;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Init;
+use ItalyStrap\ThemeJsonGenerator\Application\Message;
+use ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem\DataFromJsonTrait;
+use ItalyStrap\ThemeJsonGenerator\Infrastructure\Handler\ConsoleHandler;
+use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-/**
- * @psalm-api
- */
+#[AsCommand(name: InitCommand::NAME, description: InitCommand::DESCRIPTION)]
class InitCommand extends Command
{
use RootFolderTrait;
@@ -25,23 +21,21 @@ class InitCommand extends Command
public const NAME = 'init';
- private Init $init;
+ public const DESCRIPTION = 'Initialize theme.json file';
- private \Symfony\Component\EventDispatcher\EventDispatcher $subscriber;
+ private ConsoleHandler $handler;
public function __construct(
- \Symfony\Component\EventDispatcher\EventDispatcher $subscriber,
- Init $init
+ ConsoleHandler $handler,
) {
- $this->subscriber = $subscriber;
- $this->init = $init;
+ $this->handler = $handler;
parent::__construct();
}
protected function configure(): void
{
$this->setName(self::NAME);
- $this->setDescription('Initialize theme.json file');
+ $this->setDescription(self::DESCRIPTION);
$this->addOption(
'styles',
@@ -55,45 +49,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$rootFolder = $this->rootFolder();
- $this->subscriber->addListener(
- EntryPointDoesNotExist::class,
- static function (EntryPointDoesNotExist $event) use ($output): void {
- $output->writeln(\sprintf(
- 'Entry file does not exist, creating %s file',
- $event->getFile()
- ));
- }
- );
-
- $this->subscriber->addListener(
- EntryPointCreated::class,
- static function (EntryPointCreated $event) use ($output): void {
- $output->writeln(\sprintf(
- 'Entry file %s created',
- $event->getFile()
- ));
- }
- );
-
- $this->subscriber->addListener(
- EntryPointCanNotBeCreated::class,
- static function (EntryPointCanNotBeCreated $event) use ($output): void {
- $output->writeln(\sprintf(
- 'Entry file %s cannot be created because of %s',
- $event->getFile(),
- $event->getException()->getMessage()
- ));
- }
- );
-
- $message = new InitMessage($rootFolder, (string)$input->getOption('styles'));
+ $message = new Message($rootFolder);
- if ($message->getStyleOption() !== '') {
- throw new \RuntimeException('The option --styles is not yet implemented');
+ try {
+ return $this->handler->handle($message);
+ } catch (\Exception $exception) {
+ $output->writeln('Error: ' . $exception->getMessage() . '');
+ return Command::FAILURE;
}
-
- $this->init->handle($message);
-
- return Command::SUCCESS;
}
}
diff --git a/src/Application/Commands/Middleware/DeleteSchemaJsonMiddleware.php b/src/Application/Commands/Middleware/DeleteSchemaJsonMiddleware.php
deleted file mode 100644
index a0995f47..00000000
--- a/src/Application/Commands/Middleware/DeleteSchemaJsonMiddleware.php
+++ /dev/null
@@ -1,22 +0,0 @@
-getSchemaPath();
- if ($message->shouldRecreate() && \file_exists($schemaPath)) {
- \unlink($schemaPath);
- }
-
- return (int)$handler->handle($message);
- }
-}
diff --git a/src/Application/Commands/Utils/RootFolderTrait.php b/src/Application/Commands/Utils/RootFolderTrait.php
index 45d13bcd..91cce765 100644
--- a/src/Application/Commands/Utils/RootFolderTrait.php
+++ b/src/Application/Commands/Utils/RootFolderTrait.php
@@ -4,6 +4,9 @@
namespace ItalyStrap\ThemeJsonGenerator\Application\Commands\Utils;
+/**
+ * TODO: Move this logic into Infrastructure Filesystem layer
+ */
trait RootFolderTrait
{
private function rootFolder(string $path = ''): string
diff --git a/src/Application/Commands/ValidateCommand.php b/src/Application/Commands/ValidateCommand.php
index dd854058..9a5fadd9 100644
--- a/src/Application/Commands/ValidateCommand.php
+++ b/src/Application/Commands/ValidateCommand.php
@@ -4,36 +4,29 @@
namespace ItalyStrap\ThemeJsonGenerator\Application\Commands;
-use ItalyStrap\ThemeJsonGenerator\Application\Commands\Utils\DataFromJsonTrait;
use ItalyStrap\ThemeJsonGenerator\Application\Commands\Utils\RootFolderTrait;
use ItalyStrap\ThemeJsonGenerator\Application\ValidateMessage;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\ValidatedFails;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\ValidatingFile;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\ValidFile;
+use ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem\DataFromJsonTrait;
+use ItalyStrap\ThemeJsonGenerator\Infrastructure\Handler\ConsoleHandler;
+use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-/**
- * @psalm-api
- */
+#[AsCommand(name: ValidateCommand::NAME, description: ValidateCommand::DESCRIPTION)]
class ValidateCommand extends Command
{
use RootFolderTrait;
use DataFromJsonTrait;
public const NAME = 'validate';
-
- private \Symfony\Component\EventDispatcher\EventDispatcher $subscriber;
-
- private \ItalyStrap\Bus\HandlerInterface $handler;
+ public const DESCRIPTION = 'Validate theme.json file';
+ private ConsoleHandler $handler;
public function __construct(
- \Symfony\Component\EventDispatcher\EventDispatcher $subscriber,
- \ItalyStrap\Bus\HandlerInterface $handler
+ ConsoleHandler $handler
) {
- $this->subscriber = $subscriber;
$this->handler = $handler;
parent::__construct();
}
@@ -41,7 +34,7 @@ public function __construct(
protected function configure(): void
{
$this->setName(self::NAME);
- $this->setDescription('Validate theme.json file');
+ $this->setDescription(self::DESCRIPTION);
$this->addOption(
'force',
@@ -59,48 +52,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$rootFolder = $this->rootFolder();
$schemaPath = $rootFolder . '/theme.schema.json';
- $this->subscriber->addListener(
- ValidatingFile::class,
- static function (ValidatingFile $event) use ($output): void {
- $output->writeln('========================');
- $output->writeln(\sprintf(
- 'Validating %s',
- $event->getFile()->getFilename()
- ));
- }
- );
-
- $this->subscriber->addListener(
- ValidFile::class,
- static function (ValidFile $event) use ($output): void {
- $output->writeln(\sprintf(
- '%s is valid',
- $event->getFile()->getFilename()
- ));
- }
- );
-
- $this->subscriber->addListener(
- ValidatedFails::class,
- static function (ValidatedFails $event) use ($output): void {
- $output->writeln('# ' . $event->getFile()->getFilename() . ' file errors');
- /**
- * @var array $error
- */
- foreach ($event->getErrors() as $error) {
- $output->writeln(\sprintf(
- '- [%s] is not valid. %s',
- $error['property'] ?? '',
- $error['message'] ?? ''
- ));
- }
- }
- );
-
- $message = new ValidateMessage($rootFolder, $schemaPath, (bool)$input->getOption('force'));
+ $message = new ValidateMessage($rootFolder, $schemaPath, $input->getOption('force') === true);
try {
- return (int)$this->handler->handle($message);
+ return $this->handler->handle($message);
} catch (\Exception $exception) {
$output->writeln('Error: ' . $exception->getMessage() . '');
return Command::FAILURE;
diff --git a/src/Application/Config/TJGConfig.php b/src/Application/Config/TJGConfig.php
deleted file mode 100644
index 59be5341..00000000
--- a/src/Application/Config/TJGConfig.php
+++ /dev/null
@@ -1,18 +0,0 @@
-
- * @psalm-suppress DeprecatedInterface
- */
-class TJGConfig extends Config
-{
-}
diff --git a/src/Application/DumpMessage.php b/src/Application/DumpMessage.php
index 24b3bc1b..8213928e 100644
--- a/src/Application/DumpMessage.php
+++ b/src/Application/DumpMessage.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Application;
-/**
- * @psalm-api
- */
class DumpMessage
{
private string $rootFolder = '';
diff --git a/src/Application/InitMessage.php b/src/Application/InitMessage.php
deleted file mode 100644
index 889cdd61..00000000
--- a/src/Application/InitMessage.php
+++ /dev/null
@@ -1,31 +0,0 @@
-rootFolder = $rootFolder;
- $this->styleOption = $styleOption;
- }
-
- public function getRootFolder(): string
- {
- return $this->rootFolder;
- }
-
- public function getStyleOption(): string
- {
- return $this->styleOption;
- }
-}
diff --git a/src/Application/InfoMessage.php b/src/Application/Message.php
similarity index 89%
rename from src/Application/InfoMessage.php
rename to src/Application/Message.php
index 24aca104..ee2f460b 100644
--- a/src/Application/InfoMessage.php
+++ b/src/Application/Message.php
@@ -4,10 +4,7 @@
namespace ItalyStrap\ThemeJsonGenerator\Application;
-/**
- * @psalm-api
- */
-class InfoMessage
+class Message
{
private string $rootFolder = '';
diff --git a/src/Application/Middlewares/DeleteSchemaJson.php b/src/Application/Middlewares/DeleteSchemaJson.php
new file mode 100644
index 00000000..98dade27
--- /dev/null
+++ b/src/Application/Middlewares/DeleteSchemaJson.php
@@ -0,0 +1,27 @@
+getSchemaPath();
+ if ($message->shouldRecreate() && \file_exists($schemaPath)) {
+ \unlink($schemaPath);
+ }
+
+ return $handler->handle($message);
+ }
+}
diff --git a/src/Domain/Output/Dump.php b/src/Application/Middlewares/Dump.php
similarity index 60%
rename from src/Domain/Output/Dump.php
rename to src/Application/Middlewares/Dump.php
index 0bd4f4b8..c67193b6 100644
--- a/src/Domain/Output/Dump.php
+++ b/src/Application/Middlewares/Dump.php
@@ -2,48 +2,51 @@
declare(strict_types=1);
-namespace ItalyStrap\ThemeJsonGenerator\Domain\Output;
+namespace ItalyStrap\ThemeJsonGenerator\Application\Middlewares;
+use ItalyStrap\Config\Config;
use ItalyStrap\Config\ConfigInterface;
+use ItalyStrap\Pipeline\HandlerInterface;
+use ItalyStrap\Pipeline\MiddlewareInterface;
+use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson;
use ItalyStrap\ThemeJsonGenerator\Application\DumpMessage;
-use ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Presets;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetsInterface;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\DryRunMode;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\GeneratedFile;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\GeneratingFile;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\NoFileFound;
use ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem\FilesFinder;
use ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem\JsonFileWriter;
use ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem\ScssFileWriter;
+use ItalyStrap\ThemeJsonGenerator\Infrastructure\Handler\ConsoleHandler;
use Psr\Container\ContainerInterface;
-use Psr\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\Console\Output\OutputInterface;
-/**
- * @psalm-api
- */
-class Dump
+class Dump implements MiddlewareInterface
{
- public const JSON_FILE_SUFFIX = '.json';
+ /**
+ * @var string
+ */
+ public const M_NO_FILE_FOUND = 'No file found';
- private ConfigInterface $config;
+ public const JSON_FILE_SUFFIX = '.json';
private FilesFinder $filesFinder;
- private EventDispatcherInterface $dispatcher;
-
public function __construct(
- EventDispatcherInterface $dispatcher,
- ConfigInterface $config,
FilesFinder $filesFinder
) {
- $this->config = $config;
$this->filesFinder = $filesFinder;
- $this->dispatcher = $dispatcher;
}
- public function handle(DumpMessage $message): void
+ /**
+ * @phpstan-param DumpMessage $message
+ * @phpstan-param ConsoleHandler $handler
+ */
+ public function process(object $message, HandlerInterface $handler): int
{
+ /**
+ * OutputInterface $output
+ */
+ $output = new \Symfony\Component\Console\Output\ConsoleOutput();
+
$count = 0;
/**
* Let's test the new workflow
@@ -52,10 +55,10 @@ public function handle(DumpMessage $message): void
*/
foreach ($this->filesFinder->find($message->getRootFolder(), 'php') as $fileName => $file) {
$injector = $this->configureContainer();
- /** @psalm-suppress UnresolvableInclude */
$injector->execute(require $file);
$presets = $injector->make(PresetsInterface::class);
$themeJson = $injector->make(ThemeJson::class);
+
$themeJson->setPresets($presets);
$count++;
@@ -66,59 +69,89 @@ public function handle(DumpMessage $message): void
// $dispatcher->dispatch($themeJson);
if ($message->isDryRun()) {
- $this->dispatcher->dispatch(new DryRunMode());
+ $output->writeln(\sprintf(
+ 'Dry run mode enabled, skipping file generation for %s',
+ $fileName
+ ));
continue;
}
- $this->generateJsonFile($message, $fileName, $file, $themeJson);
- $this->generateScssFile($message, $fileName, $themeJson);
+ $this->generateJsonFile($output, $message, $fileName, $file, $themeJson);
+ $this->generateScssFile($output, $message, $fileName, $themeJson);
}
if ($count === 0) {
- $this->dispatcher->dispatch(new NoFileFound());
+ $output->writeln(self::M_NO_FILE_FOUND);
}
+
+ return $handler->handle($message);
}
+ /**
+ * @param ThemeJson $themeJson
+ */
private function generateJsonFile(
+ OutputInterface $output,
DumpMessage $message,
string $fileName,
\SplFileInfo $file,
ThemeJson $themeJson
): void {
- $this->dispatcher->dispatch(new GeneratingFile($fileName . self::JSON_FILE_SUFFIX));
+
+ $output->writeln(\sprintf(
+ 'Generating %s file',
+ $fileName . self::JSON_FILE_SUFFIX
+ ));
(new JsonFileWriter($this->filesFinder->resolveJsonFile($file)))
->write($themeJson);
- $this->dispatcher->dispatch(new GeneratedFile($fileName . self::JSON_FILE_SUFFIX));
+ $output->writeln(\sprintf(
+ 'Generated %s file',
+ $fileName . self::JSON_FILE_SUFFIX
+ ));
+ $output->writeln('========================');
}
- private function generateScssFile(DumpMessage $message, string $fileName, ThemeJson $themeJson): void
- {
+ /**
+ * @param ThemeJson $themeJson
+ */
+ private function generateScssFile(
+ OutputInterface $output,
+ DumpMessage $message,
+ string $fileName,
+ ThemeJson $themeJson
+ ): void {
$path_for_theme_sass = $message->getRootFolder() . DIRECTORY_SEPARATOR . $message->getSassFolder();
if ($message->getSassFolder() !== '' && \is_writable($path_for_theme_sass)) {
- $this->dispatcher->dispatch(new GeneratingFile($fileName . '.scss'));
+ $output->writeln(\sprintf(
+ 'Generating %s file',
+ $fileName . '.scss'
+ ));
+
(new ScssFileWriter($path_for_theme_sass . DIRECTORY_SEPARATOR . $fileName . '.scss'))
->write($themeJson);
- $this->dispatcher->dispatch(new GeneratedFile($fileName . '.scss'));
+
+ $output->writeln(\sprintf(
+ 'Generated %s file',
+ $fileName . '.scss'
+ ));
+ $output->writeln('========================');
}
}
- private function configureContainer(): \ItalyStrap\Empress\Injector
+ private function configureContainer(): \Auryn\Injector
{
- $injector = new \ItalyStrap\Empress\Injector();
+ $injector = new \Auryn\Injector();
$injector->share($injector);
- $container = $this->createContainer($injector, clone $this->config);
+ $container = $this->createContainer($injector, new Config());
$injector->alias(ContainerInterface::class, \get_class($container));
$injector->share($container);
$injector->alias(PresetsInterface::class, Presets::class);
$injector->share(PresetsInterface::class);
- $injector->alias(EventDispatcherInterface::class, \get_class($this->dispatcher));
- $injector->share(EventDispatcherInterface::class);
-
/**
* Injector resolve to null if a param is nullable, so we need to be explicit and declare the param
* I need this for all the classes under the Styles namespace
@@ -130,16 +163,25 @@ private function configureContainer(): \ItalyStrap\Empress\Injector
return $injector;
}
+ /**
+ * @param ConfigInterface $config
+ */
private function createContainer(
- \ItalyStrap\Empress\Injector $injector,
- \ItalyStrap\Config\ConfigInterface $config
+ \Auryn\Injector $injector,
+ ConfigInterface $config
): ContainerInterface {
return new class ($injector, $config) implements ContainerInterface {
private \Auryn\Injector $injector;
+ /**
+ * @var ConfigInterface
+ */
private ConfigInterface $config;
- public function __construct(\ItalyStrap\Empress\Injector $injector, ConfigInterface $config)
+ /**
+ * @param ConfigInterface $config
+ */
+ public function __construct(\Auryn\Injector $injector, ConfigInterface $config)
{
$this->injector = $injector;
$this->config = $config;
diff --git a/src/Domain/Output/Info.php b/src/Application/Middlewares/Info.php
similarity index 50%
rename from src/Domain/Output/Info.php
rename to src/Application/Middlewares/Info.php
index be989e75..a7a60023 100644
--- a/src/Domain/Output/Info.php
+++ b/src/Application/Middlewares/Info.php
@@ -2,16 +2,18 @@
declare(strict_types=1);
-namespace ItalyStrap\ThemeJsonGenerator\Domain\Output;
+namespace ItalyStrap\ThemeJsonGenerator\Application\Middlewares;
-use ItalyStrap\ThemeJsonGenerator\Application\InfoMessage;
+use ItalyStrap\Pipeline\HandlerInterface;
+use ItalyStrap\Pipeline\MiddlewareInterface;
+use ItalyStrap\ThemeJsonGenerator\Application\Message;
use ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem\FilesFinder;
+use Symfony\Component\Console\Command\Command;
/**
- * @psalm-api
* @todo Implement the logic
*/
-class Info implements \ItalyStrap\Bus\HandlerInterface
+class Info implements MiddlewareInterface
{
private FilesFinder $filesFinder;
@@ -21,13 +23,15 @@ public function __construct(
$this->filesFinder = $filesFinder;
}
- public function handle(object $message): int
+ /**
+ * @phpstan-param Message $message
+ */
+ public function process(object $message, HandlerInterface $handler): int
{
- /** @var InfoMessage $message */
foreach ($this->filesFinder->find($message->getRootFolder(), 'json') as $file) {
echo $file->getBasename() . PHP_EOL;
}
- return 0;
+ return Command::SUCCESS;
}
}
diff --git a/src/Domain/Output/Init.php b/src/Application/Middlewares/Init.php
similarity index 71%
rename from src/Domain/Output/Init.php
rename to src/Application/Middlewares/Init.php
index 4e33e4f9..837de744 100644
--- a/src/Domain/Output/Init.php
+++ b/src/Application/Middlewares/Init.php
@@ -2,30 +2,26 @@
declare(strict_types=1);
-namespace ItalyStrap\ThemeJsonGenerator\Domain\Output;
+namespace ItalyStrap\ThemeJsonGenerator\Application\Middlewares;
use Brick\VarExporter\VarExporter;
-use ItalyStrap\ThemeJsonGenerator\Application\InitMessage;
-use ItalyStrap\ThemeJsonGenerator\Application\Commands\Utils\DataFromJsonTrait;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\EntryPointCanNotBeCreated;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\EntryPointCreated;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\EntryPointDoesNotExist;
+use ItalyStrap\Pipeline\HandlerInterface;
+use ItalyStrap\Pipeline\MiddlewareInterface;
+use ItalyStrap\ThemeJsonGenerator\Application\Message;
+use ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem\DataFromJsonTrait;
use ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem\FilesFinder;
use PhpParser\Error;
-use PhpParser\Node;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\ClassConst;
use PhpParser\NodeFinder;
use PhpParser\ParserFactory;
-use Psr\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Output\OutputInterface;
use Webimpress\SafeWriter\Exception\ExceptionInterface as FileWriterException;
use Webimpress\SafeWriter\FileWriter;
use Webmozart\Assert\Assert;
-/**
- * @psalm-api
- */
-class Init
+class Init implements MiddlewareInterface
{
use DataFromJsonTrait;
@@ -37,8 +33,7 @@ class Init
declare(strict_types=1);
-use ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson;
-use ItalyStrap\ThemeJsonGenerator\Domain\Input\SectionNames;
+use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetsInterface;
use Psr\Container\ContainerInterface;
@@ -53,30 +48,40 @@ class Init
private FilesFinder $filesFinder;
- private EventDispatcherInterface $dispatcher;
-
public function __construct(
- EventDispatcherInterface $dispatcher,
FilesFinder $filesFinder
) {
$this->filesFinder = $filesFinder;
- $this->dispatcher = $dispatcher;
}
- public function handle(InitMessage $command): void
+ /**
+ * @phpstan-param Message $message
+ */
+ public function process(object $message, HandlerInterface $handler): int
{
- foreach ($this->filesFinder->find($command->getRootFolder(), 'json') as $file) {
- $this->generateEntryPointDataFile($file);
+ /**
+ * OutputInterface $output
+ */
+ $output = new \Symfony\Component\Console\Output\ConsoleOutput();
+
+ foreach ($this->filesFinder->find($message->getRootFolder(), 'json') as $file) {
+ $this->generateEntryPointDataFile($output, $file);
}
+
+ return Command::SUCCESS;
}
private function generateEntryPointDataFile(
+ OutputInterface $output,
\SplFileInfo $file
): void {
$entryPointFileName = $file->getFilename() . self::ENTRY_POINT_EXTENSION;
$entryPointRealPath = $file->getPath() . DIRECTORY_SEPARATOR . $entryPointFileName;
if (!\file_exists($entryPointRealPath)) {
- $this->dispatcher->dispatch(new EntryPointDoesNotExist($entryPointRealPath));
+ $output->writeln(\sprintf(
+ 'Entry file does not exist, creating %s file',
+ $entryPointRealPath
+ ));
$dataExported = $this->exportFromThemeJsonIfExists($file);
$content = \sprintf(
@@ -87,14 +92,18 @@ private function generateEntryPointDataFile(
try {
FileWriter::writeFile($entryPointRealPath, $content, 0666);
} catch (FileWriterException $fileWriterException) {
- $this->dispatcher->dispatch(new EntryPointCanNotBeCreated(
+ $output->writeln(\sprintf(
+ 'Entry file %s cannot be created because of %s',
$entryPointRealPath,
- $fileWriterException
+ $fileWriterException->getMessage()
));
return;
}
- $this->dispatcher->dispatch(new EntryPointCreated($entryPointRealPath));
+ $output->writeln(\sprintf(
+ 'Entry file %s created',
+ $entryPointRealPath
+ ));
}
}
diff --git a/src/Application/Commands/Middleware/SchemaJsonMiddleware.php b/src/Application/Middlewares/SchemaJson.php
similarity index 66%
rename from src/Application/Commands/Middleware/SchemaJsonMiddleware.php
rename to src/Application/Middlewares/SchemaJson.php
index 70643d80..e4c5e618 100644
--- a/src/Application/Commands/Middleware/SchemaJsonMiddleware.php
+++ b/src/Application/Middlewares/SchemaJson.php
@@ -2,22 +2,28 @@
declare(strict_types=1);
-namespace ItalyStrap\ThemeJsonGenerator\Application\Commands\Middleware;
+namespace ItalyStrap\ThemeJsonGenerator\Application\Middlewares;
+use ItalyStrap\Pipeline\HandlerInterface;
+use ItalyStrap\Pipeline\MiddlewareInterface;
use ItalyStrap\ThemeJsonGenerator\Application\ValidateMessage;
+use ItalyStrap\ThemeJsonGenerator\Infrastructure\Handler\ConsoleHandler;
use Webimpress\SafeWriter\FileWriter;
-class SchemaJsonMiddleware implements \ItalyStrap\Bus\MiddlewareInterface
+class SchemaJson implements MiddlewareInterface
{
- public function process(object $message, \ItalyStrap\Bus\HandlerInterface $handler): int
+ /**
+ * @phpstan-param ValidateMessage $message
+ * @phpstan-param ConsoleHandler $handler
+ */
+ public function process(object $message, HandlerInterface $handler): int
{
- /** @var ValidateMessage $message */
$schemaPath = $message->getSchemaPath();
if (!\file_exists($schemaPath) || $this->isFileSchemaOlderThanOneWeek($schemaPath)) {
$this->createFileSchema($schemaPath);
}
- return (int)$handler->handle($message);
+ return $handler->handle($message);
}
private function isFileSchemaOlderThanOneWeek(string $schemaPath): bool
diff --git a/src/Application/Middlewares/Validate.php b/src/Application/Middlewares/Validate.php
new file mode 100644
index 00000000..3723accd
--- /dev/null
+++ b/src/Application/Middlewares/Validate.php
@@ -0,0 +1,95 @@
+validator = $validator;
+ $this->filesFinder = $filesFinder;
+ $this->compiler = $compiler;
+ }
+
+ /**
+ * @phpstan-param ValidateMessage $message
+ * @phpstan-param ConsoleHandler $handler
+ */
+ public function process(object $message, HandlerInterface $handler): mixed
+ {
+ /**
+ * OutputInterface $output
+ */
+ $output = new \Symfony\Component\Console\Output\ConsoleOutput();
+
+ foreach ($this->filesFinder->find($message->getRootFolder(), 'json') as $file) {
+ $output->writeln('========================');
+ $output->writeln(\sprintf(
+ 'Validating %s',
+ $file->getFilename()
+ ));
+
+ $this->validateJsonFile($output, $file, $message->getSchemaPath());
+ $this->validator->reset();
+ /**
+ * @todo Implementing scss validation
+ */
+ $this->compiler->compileString('');
+ }
+
+ return $handler->handle($message);
+ }
+
+ private function validateJsonFile(
+ OutputInterface $output,
+ \SplFileInfo $file,
+ string $schemaPath
+ ): void {
+ $data = $this->objectFromPath((string)$file);
+ $this->validator->validate($data, (object)['$ref' => 'file://' . \realpath($schemaPath)]);
+
+ if (!$this->validator->isValid()) {
+ $output->writeln('# ' . $file->getFilename() . ' file errors');
+ /**
+ * @var array $error
+ */
+ foreach ((array)$this->validator->getErrors() as $error) {
+ $output->writeln(\sprintf(
+ '- [%s] is not valid. %s',
+ $error['property'] ?? '',
+ $error['message'] ?? ''
+ ));
+ }
+
+ return;
+ }
+
+ $output->writeln(\sprintf(
+ '%s is valid',
+ $file->getFilename()
+ ));
+ }
+}
diff --git a/src/Application/ValidateMessage.php b/src/Application/ValidateMessage.php
index a4f62d0d..19f52ed4 100644
--- a/src/Application/ValidateMessage.php
+++ b/src/Application/ValidateMessage.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Application;
-/**
- * @psalm-api
- */
class ValidateMessage
{
private string $rootFolder;
diff --git a/src/Bootstrap.php b/src/Bootstrap.php
index 01167d83..6548fb9f 100644
--- a/src/Bootstrap.php
+++ b/src/Bootstrap.php
@@ -4,68 +4,46 @@
namespace ItalyStrap\ThemeJsonGenerator;
-use Symfony\Component\Console\Application;
-use ItalyStrap\Bus\Bus;
-use ItalyStrap\Config\Config;
-use ItalyStrap\Config\ConfigInterface;
-use ItalyStrap\Empress\Injector;
-use ItalyStrap\Finder\Finder;
-use ItalyStrap\Finder\FinderFactory;
-use ItalyStrap\Finder\FinderInterface;
+use ItalyStrap\Empress\ContainerBuilder;
use ItalyStrap\ThemeJsonGenerator\Application\Commands\DumpCommand;
use ItalyStrap\ThemeJsonGenerator\Application\Commands\InfoCommand;
use ItalyStrap\ThemeJsonGenerator\Application\Commands\InitCommand;
use ItalyStrap\ThemeJsonGenerator\Application\Commands\ValidateCommand;
-use ItalyStrap\ThemeJsonGenerator\Application\Commands\Middleware\DeleteSchemaJsonMiddleware;
-use ItalyStrap\ThemeJsonGenerator\Application\Commands\Middleware\SchemaJsonMiddleware;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Info;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Validate;
-use Psr\EventDispatcher\EventDispatcherInterface;
+use Psr\Container\ContainerInterface;
+use Symfony\Component\Console\Application;
+use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
-/**
- * @psalm-api
- */
final class Bootstrap
{
+ public function container(): ContainerInterface
+ {
+ $builder = new ContainerBuilder();
+
+ /**
+ * The order of the modules is important
+ */
+// $builder->addModule(new ModuleUI());
+ $builder->addModule(new ModuleInfrastructure());
+// $builder->addModule(new ModuleDomain());
+ $builder->addModule(new ModuleApplication());
+
+ return $builder->build();
+ }
public function run(): int
{
- $injector = new Injector();
- $injector->share($injector);
- $injector->alias(ConfigInterface::class, Config::class);
+ $container = $this->container();
+
+ $application = new Application('Theme JSON Generator', '0.1.0');
- $injector->alias(FinderInterface::class, Finder::class);
- $injector->delegate(Finder::class, static fn (): FinderInterface => (new FinderFactory())->make());
+ $commandLoader = new ContainerCommandLoader($container, [
+ InitCommand::NAME => InitCommand::class,
+ DumpCommand::NAME => DumpCommand::class,
+ ValidateCommand::NAME => ValidateCommand::class,
+ InfoCommand::NAME => InfoCommand::class,
+ ]);
- $injector->alias(
- EventDispatcherInterface::class,
- \Symfony\Component\EventDispatcher\EventDispatcher::class
- );
- $injector->share(EventDispatcherInterface::class);
- $injector->share(\Symfony\Component\EventDispatcher\EventDispatcher::class);
+ $application->setCommandLoader($commandLoader);
- $application = new Application();
- /** @psalm-suppress InvalidArgument */
- $application->add($injector->make(InitCommand::class));
- /** @psalm-suppress InvalidArgument */
- $application->add($injector->make(DumpCommand::class));
- /** @psalm-suppress InvalidArgument */
- $application->add($injector->make(ValidateCommand::class, [
- '+handler' => static function (string $named_param, Injector $injector): Bus {
- $bus = new Bus(
- $injector->make(Validate::class)
- );
- $bus->addMiddleware(
- new DeleteSchemaJsonMiddleware(),
- new SchemaJsonMiddleware()
- );
- return $bus;
- },
- ]));
- $application->add($injector->make(InfoCommand::class, [
- '+handler' => static fn(string $named_param, Injector $injector): Bus => new Bus(
- $injector->make(Info::class)
- ),
- ]));
return $application->run();
}
}
diff --git a/src/Domain/Input/Settings/Color/Duotone.php b/src/Domain/Input/Settings/Color/Duotone.php
index 465b759e..b6aca50c 100644
--- a/src/Domain/Input/Settings/Color/Duotone.php
+++ b/src/Domain/Input/Settings/Color/Duotone.php
@@ -7,9 +7,6 @@
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetTrait;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetInterface;
-/**
- * @psalm-api
- */
class Duotone implements PresetInterface
{
use PresetTrait;
diff --git a/src/Domain/Input/Settings/Color/Gradient.php b/src/Domain/Input/Settings/Color/Gradient.php
index 621edf56..a6059f58 100644
--- a/src/Domain/Input/Settings/Color/Gradient.php
+++ b/src/Domain/Input/Settings/Color/Gradient.php
@@ -8,9 +8,6 @@
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetTrait;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetInterface;
-/**
- * @psalm-api
- */
class Gradient implements PresetInterface
{
use PresetTrait;
diff --git a/src/Domain/Input/Settings/Color/Palette.php b/src/Domain/Input/Settings/Color/Palette.php
index 5fdd867d..f7398c09 100644
--- a/src/Domain/Input/Settings/Color/Palette.php
+++ b/src/Domain/Input/Settings/Color/Palette.php
@@ -8,9 +8,6 @@
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetTrait;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetInterface;
-/**
- * @psalm-api
- */
class Palette implements PresetInterface
{
use PresetTrait;
diff --git a/src/Domain/Input/Settings/Color/Shadow.php b/src/Domain/Input/Settings/Color/Shadow.php
index 65183d85..ad885d4f 100644
--- a/src/Domain/Input/Settings/Color/Shadow.php
+++ b/src/Domain/Input/Settings/Color/Shadow.php
@@ -8,9 +8,6 @@
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetInterface;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetTrait;
-/**
- * @psalm-api
- */
class Shadow implements PresetInterface
{
use PresetTrait;
diff --git a/src/Domain/Input/Settings/Color/Utilities/AchromaticColorsExperimental.php b/src/Domain/Input/Settings/Color/Utilities/AchromaticColorsExperimental.php
index 2f2e8259..4b845b86 100644
--- a/src/Domain/Input/Settings/Color/Utilities/AchromaticColorsExperimental.php
+++ b/src/Domain/Input/Settings/Color/Utilities/AchromaticColorsExperimental.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities;
-/**
- * @psalm-api
- */
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 314842ae..310f6857 100644
--- a/src/Domain/Input/Settings/Color/Utilities/AnalogousColorsExperimental.php
+++ b/src/Domain/Input/Settings/Color/Utilities/AnalogousColorsExperimental.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities;
-/**
- * @psalm-api
- */
class AnalogousColorsExperimental implements ColorsGenerator
{
private ColorModifierInterface $colorModifier;
diff --git a/src/Domain/Input/Settings/Color/Utilities/BoxShadow.php b/src/Domain/Input/Settings/Color/Utilities/BoxShadow.php
index 3633f050..949873c5 100644
--- a/src/Domain/Input/Settings/Color/Utilities/BoxShadow.php
+++ b/src/Domain/Input/Settings/Color/Utilities/BoxShadow.php
@@ -6,9 +6,6 @@
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Palette;
-/**
- * @psalm-api
- */
class BoxShadow
{
private bool $inset = false;
diff --git a/src/Domain/Input/Settings/Color/Utilities/Color.php b/src/Domain/Input/Settings/Color/Utilities/Color.php
index eb990a9b..e0423a4d 100644
--- a/src/Domain/Input/Settings/Color/Utilities/Color.php
+++ b/src/Domain/Input/Settings/Color/Utilities/Color.php
@@ -8,9 +8,6 @@
use Spatie\Color\Factory as ColorFactory;
use Spatie\Color\Hsla;
-/**
- * @psalm-api
- */
final class Color implements ColorInterface
{
private SpatieColor $spatieColor;
@@ -39,10 +36,15 @@ public function __construct(string $color)
if ($reflected->hasProperty('alpha')) {
$reflectionProperty = $reflected->getProperty('alpha');
$reflectionProperty->setAccessible(true);
- /**
- * @psalm-suppress MixedAssignment
- */
- $this->alpha = $reflectionProperty->getValue($this->spatieColor);
+ $alpha = $reflectionProperty->getValue($this->spatieColor);
+ if (!\is_string($alpha) && !\is_float($alpha) && !\is_int($alpha)) {
+ throw new \RuntimeException(\sprintf(
+ 'Expected alpha to be string, float, or int, got %s.',
+ \get_debug_type($alpha)
+ ));
+ }
+
+ $this->alpha = \is_int($alpha) ? (float)$alpha : $alpha;
$reflectionProperty->setAccessible(false);
}
@@ -170,7 +172,7 @@ public function toHsl(): self
return new self((string) $this->spatieColor->toHsl());
}
- public function toHsla(float $alpha = null): self
+ public function toHsla(?float $alpha = null): self
{
$alpha = $alpha ?? $this->fromHexToFloat($this->alpha);
return new self((string) $this->spatieColor->toHsla($alpha));
@@ -181,7 +183,7 @@ public function toRgb(): self
return new self((string) $this->spatieColor->toRgb());
}
- public function toRgba(float $alpha = null): self
+ public function toRgba(?float $alpha = null): self
{
$alpha = $alpha ?? $this->fromHexToFloat($this->alpha);
return new self((string) $this->spatieColor->toRgba($alpha));
@@ -192,10 +194,7 @@ public function __toString(): string
return (string)$this->spatieColor;
}
- /**
- * @param mixed $alpha
- */
- private function fromHexToFloat($alpha): float
+ private function fromHexToFloat(string|int|float $alpha): float
{
return \is_string($alpha) ? \hexdec($alpha) / 255 : (float)$alpha;
}
diff --git a/src/Domain/Input/Settings/Color/Utilities/ColorFactory.php b/src/Domain/Input/Settings/Color/Utilities/ColorFactory.php
index e078caee..620ddbb0 100644
--- a/src/Domain/Input/Settings/Color/Utilities/ColorFactory.php
+++ b/src/Domain/Input/Settings/Color/Utilities/ColorFactory.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities;
-/**
- * @psalm-api
- */
final class ColorFactory implements ColorFactoryInterface
{
/**
diff --git a/src/Domain/Input/Settings/Color/Utilities/ColorFactoryInterface.php b/src/Domain/Input/Settings/Color/Utilities/ColorFactoryInterface.php
index 418bc006..b4a8fd18 100644
--- a/src/Domain/Input/Settings/Color/Utilities/ColorFactoryInterface.php
+++ b/src/Domain/Input/Settings/Color/Utilities/ColorFactoryInterface.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities;
-/**
- * @psalm-api
- */
interface ColorFactoryInterface
{
/**
diff --git a/src/Domain/Input/Settings/Color/Utilities/ColorInterface.php b/src/Domain/Input/Settings/Color/Utilities/ColorInterface.php
index 4fd15496..a6d8ece7 100644
--- a/src/Domain/Input/Settings/Color/Utilities/ColorInterface.php
+++ b/src/Domain/Input/Settings/Color/Utilities/ColorInterface.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities;
-/**
- * @psalm-api
- */
// phpcs:ignore PHPCompatibility.Interfaces.NewInterfaces.stringableFound
interface ColorInterface extends \Stringable
{
diff --git a/src/Domain/Input/Settings/Color/Utilities/ColorModifier.php b/src/Domain/Input/Settings/Color/Utilities/ColorModifier.php
index fc3c54a7..54351346 100644
--- a/src/Domain/Input/Settings/Color/Utilities/ColorModifier.php
+++ b/src/Domain/Input/Settings/Color/Utilities/ColorModifier.php
@@ -6,9 +6,6 @@
use Exception;
-/**
- * @psalm-api
- */
final class ColorModifier implements ColorModifierInterface
{
private ColorInterface $color;
@@ -20,7 +17,7 @@ final class ColorModifier implements ColorModifierInterface
/**
* @throws Exception
*/
- public function __construct(ColorInterface $color, ColorFactoryInterface $factory = null)
+ public function __construct(ColorInterface $color, ?ColorFactoryInterface $factory = null)
{
$this->color = $color;
$this->color_factory = $factory ?? new ColorFactory();
@@ -137,10 +134,6 @@ private function createNewColorWithChangedContrast(int $amount): ColorInterface
);
}
- /**
- * @psalm-suppress MixedInferredReturnType
- * @psalm-suppress MixedReturnStatement
- */
private function createNewColorFrom(
string $hue,
string $saturation,
@@ -161,8 +154,6 @@ private function createNewColorFrom(
/**
* @todo Is it a good idea to make it public?
* Evaluate possible side effects.
- * @psalm-suppress MixedInferredReturnType
- * @psalm-suppress MixedReturnStatement
*/
private function mixWith(string $color_string, float $weight = 0): ColorInterface
{
@@ -211,7 +202,7 @@ private function sanitizeFromFloatToInteger(float $value): int
/**
* @param ColorInterface $newColor
- * @return mixed
+ * @return ColorInterface
* @throws Exception
*/
private function callMethodOnColorObject(ColorInterface $newColor): ColorInterface
diff --git a/src/Domain/Input/Settings/Color/Utilities/ColorModifierInterface.php b/src/Domain/Input/Settings/Color/Utilities/ColorModifierInterface.php
index 48b9a33a..58a6d16f 100644
--- a/src/Domain/Input/Settings/Color/Utilities/ColorModifierInterface.php
+++ b/src/Domain/Input/Settings/Color/Utilities/ColorModifierInterface.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities;
-/**
- * @psalm-api
- */
interface ColorModifierInterface
{
public function tint(float $weight = 0): ColorInterface;
diff --git a/src/Domain/Input/Settings/Color/Utilities/ColorsGenerator.php b/src/Domain/Input/Settings/Color/Utilities/ColorsGenerator.php
index 48d9c84a..43b2d09f 100644
--- a/src/Domain/Input/Settings/Color/Utilities/ColorsGenerator.php
+++ b/src/Domain/Input/Settings/Color/Utilities/ColorsGenerator.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities;
-/**
- * @psalm-api
- */
interface ColorsGenerator
{
/**
diff --git a/src/Domain/Input/Settings/Color/Utilities/ComplementaryColorsExperimental.php b/src/Domain/Input/Settings/Color/Utilities/ComplementaryColorsExperimental.php
index 10c8cd0e..65dc9381 100644
--- a/src/Domain/Input/Settings/Color/Utilities/ComplementaryColorsExperimental.php
+++ b/src/Domain/Input/Settings/Color/Utilities/ComplementaryColorsExperimental.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities;
-/**
- * @psalm-api
- */
class ComplementaryColorsExperimental implements ColorsGenerator
{
private ColorModifierInterface $color;
diff --git a/src/Domain/Input/Settings/Color/Utilities/GradientInterface.php b/src/Domain/Input/Settings/Color/Utilities/GradientInterface.php
index 3311c5d2..9aee6da6 100644
--- a/src/Domain/Input/Settings/Color/Utilities/GradientInterface.php
+++ b/src/Domain/Input/Settings/Color/Utilities/GradientInterface.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities;
-/**
- * @psalm-api
- */
// phpcs:ignore PHPCompatibility.Interfaces.NewInterfaces.stringableFound
interface GradientInterface extends \Stringable
{
diff --git a/src/Domain/Input/Settings/Color/Utilities/LinearGradient.php b/src/Domain/Input/Settings/Color/Utilities/LinearGradient.php
index 4873bc3b..451d47c6 100644
--- a/src/Domain/Input/Settings/Color/Utilities/LinearGradient.php
+++ b/src/Domain/Input/Settings/Color/Utilities/LinearGradient.php
@@ -6,9 +6,6 @@
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Palette;
-/**
- * @psalm-api
- */
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 0ef44567..25a3d1dc 100644
--- a/src/Domain/Input/Settings/Color/Utilities/MonochromaticColorsExperimental.php
+++ b/src/Domain/Input/Settings/Color/Utilities/MonochromaticColorsExperimental.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities;
-/**
- * @psalm-api
- */
class MonochromaticColorsExperimental implements ColorsGenerator
{
private ColorModifierInterface $colorModifier;
diff --git a/src/Domain/Input/Settings/Color/Utilities/SplitComplementaryColorsExperimental.php b/src/Domain/Input/Settings/Color/Utilities/SplitComplementaryColorsExperimental.php
index 8a710780..81813ba4 100644
--- a/src/Domain/Input/Settings/Color/Utilities/SplitComplementaryColorsExperimental.php
+++ b/src/Domain/Input/Settings/Color/Utilities/SplitComplementaryColorsExperimental.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities;
-/**
- * @psalm-api
- */
class SplitComplementaryColorsExperimental implements ColorsGenerator
{
private ColorModifierInterface $colorModifier;
diff --git a/src/Domain/Input/Settings/Color/Utilities/SquareColorsExperimental.php b/src/Domain/Input/Settings/Color/Utilities/SquareColorsExperimental.php
index 2415c2a9..5ccc94e1 100644
--- a/src/Domain/Input/Settings/Color/Utilities/SquareColorsExperimental.php
+++ b/src/Domain/Input/Settings/Color/Utilities/SquareColorsExperimental.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities;
-/**
- * @psalm-api
- */
class SquareColorsExperimental implements ColorsGenerator
{
private ColorModifierInterface $colorModifier;
diff --git a/src/Domain/Input/Settings/Color/Utilities/TriadicColorsExperimental.php b/src/Domain/Input/Settings/Color/Utilities/TriadicColorsExperimental.php
index 887cbfd4..2905b733 100644
--- a/src/Domain/Input/Settings/Color/Utilities/TriadicColorsExperimental.php
+++ b/src/Domain/Input/Settings/Color/Utilities/TriadicColorsExperimental.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities;
-/**
- * @psalm-api
- */
class TriadicColorsExperimental implements ColorsGenerator
{
private ColorModifierInterface $colorModifier;
diff --git a/src/Domain/Input/Settings/Custom/Custom.php b/src/Domain/Input/Settings/Custom/Custom.php
index 318b6bd2..81e5327a 100644
--- a/src/Domain/Input/Settings/Custom/Custom.php
+++ b/src/Domain/Input/Settings/Custom/Custom.php
@@ -7,9 +7,6 @@
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetTrait;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetInterface;
-/**
- * @psalm-api
- */
class Custom implements PresetInterface
{
use PresetTrait;
diff --git a/src/Domain/Input/Settings/Custom/CustomToPresets.php b/src/Domain/Input/Settings/Custom/CustomToPresets.php
index a9754e21..e1f5adee 100644
--- a/src/Domain/Input/Settings/Custom/CustomToPresets.php
+++ b/src/Domain/Input/Settings/Custom/CustomToPresets.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Custom;
-/**
- * @psalm-api
- */
class CustomToPresets
{
/**
@@ -23,17 +20,24 @@ public function __construct(
$this->customs = $customs;
}
+ /**
+ * @return Custom[]
+ */
public function toArray(): array
{
return $this->presetsToFlat($this->customs);
}
+ /**
+ * @param array $presets
+ * @return Custom[]
+ */
private function presetsToFlat(array $presets, string $prefix = ''): array
{
$processed = [];
/**
- * @var string|array|\Stringable $value
+ * @var string|array|\Stringable $value
*/
foreach ($presets as $key => $value) {
$fullKey = (string)($prefix === '' ? $key : $prefix . '.' . $key);
diff --git a/src/Domain/Input/Settings/NullPresets.php b/src/Domain/Input/Settings/NullPresets.php
index 7e659276..011d4668 100644
--- a/src/Domain/Input/Settings/NullPresets.php
+++ b/src/Domain/Input/Settings/NullPresets.php
@@ -6,7 +6,6 @@
/**
* @infection-ignore-all
- * @psalm-api
*/
class NullPresets implements PresetsInterface
{
@@ -29,4 +28,9 @@ public function parse(string $content): string
{
return $content;
}
+
+ public function toArrayByCategory(string $category): array
+ {
+ return [];
+ }
}
diff --git a/src/Domain/Input/Settings/PresetInterface.php b/src/Domain/Input/Settings/PresetInterface.php
index ea7f0378..c31058e3 100644
--- a/src/Domain/Input/Settings/PresetInterface.php
+++ b/src/Domain/Input/Settings/PresetInterface.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings;
-/**
- * @psalm-api
- */
// phpcs:ignore PHPCompatibility.Interfaces.NewInterfaces.stringableFound
interface PresetInterface extends \Stringable
{
@@ -23,7 +20,7 @@ public function var(string $fallback = ''): string;
public function __toString(): string;
/**
- * @return array
+ * @return array|object>
*/
public function toArray(): array;
}
diff --git a/src/Domain/Input/Settings/PresetTrait.php b/src/Domain/Input/Settings/PresetTrait.php
index daf4aca3..ad711061 100644
--- a/src/Domain/Input/Settings/PresetTrait.php
+++ b/src/Domain/Input/Settings/PresetTrait.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings;
-/**
- * @psalm-api
- */
trait PresetTrait
{
public function type(): string
diff --git a/src/Domain/Input/Settings/Presets.php b/src/Domain/Input/Settings/Presets.php
index b064e496..093cae85 100644
--- a/src/Domain/Input/Settings/Presets.php
+++ b/src/Domain/Input/Settings/Presets.php
@@ -10,7 +10,6 @@
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Custom\Custom;
/**
- * @psalm-api
* @see PresetsTest
* @see PresetsIntegrationTest
*/
@@ -35,7 +34,6 @@ public function add(PresetInterface $item): self
$this->assertIsUnique($key, $item);
- /** @psalm-suppress MixedPropertyTypeCoercion */
$this->insertValue(
$this->collection,
\explode('.', $key),
@@ -114,6 +112,9 @@ public function field(string $field): self
return $this;
}
+ /**
+ * @return array
+ */
public function toArray(): array
{
$field = $this->field;
@@ -129,7 +130,8 @@ public function toArray(): array
return $this->processCustomCollection($fetched);
}
- return $this->processPresetCollection($fetched);
+ /** @var PresetInterface[] $fetched */
+ return $this->processPresetCollection(...$fetched);
}
/**
@@ -141,7 +143,11 @@ public function toArrayByCategory(string $category): array
return $this->toArray();
}
- private function processPresetCollection(array $collection): array
+ /**
+ * @param PresetInterface ...$collection
+ * @return array>
+ */
+ private function processPresetCollection(PresetInterface ...$collection): array
{
return \array_values(\array_map(
function (PresetInterface $item): array {
@@ -162,7 +168,7 @@ function (PresetInterface $item): array {
/**
* @param array $collection
- * @param array-key|string $prefix
+ * @param string $prefix
* @return array
*/
private function processCustomCollection(array $collection, string $prefix = ''): array
@@ -196,6 +202,9 @@ private function assertIsUnique(string $key, PresetInterface $item): void
}
}
+ /**
+ * @return array
+ */
public function jsonSerialize(): array
{
return $this->toArray();
diff --git a/src/Domain/Input/Settings/PresetsInterface.php b/src/Domain/Input/Settings/PresetsInterface.php
index 92e6921e..9194550e 100644
--- a/src/Domain/Input/Settings/PresetsInterface.php
+++ b/src/Domain/Input/Settings/PresetsInterface.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings;
-/**
- * @psalm-api
- */
interface PresetsInterface
{
public function add(PresetInterface $item): self;
@@ -23,4 +20,9 @@ public function addMultiple(array $items): self;
public function get(string $key, $default = null);
public function parse(string $content): string;
+
+ /**
+ * @return array
+ */
+ public function toArrayByCategory(string $category): array;
}
diff --git a/src/Domain/Input/Settings/Typography/FontFamily.php b/src/Domain/Input/Settings/Typography/FontFamily.php
index f0efac9b..44cbaad6 100644
--- a/src/Domain/Input/Settings/Typography/FontFamily.php
+++ b/src/Domain/Input/Settings/Typography/FontFamily.php
@@ -7,9 +7,6 @@
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetTrait;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetInterface;
-/**
- * @psalm-api
- */
class FontFamily implements PresetInterface
{
use PresetTrait;
diff --git a/src/Domain/Input/Settings/Typography/FontSize.php b/src/Domain/Input/Settings/Typography/FontSize.php
index d2dfc421..b3968be4 100644
--- a/src/Domain/Input/Settings/Typography/FontSize.php
+++ b/src/Domain/Input/Settings/Typography/FontSize.php
@@ -8,9 +8,6 @@
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\PresetInterface;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Typography\Utilities\Fluid;
-/**
- * @psalm-api
- */
class FontSize implements PresetInterface
{
use PresetTrait;
@@ -36,6 +33,9 @@ public function __construct(string $slug, string $name, string $size, ?Fluid $fl
$this->fluid = $fluid;
}
+ /**
+ * @return array{slug: string, name: string, size: string, fluid?: Fluid}
+ */
public function toArray(): array
{
return \array_filter([
diff --git a/src/Domain/Input/Settings/Typography/Utilities/Fluid.php b/src/Domain/Input/Settings/Typography/Utilities/Fluid.php
index 69001aac..9a2947fa 100644
--- a/src/Domain/Input/Settings/Typography/Utilities/Fluid.php
+++ b/src/Domain/Input/Settings/Typography/Utilities/Fluid.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Typography\Utilities;
-/**
- * @psalm-api
- */
class Fluid
{
/**
diff --git a/src/Domain/Input/Settings/Typography/Utilities/FontFace.php b/src/Domain/Input/Settings/Typography/Utilities/FontFace.php
index a20686f0..fca02c70 100644
--- a/src/Domain/Input/Settings/Typography/Utilities/FontFace.php
+++ b/src/Domain/Input/Settings/Typography/Utilities/FontFace.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Typography\Utilities;
-/**
- * @psalm-api
- */
class FontFace
{
private string $fontFamily;
@@ -17,8 +14,14 @@ class FontFace
private string $fontStretch;
+ /**
+ * @var string[]
+ */
private array $src;
+ /**
+ * @param string[] $src
+ */
public function __construct(
string $fontFamily,
string $fontWeight,
@@ -34,7 +37,7 @@ public function __construct(
}
/**
- * @return array{fontFamily: string, fontWeight: string, fontStyle: string, fontStretch: string, src: mixed[]}
+ * @return array{fontFamily: string, fontWeight: string, fontStyle: string, fontStretch: string, src: string[]}
*/
public function toArray(): array
{
diff --git a/src/Domain/Input/Settings/Utilities/CalcExperimental.php b/src/Domain/Input/Settings/Utilities/CalcExperimental.php
index 831da7ea..75a438cc 100644
--- a/src/Domain/Input/Settings/Utilities/CalcExperimental.php
+++ b/src/Domain/Input/Settings/Utilities/CalcExperimental.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Utilities;
-/**
- * @psalm-api
- */
class CalcExperimental
{
private string $value;
diff --git a/src/Domain/Input/Settings/Utilities/ClampExperimental.php b/src/Domain/Input/Settings/Utilities/ClampExperimental.php
index 0aeb4bae..4190deb3 100644
--- a/src/Domain/Input/Settings/Utilities/ClampExperimental.php
+++ b/src/Domain/Input/Settings/Utilities/ClampExperimental.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Utilities;
-/**
- * @psalm-api
- */
class ClampExperimental
{
private string $value;
diff --git a/src/Domain/Input/Settings/Utilities/DimensionExperimental.php b/src/Domain/Input/Settings/Utilities/DimensionExperimental.php
index 0d8f3962..38e55c0a 100644
--- a/src/Domain/Input/Settings/Utilities/DimensionExperimental.php
+++ b/src/Domain/Input/Settings/Utilities/DimensionExperimental.php
@@ -9,7 +9,6 @@
* https://github.com/pimlie/php-unit-conversion
* https://github.com/PhpUnitsOfMeasure/php-units-of-measure
* https://wiki.php.net/rfc/clamp
- * @psalm-api
*/
final class DimensionExperimental
{
diff --git a/src/Domain/Input/Settings/Utilities/SupportedUnitsExperimental.php b/src/Domain/Input/Settings/Utilities/SupportedUnitsExperimental.php
index f8cedace..a2b64930 100644
--- a/src/Domain/Input/Settings/Utilities/SupportedUnitsExperimental.php
+++ b/src/Domain/Input/Settings/Utilities/SupportedUnitsExperimental.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Utilities;
-/**
- * @psalm-api
- */
class SupportedUnitsExperimental implements UnitInterfaceExperimental
{
private array $units;
diff --git a/src/Domain/Input/Settings/Utilities/UnitInterfaceExperimental.php b/src/Domain/Input/Settings/Utilities/UnitInterfaceExperimental.php
index b661ce99..8f1900fc 100644
--- a/src/Domain/Input/Settings/Utilities/UnitInterfaceExperimental.php
+++ b/src/Domain/Input/Settings/Utilities/UnitInterfaceExperimental.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Utilities;
-/**
- * @psalm-api
- */
interface UnitInterfaceExperimental
{
/**
diff --git a/src/Domain/Input/Styles/ArrayableInterface.php b/src/Domain/Input/Styles/ArrayableInterface.php
index 08c18822..86dda03f 100644
--- a/src/Domain/Input/Styles/ArrayableInterface.php
+++ b/src/Domain/Input/Styles/ArrayableInterface.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles;
-/**
- * @psalm-api
- */
interface ArrayableInterface
{
/**
diff --git a/src/Domain/Input/Styles/Border.php b/src/Domain/Input/Styles/Border.php
index ef9893ed..ebbeb358 100644
--- a/src/Domain/Input/Styles/Border.php
+++ b/src/Domain/Input/Styles/Border.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles;
-/**
- * @psalm-api
- */
final class Border implements ArrayableInterface, \JsonSerializable
{
use CommonTrait;
diff --git a/src/Domain/Input/Styles/Color.php b/src/Domain/Input/Styles/Color.php
index 14fac358..9046f3ce 100644
--- a/src/Domain/Input/Styles/Color.php
+++ b/src/Domain/Input/Styles/Color.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles;
-/**
- * @psalm-api
- */
final class Color implements ArrayableInterface, \JsonSerializable
{
use CommonTrait;
diff --git a/src/Domain/Input/Styles/CommonTrait.php b/src/Domain/Input/Styles/CommonTrait.php
index e8219cfa..817258b5 100644
--- a/src/Domain/Input/Styles/CommonTrait.php
+++ b/src/Domain/Input/Styles/CommonTrait.php
@@ -21,7 +21,7 @@ trait CommonTrait
* @param array $properties
*/
public function __construct(
- PresetsInterface $presets = null,
+ ?PresetsInterface $presets = null,
array $properties = []
) {
$this->presets = $presets ?? new NullPresets();
@@ -66,17 +66,21 @@ public function property(string $property, string $value): self
*/
private function setProperty(string $key, string $value): self
{
- /**
- * @var PresetInterface|mixed $value
- */
$value = $this->presets->get($value, $value);
if ($value instanceof PresetInterface) {
$value = $value->var();
}
+ if (!\is_scalar($value) && !$value instanceof \Stringable) {
+ throw new \RuntimeException(\sprintf(
+ 'Expected style value to be stringable, got %s.',
+ \get_debug_type($value)
+ ));
+ }
+
/**
- * This prevents to return a string with the placeholder like this:
+ * This prevents returning a string with the placeholder like this:
* {{color.base}}
* instead we want to return the value of the placeholder like this:
* var(--wp--preset--color--base)
@@ -102,6 +106,9 @@ public function toArray(): array
return $result;
}
+ /**
+ * @return array
+ */
public function jsonSerialize(): array
{
return $this->toArray();
diff --git a/src/Domain/Input/Styles/Css.php b/src/Domain/Input/Styles/Css.php
index b8fbfa50..72b53f4d 100644
--- a/src/Domain/Input/Styles/Css.php
+++ b/src/Domain/Input/Styles/Css.php
@@ -17,7 +17,6 @@
* @link https://www.google.it/search?q=php+inline+css+content&sca_esv=596560865&ei=mAicZaTCGp3Axc8Pq7yT8AQ&ved=0ahUKEwik7p-Rgs6DAxUdYPEDHSveBE4Q4dUDCBA&uact=5&oq=php+inline+css+content&gs_lp=Egxnd3Mtd2l6LXNlcnAiFnBocCBpbmxpbmUgY3NzIGNvbnRlbnQyBRAhGKABMgUQIRigATIIECEYFhgeGB0yCBAhGBYYHhgdMggQIRgWGB4YHUjvogFQmgdYwJcBcAF4AZABAJgBsQGgAZkSqgEEMC4xOLgBA8gBAPgBAcICChAAGEcY1gQYsAPCAgoQABiABBiKBRhDwgIFEAAYgATCAgYQABgWGB7CAgcQABiABBgTwgIIEAAYFhgeGBPiAwQYACBBiAYBkAYI&sclient=gws-wiz-serp#ip=1
* @link https://github.com/topics/inline-css?l=php
*
- * @psalm-api
* @see CssTest
*/
class Css implements CssInterface
@@ -27,7 +26,7 @@ class Css implements CssInterface
private bool $shouldResolveVariables = true;
public function __construct(
- PresetsInterface $presets = null
+ ?PresetsInterface $presets = null
) {
$this->presets = $presets ?? new NullPresets();
}
@@ -158,7 +157,7 @@ private function duplicateRulesForSelectorList(string $css): string
$pattern = '/\{(.*)}/s';
\preg_match($pattern, $css, $matches);
- if (!isset($matches[1])) {
+ if (!isset($matches[0], $matches[1])) {
return $css;
}
diff --git a/src/Domain/Input/Styles/CssInterface.php b/src/Domain/Input/Styles/CssInterface.php
index ec55bbf5..ac3405a4 100644
--- a/src/Domain/Input/Styles/CssInterface.php
+++ b/src/Domain/Input/Styles/CssInterface.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles;
-/**
- * @psalm-api
- */
interface CssInterface
{
public const M_AMPERSAND_MUST_NOT_BE_AT_THE_BEGINNING = 'CSS cannot begin with an ampersand (&)';
diff --git a/src/Domain/Input/Styles/Outline.php b/src/Domain/Input/Styles/Outline.php
index ce42c3fe..ff80abcb 100644
--- a/src/Domain/Input/Styles/Outline.php
+++ b/src/Domain/Input/Styles/Outline.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles;
-/**
- * @psalm-api
- */
class Outline implements ArrayableInterface, \JsonSerializable
{
use CommonTrait;
diff --git a/src/Domain/Input/Styles/Scss.php b/src/Domain/Input/Styles/Scss.php
index a33f8cb8..3af4d1db 100644
--- a/src/Domain/Input/Styles/Scss.php
+++ b/src/Domain/Input/Styles/Scss.php
@@ -11,7 +11,6 @@
use ScssPhp\ScssPhp\OutputStyle;
/**
- * @psalm-api
* @see ScssTest
*/
class Scss implements CssInterface
@@ -28,7 +27,7 @@ class Scss implements CssInterface
public function __construct(
Css $css,
Compiler $compiler,
- PresetsInterface $presets = null
+ ?PresetsInterface $presets = null
) {
$this->css = $css;
$this->compiler = $compiler;
diff --git a/src/Domain/Input/Styles/Spacing.php b/src/Domain/Input/Styles/Spacing.php
index 52d9ddd3..2711cbbb 100644
--- a/src/Domain/Input/Styles/Spacing.php
+++ b/src/Domain/Input/Styles/Spacing.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles;
-/**
- * @psalm-api
- */
final class Spacing implements ArrayableInterface, \JsonSerializable
{
use CommonTrait;
@@ -60,6 +57,9 @@ public function left(string $value): self
* Three values => 10px auto 0px => 10px auto 0px auto
* Four values => 1px 2px 3px 4px => 1px 2px 3px 4px
*/
+ /**
+ * @param string[] $values
+ */
public function shorthand(array $values): self
{
switch (\count($values)) {
diff --git a/src/Domain/Input/Styles/Typography.php b/src/Domain/Input/Styles/Typography.php
index e9ea1048..fb8b3f40 100644
--- a/src/Domain/Input/Styles/Typography.php
+++ b/src/Domain/Input/Styles/Typography.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles;
-/**
- * @psalm-api
- */
final class Typography implements ArrayableInterface, \JsonSerializable
{
use CommonTrait;
diff --git a/src/Domain/Output/Events/DryRunMode.php b/src/Domain/Output/Events/DryRunMode.php
deleted file mode 100644
index e46f3066..00000000
--- a/src/Domain/Output/Events/DryRunMode.php
+++ /dev/null
@@ -1,15 +0,0 @@
-file = $file;
- $this->exception = $exception;
- }
-
- public function getFile(): string
- {
- return $this->file;
- }
-
- public function getException(): \Throwable
- {
- return $this->exception;
- }
-}
diff --git a/src/Domain/Output/Events/EntryPointCreated.php b/src/Domain/Output/Events/EntryPointCreated.php
deleted file mode 100644
index 48993dc2..00000000
--- a/src/Domain/Output/Events/EntryPointCreated.php
+++ /dev/null
@@ -1,23 +0,0 @@
-file = $file;
- }
-
- public function getFile(): string
- {
- return $this->file;
- }
-}
diff --git a/src/Domain/Output/Events/EntryPointDoesNotExist.php b/src/Domain/Output/Events/EntryPointDoesNotExist.php
deleted file mode 100644
index f499d840..00000000
--- a/src/Domain/Output/Events/EntryPointDoesNotExist.php
+++ /dev/null
@@ -1,23 +0,0 @@
-file = $file;
- }
-
- public function getFile(): string
- {
- return $this->file;
- }
-}
diff --git a/src/Domain/Output/Events/GeneratedFile.php b/src/Domain/Output/Events/GeneratedFile.php
deleted file mode 100644
index f8a0119c..00000000
--- a/src/Domain/Output/Events/GeneratedFile.php
+++ /dev/null
@@ -1,23 +0,0 @@
-file = $file;
- }
-
- public function getFileName(): string
- {
- return $this->file;
- }
-}
diff --git a/src/Domain/Output/Events/GeneratingFile.php b/src/Domain/Output/Events/GeneratingFile.php
deleted file mode 100644
index 1ce696ed..00000000
--- a/src/Domain/Output/Events/GeneratingFile.php
+++ /dev/null
@@ -1,23 +0,0 @@
-file = $file;
- }
-
- public function getFileName(): string
- {
- return $this->file;
- }
-}
diff --git a/src/Domain/Output/Events/NoFileFound.php b/src/Domain/Output/Events/NoFileFound.php
deleted file mode 100644
index 16b3196e..00000000
--- a/src/Domain/Output/Events/NoFileFound.php
+++ /dev/null
@@ -1,20 +0,0 @@
-file = $file;
- }
-
- public function getFile(): \SplFileInfo
- {
- return $this->file;
- }
-}
diff --git a/src/Domain/Output/Events/ValidatedFails.php b/src/Domain/Output/Events/ValidatedFails.php
deleted file mode 100644
index 9c4d060f..00000000
--- a/src/Domain/Output/Events/ValidatedFails.php
+++ /dev/null
@@ -1,31 +0,0 @@
-file = $file;
- $this->errors = $errors;
- }
-
- public function getFile(): \SplFileInfo
- {
- return $this->file;
- }
-
- public function getErrors(): array
- {
- return $this->errors;
- }
-}
diff --git a/src/Domain/Output/Events/ValidatingFile.php b/src/Domain/Output/Events/ValidatingFile.php
deleted file mode 100644
index f74de399..00000000
--- a/src/Domain/Output/Events/ValidatingFile.php
+++ /dev/null
@@ -1,23 +0,0 @@
-file = $file;
- }
-
- public function getFile(): \SplFileInfo
- {
- return $this->file;
- }
-}
diff --git a/src/Domain/Output/Validate.php b/src/Domain/Output/Validate.php
deleted file mode 100644
index a123f232..00000000
--- a/src/Domain/Output/Validate.php
+++ /dev/null
@@ -1,74 +0,0 @@
-validator = $validator;
- $this->filesFinder = $filesFinder;
- $this->dispatcher = $dispatcher;
- $this->compiler = $compiler;
- }
-
- public function handle(object $message): int
- {
- /** @var ValidateMessage $message */
- foreach ($this->filesFinder->find($message->getRootFolder(), 'json') as $file) {
- $this->dispatcher->dispatch(new ValidatingFile($file));
- $this->validateJsonFile($file, $message->getSchemaPath());
- $this->validator->reset();
- /**
- * @todo Implementing scss validation
- */
- $this->compiler->compileString('');
- }
-
- return 0;
- }
-
- private function validateJsonFile(
- \SplFileInfo $file,
- string $schemaPath
- ): void {
- $data = $this->objectFromPath((string)$file);
- $this->validator->validate($data, (object)['$ref' => 'file://' . \realpath($schemaPath)]);
-
- if (!$this->validator->isValid()) {
- $this->dispatcher->dispatch(new ValidatedFails($file, (array)$this->validator->getErrors()));
- return;
- }
-
- $this->dispatcher->dispatch(new ValidFile($file));
- }
-}
diff --git a/src/Helper/ConvertCase.php b/src/Infrastructure/Filesystem/ConvertCase.php
similarity index 88%
rename from src/Helper/ConvertCase.php
rename to src/Infrastructure/Filesystem/ConvertCase.php
index 55690b10..a345a156 100644
--- a/src/Helper/ConvertCase.php
+++ b/src/Infrastructure/Filesystem/ConvertCase.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace ItalyStrap\ThemeJsonGenerator\Helper;
+namespace ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem;
use function preg_replace;
use function strtolower;
diff --git a/src/Application/Commands/Utils/DataFromJsonTrait.php b/src/Infrastructure/Filesystem/DataFromJsonTrait.php
similarity index 91%
rename from src/Application/Commands/Utils/DataFromJsonTrait.php
rename to src/Infrastructure/Filesystem/DataFromJsonTrait.php
index 4bb9b56a..70e76dc1 100644
--- a/src/Application/Commands/Utils/DataFromJsonTrait.php
+++ b/src/Infrastructure/Filesystem/DataFromJsonTrait.php
@@ -2,10 +2,13 @@
declare(strict_types=1);
-namespace ItalyStrap\ThemeJsonGenerator\Application\Commands\Utils;
+namespace ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem;
trait DataFromJsonTrait
{
+ /**
+ * @return array
+ */
private function associativeFromPath(string $path): array
{
return (array)$this->fromPath($path, true);
diff --git a/src/Infrastructure/Filesystem/FileWriter.php b/src/Infrastructure/Filesystem/FileWriter.php
index c076d937..cf795e13 100644
--- a/src/Infrastructure/Filesystem/FileWriter.php
+++ b/src/Infrastructure/Filesystem/FileWriter.php
@@ -9,6 +9,7 @@
interface FileWriter
{
/**
+ * @param ConfigInterface $data
* @throws \Exception
*/
public function write(ConfigInterface $data): void;
diff --git a/src/Infrastructure/Filesystem/FilesExtension.php b/src/Infrastructure/Filesystem/FilesExtension.php
index 965a75b8..252f8a01 100644
--- a/src/Infrastructure/Filesystem/FilesExtension.php
+++ b/src/Infrastructure/Filesystem/FilesExtension.php
@@ -4,9 +4,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem;
-/**
- * @psalm-api
- */
final class FilesExtension
{
public const PHP = '.php';
diff --git a/src/Infrastructure/Filesystem/FilesFinder.php b/src/Infrastructure/Filesystem/FilesFinder.php
index 1a028e80..f51c0e67 100644
--- a/src/Infrastructure/Filesystem/FilesFinder.php
+++ b/src/Infrastructure/Filesystem/FilesFinder.php
@@ -6,9 +6,6 @@
use ItalyStrap\Finder\FinderInterface;
-/**
- * @psalm-api
- */
class FilesFinder
{
public const ROOT_FILE_NAME = 'theme';
@@ -71,7 +68,7 @@ public function find(
public function resolveJsonFile(\SplFileInfo $file): string
{
$fileName = $this->extractFileName($file);
- $themeRoot = \getcwd();
+ $themeRoot = (string)\getcwd();
$stylesFolder = '';
if ($fileName !== self::ROOT_FILE_NAME) {
$stylesFolder = self::STYLES_FOLDER;
@@ -87,6 +84,10 @@ public function resolveJsonFile(\SplFileInfo $file): string
}
$styleCssContent = \file_get_contents($styleCss);
+ if ($styleCssContent === false) {
+ throw new \RuntimeException('Unable to read the style.css file');
+ }
+
if (\strpos($styleCssContent, 'Theme Name:') === false) {
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 90d60381..a4ba15a0 100644
--- a/src/Infrastructure/Filesystem/JsonFileWriter.php
+++ b/src/Infrastructure/Filesystem/JsonFileWriter.php
@@ -20,6 +20,7 @@ public function __construct(string $path)
}
/**
+ * @param ConfigInterface $data
* @throws \Exception
*/
public function write(ConfigInterface $data): void
diff --git a/src/Infrastructure/Filesystem/ScssFileWriter.php b/src/Infrastructure/Filesystem/ScssFileWriter.php
index 7d2ccae3..bcb740ec 100644
--- a/src/Infrastructure/Filesystem/ScssFileWriter.php
+++ b/src/Infrastructure/Filesystem/ScssFileWriter.php
@@ -5,7 +5,6 @@
namespace ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem;
use ItalyStrap\Config\ConfigInterface;
-use ItalyStrap\ThemeJsonGenerator\Helper\ConvertCase;
use Webimpress\SafeWriter;
class ScssFileWriter implements FileWriter
@@ -22,6 +21,9 @@ public function __construct(string $path)
$this->path = $path;
}
+ /**
+ * @param ConfigInterface $data
+ */
public function write(ConfigInterface $data): void
{
if (\count($data) === 0) {
@@ -36,7 +38,7 @@ public function write(ConfigInterface $data): void
}
/**
- * @param ConfigInterface $data
+ * @param ConfigInterface $data
* @return string
*/
private function generateScssContent(ConfigInterface $data): string
diff --git a/src/Infrastructure/Handler/ConsoleHandler.php b/src/Infrastructure/Handler/ConsoleHandler.php
new file mode 100644
index 00000000..c5dc3f04
--- /dev/null
+++ b/src/Infrastructure/Handler/ConsoleHandler.php
@@ -0,0 +1,43 @@
+pipeline = new Pipeline(
+ new CallbackHandler(
+ static fn (object $message): int => self::SUCCESS
+ ),
+ ...$middleware,
+ );
+ }
+
+ public function handle(object $message): int
+ {
+ $result = $this->pipeline->handle($message);
+
+ if (!is_int($result)) {
+ throw new \RuntimeException(\sprintf(
+ 'Expected middleware to return an int exit code, got %s',
+ get_debug_type($result),
+ ));
+ }
+
+ return $result;
+ }
+}
diff --git a/src/ModuleApplication.php b/src/ModuleApplication.php
new file mode 100644
index 00000000..f11de8d4
--- /dev/null
+++ b/src/ModuleApplication.php
@@ -0,0 +1,75 @@
+>
+ */
+ public function __invoke(): array
+ {
+ return [
+ AurynConfig::FACTORIES => [
+ InitCommand::class => function (ContainerInterface $container): InitCommand {
+ return new InitCommand(new ConsoleHandler(
+ $this->middleware($container, Init::class)
+ ));
+ },
+ DumpCommand::class => function (ContainerInterface $container): DumpCommand {
+ return new DumpCommand(new ConsoleHandler(
+ $this->middleware($container, Dump::class),
+ ));
+ },
+ ValidateCommand::class => function (ContainerInterface $container): ValidateCommand {
+ return new ValidateCommand(new ConsoleHandler(
+ new DeleteSchemaJson(),
+ new SchemaJson(),
+ $this->middleware($container, Validate::class)
+ ));
+ },
+ InfoCommand::class => function (ContainerInterface $container): InfoCommand {
+ return new InfoCommand(new ConsoleHandler(
+ $this->middleware($container, Info::class)
+ ));
+ },
+ ],
+ ];
+ }
+
+ /**
+ * @param class-string $id
+ */
+ private function middleware(ContainerInterface $container, string $id): MiddlewareInterface
+ {
+ $middleware = $container->get($id);
+ if (!$middleware instanceof MiddlewareInterface) {
+ throw new \RuntimeException(\sprintf(
+ 'Expected container entry %s to be an instance of %s, got %s.',
+ $id,
+ MiddlewareInterface::class,
+ \get_debug_type($middleware)
+ ));
+ }
+
+ return $middleware;
+ }
+}
diff --git a/src/ModuleInfrastructure.php b/src/ModuleInfrastructure.php
new file mode 100644
index 00000000..84bd9990
--- /dev/null
+++ b/src/ModuleInfrastructure.php
@@ -0,0 +1,34 @@
+
+ */
+ public function __invoke(): array
+ {
+ return [
+ AurynConfig::ALIASES => [
+ FinderInterface::class => Finder::class,
+ EventDispatcherInterface::class => \Symfony\Component\EventDispatcher\EventDispatcher::class,
+ ],
+ AurynConfig::SHARING => [
+ EventDispatcherInterface::class,
+ \Symfony\Component\EventDispatcher\EventDispatcher::class
+ ],
+ AurynConfig::FACTORIES => [
+ Finder::class => static fn (): FinderInterface => (new FinderFactory())->make(),
+ ],
+ ];
+ }
+}
diff --git a/stubs/auryn-injector.stub b/stubs/auryn-injector.stub
new file mode 100644
index 00000000..cec6213d
--- /dev/null
+++ b/stubs/auryn-injector.stub
@@ -0,0 +1,18 @@
+ $args
+ * @return ($name is class-string ? T : mixed)
+ */
+ public function make($name, array $args = array())
+ {
+ }
+}
diff --git a/tests/.env b/tests/.env
index 78484b7c..d5f17d0c 100644
--- a/tests/.env
+++ b/tests/.env
@@ -1,7 +1,7 @@
# Codeception configuration file
ROOT_FOLDER="../../../"
-DB_HOST="localhost"
+DB_HOST="mysql"
DB_NAME="test"
DB_USER="root"
DB_PASSWORD="root"
@@ -9,4 +9,4 @@ DB_PASSWORD="root"
TABLE_PREFIX="wp_"
DOMAIN="localhost"
-ADMIN_EMAIL="admin@localhost.test"
\ No newline at end of file
+ADMIN_EMAIL="admin@localhost.test"
diff --git a/tests/_data/fixtures/advanced-example.json.php b/tests/_data/fixtures/advanced-example.json.php
index 607a37ab..4d6d203e 100644
--- a/tests/_data/fixtures/advanced-example.json.php
+++ b/tests/_data/fixtures/advanced-example.json.php
@@ -4,8 +4,8 @@
namespace ItalyStrap\Tests;
-use ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson;
-use ItalyStrap\ThemeJsonGenerator\Domain\Input\SectionNames;
+use ItalyStrap\ThemeJsonGenerator\Api\SectionNames;
+use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Duotone;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Gradient;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Palette;
diff --git a/tests/_data/fixtures/basic-example.json.php b/tests/_data/fixtures/basic-example.json.php
index 68e0e834..9a2fc2a1 100644
--- a/tests/_data/fixtures/basic-example.json.php
+++ b/tests/_data/fixtures/basic-example.json.php
@@ -4,8 +4,8 @@
namespace ItalyStrap\Tests;
-use ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson;
-use ItalyStrap\ThemeJsonGenerator\Domain\Input\SectionNames;
+use ItalyStrap\ThemeJsonGenerator\Api\SectionNames;
+use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson;
return static function (ThemeJson $themeJson): void {
$themeJson->merge([
diff --git a/tests/_data/fixtures/input-data.php b/tests/_data/fixtures/input-data.php
index 777fdc21..1639b21b 100644
--- a/tests/_data/fixtures/input-data.php
+++ b/tests/_data/fixtures/input-data.php
@@ -4,7 +4,7 @@
namespace ItalyStrap\Tests;
-use ItalyStrap\ThemeJsonGenerator\Domain\Input\SectionNames;
+use ItalyStrap\ThemeJsonGenerator\Api\SectionNames;
return [
SectionNames::VERSION => 1,
diff --git a/tests/functional/CommandsCest.php b/tests/functional/CommandsCest.php
index 0bffbd09..ffde386d 100644
--- a/tests/functional/CommandsCest.php
+++ b/tests/functional/CommandsCest.php
@@ -6,7 +6,7 @@
use FunctionalTester;
use ItalyStrap\Tests\FunctionalTestCase;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Events\NoFileFound;
+use ItalyStrap\ThemeJsonGenerator\Application\Middlewares\Dump;
class CommandsCest extends FunctionalTestCase
{
@@ -20,7 +20,7 @@ public function testDump(FunctionalTester $i): void
// $i->runShellCommand('bin/theme-json dump --file="theme.json"');
// $i->runShellCommand('bin/theme-json dump --path="tests"');
// $i->runShellCommand('bin/theme-json dump --path="tests/_data/fixtures/themes/theme-flat/"');
- $i->dontSeeInShellOutput(NoFileFound::M_NO_FILE_FOUND);
+ $i->dontSeeInShellOutput(Dump::M_NO_FILE_FOUND);
$i->seeResultCodeIs(0);
}
diff --git a/tests/integration.suite.yml b/tests/integration.suite.yml
index 4155150b..83657c16 100644
--- a/tests/integration.suite.yml
+++ b/tests/integration.suite.yml
@@ -2,16 +2,13 @@ actor: IntegrationTester
modules:
enabled:
- Asserts
- - WPLoader
+ - lucatume\WPBrowser\Module\WPLoader
- \Helper\Integration
config:
- WPLoader:
+ lucatume\WPBrowser\Module\WPLoader:
wpRootFolder: "%ROOT_FOLDER%"
- dbName: "%DB_NAME%"
- dbHost: "%DB_HOST%"
- dbUser: "%DB_USER%"
- dbPassword: "%DB_PASSWORD%"
+ dbUrl: "mysql://%DB_USER%:%DB_PASSWORD%@%DB_HOST%/%DB_NAME%"
tablePrefix: "%TABLE_PREFIX%"
domain: "%DOMAIN%"
adminEmail: "%ADMIN_EMAIL%"
- title: "Test"
\ No newline at end of file
+ title: "Test"
diff --git a/tests/src/IntegrationTestCase.php b/tests/src/IntegrationTestCase.php
index f931c3a7..52be6099 100644
--- a/tests/src/IntegrationTestCase.php
+++ b/tests/src/IntegrationTestCase.php
@@ -4,11 +4,11 @@
namespace ItalyStrap\Tests;
-use Codeception\TestCase\WPTestCase;
+use lucatume\WPBrowser\TestCase\WPTestCase;
class IntegrationTestCase extends WPTestCase
{
- protected \IntegrationTester $tester;
+ protected $tester;
protected function setUp(): void
{
diff --git a/tests/unit/Application/Config/ThemeJsonTest.php b/tests/unit/Api/ThemeJsonTest.php
similarity index 95%
rename from tests/unit/Application/Config/ThemeJsonTest.php
rename to tests/unit/Api/ThemeJsonTest.php
index 74b5bd17..0d0413e0 100644
--- a/tests/unit/Application/Config/ThemeJsonTest.php
+++ b/tests/unit/Api/ThemeJsonTest.php
@@ -2,10 +2,10 @@
declare(strict_types=1);
-namespace ItalyStrap\Tests\Unit\Application\Config;
+namespace ItalyStrap\Tests\Unit\Api;
use ItalyStrap\Tests\UnitTestCase;
-use ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson;
+use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson;
class ThemeJsonTest extends UnitTestCase
{
diff --git a/tests/unit/Application/Commands/Middleware/SchemaJsonMiddlewareTest.php b/tests/unit/Application/Commands/Middleware/SchemaJsonMiddlewareTest.php
deleted file mode 100644
index 3fad09f8..00000000
--- a/tests/unit/Application/Commands/Middleware/SchemaJsonMiddlewareTest.php
+++ /dev/null
@@ -1,50 +0,0 @@
-makeInstance();
- $this->assertInstanceOf(SchemaJsonMiddleware::class, $actual);
- }
-
- public function testProcess()
- {
- $message = new class {
- public function getSchemaPath(): string
- {
- return \codecept_output_dir('theme.schema.json');
- }
- };
-
- $handler = new class implements \ItalyStrap\Bus\HandlerInterface {
- public function handle(object $message): int
- {
- return 1;
- }
- };
-
- if (\file_exists($message->getSchemaPath())) {
- $this->tester->deleteFile($message->getSchemaPath());
- }
- $this->tester->writeToFile($message->getSchemaPath(), '{}');
-
- $actual = $this->makeInstance();
- $this->assertIsInt($actual->process($message, $handler));
- $this->assertSame(1, $actual->process($message, $handler));
-
- $this->tester->deleteFile($message->getSchemaPath());
- }
-}
diff --git a/tests/unit/Application/Middlewares/SchemaJsonTest.php b/tests/unit/Application/Middlewares/SchemaJsonTest.php
new file mode 100644
index 00000000..6f02f45c
--- /dev/null
+++ b/tests/unit/Application/Middlewares/SchemaJsonTest.php
@@ -0,0 +1,42 @@
+tester->deleteFile($schemaPath);
+ }
+ $this->tester->writeToFile($schemaPath, '{}');
+
+ $actual = $this->makeInstance();
+ $this->assertIsInt($actual->process($message, $handler));
+ $this->assertSame(1, $actual->process($message, $handler));
+
+ $this->tester->deleteFile($schemaPath);
+ }
+}
diff --git a/tests/unit/Bus/BusHandlerProviderTest.php b/tests/unit/Bus/BusHandlerProviderTest.php
deleted file mode 100644
index 52d513d9..00000000
--- a/tests/unit/Bus/BusHandlerProviderTest.php
+++ /dev/null
@@ -1,136 +0,0 @@
-getMessage();
- }
- };
- }
-
- private function makeMessage2(): object
- {
- static $message;
- if ($message) {
- return $message;
- }
-
- $message = new class {
- public function getMessage(): string
- {
- return 'World';
- }
- };
-
- return $message;
- }
-
- private function makeHandler2(): HandlerInterface
- {
- return new class implements HandlerInterface {
- public function handle(object $message): string
- {
- return $message->getMessage();
- }
- };
- }
-
- private function makeHandlerProvider(): HandlerInterface
- {
- return new class implements HandlerInterface {
- private array $handlers = [];
-
- /**
- * @param class-string $messageName
- */
- public function addHandler(HandlerInterface $handler, string $messageName): void
- {
- $this->handlers[$messageName] = $handler;
- }
-
- public function getHandlerForCommand(object $message): HandlerInterface
- {
- $messageClass = \get_class($message);
- if (\array_key_exists($messageClass, $this->handlers)) {
- return $this->handlers[$messageClass];
- }
-
- throw new \InvalidArgumentException(\sprintf(
- 'No handler for message %s',
- $messageClass
- ));
- }
-
- /**
- * @return mixed
- */
- public function handle(object $message)
- {
- return $this->getHandlerForCommand($message)->handle($message);
- }
- };
- }
-
- private array $handlers = [];
-
- private function makeInstance(): Bus
- {
- $handlerProvider = $this->makeHandlerProvider();
- foreach ($this->handlers as $messageName => $handler) {
- $handlerProvider->addHandler($handler, $messageName);
- }
-
- return new Bus($handlerProvider);
- }
-
- public function testMessage1(): void
- {
- $this->handlers[\get_class($this->makeMessage1())] = $this->makeHandler1();
-
- $sut = $this->makeInstance();
-
- $result = $sut->handle($this->makeMessage1());
-
- $this->assertSame('Hello', $result);
- }
-
- public function testMessage2(): void
- {
- $this->handlers[\get_class($this->makeMessage2())] = $this->makeHandler2();
-
- $sut = $this->makeInstance();
-
- $result = $sut->handle($this->makeMessage2());
-
- $this->assertSame('World', $result);
- }
-}
diff --git a/tests/unit/Bus/BusTest.php b/tests/unit/Bus/BusTest.php
deleted file mode 100644
index 14643506..00000000
--- a/tests/unit/Bus/BusTest.php
+++ /dev/null
@@ -1,78 +0,0 @@
-getMessage();
- return 1;
- }
- });
- }
-
- public function testItShouldDoSomething(): void
- {
- $sut = $this->makeInstance();
-
- $order = [];
- $sut->addMiddleware(new class ($order) implements MiddlewareInterface {
- private array $order;
-
- public function __construct(array &$order)
- {
- $this->order = &$order;
- }
-
- public function process(object $message, HandlerInterface $handler)
- {
- $this->order[] = 'Generate';
- return $handler->handle($message);
- }
- });
-
- $sut->addMiddleware(new class ($order) implements MiddlewareInterface {
- private array $order;
-
- public function __construct(array &$order)
- {
- $this->order = &$order;
- }
-
- public function process(object $message, HandlerInterface $handler)
- {
- $this->order[] = 'Validate';
- return $handler->handle($message);
- }
- });
-
- $result = $sut->handle(new class ($order) {
- private array $order;
-
- public function __construct(array &$order)
- {
- $this->order = &$order;
- }
-
- public function getMessage(): string
- {
- $this->order[] = 'Handler called';
- return 'Hello World';
- }
- });
-
- $this->assertSame(1, $result);
- $this->assertSame(['Generate', 'Validate', 'Handler called'], $order);
- }
-}
diff --git a/tests/unit/Bus/DecorateBusTest.php b/tests/unit/Bus/DecorateBusTest.php
deleted file mode 100644
index 9896b5f4..00000000
--- a/tests/unit/Bus/DecorateBusTest.php
+++ /dev/null
@@ -1,43 +0,0 @@
-getMessage() === 'Hello') {
- return $handler->handle($message);
- }
-
- return 0;
- }
- },
- new class implements \ItalyStrap\Bus\HandlerInterface {
- public function handle(object $message): int
- {
- return 1;
- }
- }
- ));
-
- $result = $sut->handle(new class {
- public function getMessage(): string
- {
- return 'Hello';
- }
- });
-
- $this->assertSame(1, $result);
- }
-}
diff --git a/tests/unit/Domain/Input/Styles/CommonTests.php b/tests/unit/Domain/Input/Styles/CommonTests.php
index 7be76aca..d2b65860 100644
--- a/tests/unit/Domain/Input/Styles/CommonTests.php
+++ b/tests/unit/Domain/Input/Styles/CommonTests.php
@@ -4,8 +4,8 @@
namespace ItalyStrap\Tests\Unit\Domain\Input\Styles;
-use ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson;
-use ItalyStrap\ThemeJsonGenerator\Domain\Input\SectionNames;
+use ItalyStrap\ThemeJsonGenerator\Api\SectionNames;
+use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\CommonTrait;
trait CommonTests
diff --git a/tests/unit/Domain/Output/DumpTest.php b/tests/unit/Domain/Output/DumpTest.php
index 905d6fb7..f85b4d10 100644
--- a/tests/unit/Domain/Output/DumpTest.php
+++ b/tests/unit/Domain/Output/DumpTest.php
@@ -4,10 +4,10 @@
namespace ItalyStrap\Tests\Unit\Domain\Output;
-use ItalyStrap\Config\Config;
+use ItalyStrap\Pipeline\CallbackHandler;
use ItalyStrap\Tests\UnitTestCase;
use ItalyStrap\ThemeJsonGenerator\Application\DumpMessage;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Dump;
+use ItalyStrap\ThemeJsonGenerator\Application\Middlewares\Dump;
use Prophecy\Argument;
class DumpTest extends UnitTestCase
@@ -15,13 +15,15 @@ class DumpTest extends UnitTestCase
private function makeInstance(): Dump
{
return new Dump(
- $this->makeDispatcher(),
- // $this->makeConfig(),
- new Config(),
$this->makeFilesFinder(),
);
}
+ private function makeHandler(): CallbackHandler
+ {
+ return new CallbackHandler(static fn (object $message): int => 0);
+ }
+
public function testItShouldHandleButDoNothing(): void
{
$this->filesFinder
@@ -29,7 +31,7 @@ public function testItShouldHandleButDoNothing(): void
->willReturn([])
->shouldBeCalledOnce();
- $this->makeInstance()->handle(new DumpMessage('', '', false, ''));
+ $this->makeInstance()->process(new DumpMessage('', '', false, ''), $this->makeHandler());
}
public function testItShouldBasicExample(): void
@@ -45,7 +47,7 @@ public function testItShouldBasicExample(): void
->resolveJsonFile($basicExample)
->willReturn(\codecept_data_dir('fixtures/basic-example.json'));
- $this->makeInstance()->handle(new DumpMessage('', '', false, ''));
+ $this->makeInstance()->process(new DumpMessage('', '', false, ''), $this->makeHandler());
$generatedFile = new \SplFileInfo(\codecept_data_dir('fixtures/basic-example.json'));
$this->assertFileExists($generatedFile->getPathname(), 'The file was not generated');
@@ -66,7 +68,7 @@ public function testItShouldAdvancedExample(): void
->resolveJsonFile($advancedExample)
->willReturn(\codecept_data_dir('fixtures/advanced-example.json'));
- $this->makeInstance()->handle(new DumpMessage('', '', false, ''));
+ $this->makeInstance()->process(new DumpMessage('', '', false, ''), $this->makeHandler());
$generatedFile = new \SplFileInfo(\codecept_data_dir('fixtures/advanced-example.json'));
$this->assertFileExists($generatedFile->getPathname(), 'The file was not generated');
diff --git a/tests/unit/Domain/Output/InitTest.php b/tests/unit/Domain/Output/InitTest.php
index 5b9dd8a9..10ea58c8 100644
--- a/tests/unit/Domain/Output/InitTest.php
+++ b/tests/unit/Domain/Output/InitTest.php
@@ -4,9 +4,10 @@
namespace ItalyStrap\Tests\Unit\Domain\Output;
+use ItalyStrap\Pipeline\CallbackHandler;
use ItalyStrap\Tests\UnitTestCase;
-use ItalyStrap\ThemeJsonGenerator\Application\InitMessage;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Init;
+use ItalyStrap\ThemeJsonGenerator\Application\Message;
+use ItalyStrap\ThemeJsonGenerator\Application\Middlewares\Init;
use Prophecy\Argument;
class InitTest extends UnitTestCase
@@ -14,11 +15,15 @@ class InitTest extends UnitTestCase
private function makeInstance(): Init
{
return new Init(
- $this->makeDispatcher(),
$this->makeFilesFinder(),
);
}
+ private function makeHandler(): CallbackHandler
+ {
+ return new CallbackHandler(static fn (object $message): int => 0);
+ }
+
public function testItShouldHandleButDoNothing(): void
{
$this->filesFinder
@@ -26,6 +31,6 @@ public function testItShouldHandleButDoNothing(): void
->willReturn([])
->shouldBeCalledOnce();
- $this->makeInstance()->handle(new InitMessage('', ''));
+ $this->makeInstance()->process(new Message(''), $this->makeHandler());
}
}
diff --git a/tests/unit/Domain/Output/ValidateTest.php b/tests/unit/Domain/Output/ValidateTest.php
index f9412cd1..f1edabd7 100644
--- a/tests/unit/Domain/Output/ValidateTest.php
+++ b/tests/unit/Domain/Output/ValidateTest.php
@@ -4,9 +4,10 @@
namespace ItalyStrap\Tests\Unit\Domain\Output;
+use ItalyStrap\Pipeline\CallbackHandler;
use ItalyStrap\Tests\UnitTestCase;
+use ItalyStrap\ThemeJsonGenerator\Application\Middlewares\Validate;
use ItalyStrap\ThemeJsonGenerator\Application\ValidateMessage;
-use ItalyStrap\ThemeJsonGenerator\Domain\Output\Validate;
use Prophecy\Argument;
class ValidateTest extends UnitTestCase
@@ -14,13 +15,17 @@ class ValidateTest extends UnitTestCase
private function makeInstance(): Validate
{
return new Validate(
- $this->makeDispatcher(),
$this->makeValidator(),
$this->makeCompiler(),
$this->makeFilesFinder()
);
}
+ private function makeHandler(): CallbackHandler
+ {
+ return new CallbackHandler(static fn (object $message): int => 0);
+ }
+
public function testItShouldHandleButDoNothing(): void
{
$this->filesFinder
@@ -28,6 +33,6 @@ public function testItShouldHandleButDoNothing(): void
->willReturn([])
->shouldBeCalledOnce();
- $this->makeInstance()->handle(new ValidateMessage('', ''));
+ $this->makeInstance()->process(new ValidateMessage('', ''), $this->makeHandler());
}
}
diff --git a/tests/unit/Infrastructure/Filesystem/JsonFileWriterIntegrationTest.php b/tests/unit/Infrastructure/Filesystem/JsonFileWriterIntegrationTest.php
index 52bdc1ff..c42c0eaf 100644
--- a/tests/unit/Infrastructure/Filesystem/JsonFileWriterIntegrationTest.php
+++ b/tests/unit/Infrastructure/Filesystem/JsonFileWriterIntegrationTest.php
@@ -5,11 +5,11 @@
namespace ItalyStrap\Tests\Unit\Infrastructure\Filesystem;
use ItalyStrap\Tests\UnitTestCase;
-use ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson;
-use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Presets;
+use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Palette;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities\Color;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Color\Utilities\ColorModifier;
+use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Presets;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\Color as StylesColor;
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Styles\Typography;
use ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem\JsonFileWriter;
diff --git a/tests/unit/Infrastructure/Filesystem/JsonFileWriterTest.php b/tests/unit/Infrastructure/Filesystem/JsonFileWriterTest.php
index 778349e7..b694455a 100644
--- a/tests/unit/Infrastructure/Filesystem/JsonFileWriterTest.php
+++ b/tests/unit/Infrastructure/Filesystem/JsonFileWriterTest.php
@@ -4,9 +4,8 @@
namespace ItalyStrap\Tests\Unit\Infrastructure\Filesystem;
-use ItalyStrap\Config\Config;
use ItalyStrap\Tests\UnitTestCase;
-use ItalyStrap\ThemeJsonGenerator\Application\Config\ThemeJson;
+use ItalyStrap\ThemeJsonGenerator\Api\ThemeJson;
use ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem\JsonFileWriter;
class JsonFileWriterTest extends UnitTestCase