Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
paths:
- '**workflows/static-analysis.yml'
- '**.php'
- '**psalm.xml'
- '**phpstan.neon'
- '**composer.json'

jobs:
Expand All @@ -27,5 +27,5 @@ jobs:

- uses: ramsey/composer-install@v3

- name: Psalm
run: vendor/bin/psalm
- name: PHPStan
run: composer stan
22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion bin/theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace ItalyStrap\ThemeJsonGenerator;

/** @psalm-suppress UnresolvableInclude */
require $_composer_autoload_path ?? __DIR__ . '/../vendor/autoload.php';

$bootstrap = new Bootstrap();
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"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",
Expand Down Expand Up @@ -97,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"
Expand All @@ -125,7 +125,7 @@
],
"qa": [
"@cs",
"@psalm",
"@stan",
"@rector",
"@unit"
],
Expand All @@ -145,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",
Expand Down
13 changes: 13 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
parameters:
level: 9
paths:
- bin
- functions
- src
stubFiles:
- stubs/auryn-injector.stub
excludePaths:
analyse:
- src/**/*Experimental*.php
parallel:
maximumNumberOfProcesses: 1
21 changes: 0 additions & 21 deletions psalm.xml

This file was deleted.

3 changes: 0 additions & 3 deletions src/Api/SectionNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace ItalyStrap\ThemeJsonGenerator\Api;

/**
* @psalm-api
*/
final class SectionNames
{
/**
Expand Down
15 changes: 12 additions & 3 deletions src/Api/ThemeJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
use ItalyStrap\ThemeJsonGenerator\Domain\Input\Settings\Typography\FontSize;

/**
* @psalm-api
* @template TKey as array-key
* @template TValue
* @template-extends Config<TKey,TValue>
* @psalm-suppress DeprecatedInterface
*/
final class ThemeJson extends Config implements \JsonSerializable
{
Expand All @@ -34,16 +32,25 @@ public function appendGlobalCss(string $css): bool
return $this->set(SectionNames::STYLES . '.css', $currentCss . $css);
}

/**
* @param array<string, mixed> $config
*/
public function setElementStyle(string $elementName, array $config): bool
{
return $this->set(SectionNames::STYLES . '.elements.' . $elementName, $config);
}

/**
* @param array<string, mixed> $config
*/
public function setBlockSettings(string $blockName, array $config): bool
{
return $this->set(SectionNames::SETTINGS . '.blocks.' . $blockName, $config);
}

/**
* @param array<string, mixed> $config
*/
public function setBlockStyle(string $blockName, array $config): bool
{
return $this->set(SectionNames::STYLES . '.blocks.' . $blockName, $config);
Expand All @@ -68,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;
Expand All @@ -78,6 +84,9 @@ public function setPresets(PresetsInterface $presets): bool
return true;
}

/**
* @return array<array-key, mixed>
*/
public function jsonSerialize(): array
{
return $this->getArrayCopy();
Expand Down
20 changes: 10 additions & 10 deletions src/Application/Commands/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@

namespace ItalyStrap\ThemeJsonGenerator\Application\Commands;

use ItalyStrap\Pipeline\HandlerInterface;
use ItalyStrap\ThemeJsonGenerator\Application\Commands\Utils\RootFolderTrait;
use ItalyStrap\ThemeJsonGenerator\Application\DumpMessage;
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
{
Expand Down Expand Up @@ -49,10 +46,10 @@ final class DumpCommand extends Command
*/
public const FILE = 'file';

private HandlerInterface $handler;
private ConsoleHandler $handler;

public function __construct(
HandlerInterface $handler
ConsoleHandler $handler
) {
$this->handler = $handler;
parent::__construct();
Expand Down Expand Up @@ -116,17 +113,20 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$rootFolder = $this->rootFolder((string)$input->getOption('path'));
$path = $input->getOption('path');
$file = $input->getOption(self::FILE);

$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 : ''
);

try {
return (int)$this->handler->handle($message);
return $this->handler->handle($message);
} catch (\Exception $exception) {
$output->writeln('<error>Error: ' . $exception->getMessage() . '</error>');
return Command::FAILURE;
Expand Down
11 changes: 4 additions & 7 deletions src/Application/Commands/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@

namespace ItalyStrap\ThemeJsonGenerator\Application\Commands;

use ItalyStrap\Pipeline\HandlerInterface;
use ItalyStrap\ThemeJsonGenerator\Application\Commands\Utils\RootFolderTrait;
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
{
Expand All @@ -23,10 +20,10 @@ class InfoCommand extends Command
public const NAME = 'info';
public const DESCRIPTION = 'Show info about JSON theme';

private HandlerInterface $handler;
private ConsoleHandler $handler;

public function __construct(
HandlerInterface $handler
ConsoleHandler $handler
) {
$this->handler = $handler;
parent::__construct();
Expand All @@ -45,7 +42,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$message = new Message($rootFolder);

try {
return (int)$this->handler->handle($message);
return $this->handler->handle($message);
} catch (\Exception $exception) {
$output->writeln('<error>Error: ' . $exception->getMessage() . '</error>');
return Command::FAILURE;
Expand Down
11 changes: 4 additions & 7 deletions src/Application/Commands/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@

namespace ItalyStrap\ThemeJsonGenerator\Application\Commands;

use ItalyStrap\Pipeline\HandlerInterface;
use ItalyStrap\ThemeJsonGenerator\Application\Commands\Utils\RootFolderTrait;
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
{
Expand All @@ -26,10 +23,10 @@ class InitCommand extends Command

public const DESCRIPTION = 'Initialize theme.json file';

private HandlerInterface $handler;
private ConsoleHandler $handler;

public function __construct(
HandlerInterface $handler,
ConsoleHandler $handler,
) {
$this->handler = $handler;
parent::__construct();
Expand All @@ -55,7 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$message = new Message($rootFolder);

try {
return (int)$this->handler->handle($message);
return $this->handler->handle($message);
} catch (\Exception $exception) {
$output->writeln('<error>Error: ' . $exception->getMessage() . '</error>');
return Command::FAILURE;
Expand Down
13 changes: 5 additions & 8 deletions src/Application/Commands/ValidateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@

namespace ItalyStrap\ThemeJsonGenerator\Application\Commands;

use ItalyStrap\Pipeline\HandlerInterface;
use ItalyStrap\ThemeJsonGenerator\Application\Commands\Utils\RootFolderTrait;
use ItalyStrap\ThemeJsonGenerator\Application\ValidateMessage;
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
{
Expand All @@ -25,10 +22,10 @@ class ValidateCommand extends Command

public const NAME = 'validate';
public const DESCRIPTION = 'Validate theme.json file';
private HandlerInterface $handler;
private ConsoleHandler $handler;

public function __construct(
HandlerInterface $handler
ConsoleHandler $handler
) {
$this->handler = $handler;
parent::__construct();
Expand All @@ -55,10 +52,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$rootFolder = $this->rootFolder();
$schemaPath = $rootFolder . '/theme.schema.json';

$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>Error: ' . $exception->getMessage() . '</error>');
return Command::FAILURE;
Expand Down
Loading
Loading