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: 5 additions & 1 deletion .docker/codecept
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
# Get project name from .env file
PROJECT_NAME=$(grep PROJECT_NAME .env | cut -d '=' -f2 | tr -d '"')

docker exec -w /var/www/html/wp-content/plugins/"${PROJECT_NAME}" "${PROJECT_NAME}"_test sh -c "vendor/bin/codecept ${*}"
docker exec \
--user www-data \
-w /var/www/html/wp-content/plugins/"${PROJECT_NAME}" \
"${PROJECT_NAME}"_test \
sh -c "vendor/bin/codecept ${*}"
7 changes: 6 additions & 1 deletion .docker/composer
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
# Get project name from .env file
PROJECT_NAME=$(grep PROJECT_NAME .env | cut -d '=' -f2 | tr -d '"')

docker-compose run -w /var/www/html/wp-content/plugins/"${PROJECT_NAME}" --rm wordpress sh -c "composer ${*}"
docker-compose run \
--user www-data \
-w /var/www/html/wp-content/plugins/"${PROJECT_NAME}" \
--rm \
wordpress \
sh -c "composer ${*}"
2 changes: 2 additions & 0 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ services:
args:
PHP_VERSION: ${PHP_VERSION}
WP_VERSION: ${WP_VERSION}
HOST_UID: ${HOST_UID:-1000}
HOST_GID: ${HOST_GID:-1000}
container_name: ${PROJECT_NAME:-wordpress}_test
restart: always
ports:
Expand Down
14 changes: 12 additions & 2 deletions .docker/wordpress/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
ARG PHP_VERSION
ARG WP_VERSION
ARG PHP_VERSION=8.2
ARG WP_VERSION=6
ARG HOST_UID=1000
ARG HOST_GID=1000

FROM wordpress:${WP_VERSION}-php${PHP_VERSION}

ARG HOST_UID
ARG HOST_GID

RUN set -eux; \
groupmod -o -g "${HOST_GID}" www-data; \
usermod -o -u "${HOST_UID}" -g "${HOST_GID}" www-data; \
chown -R www-data:www-data /var/www

# Install pcov for code coverage
RUN set -eux; \
pecl install pcov; \
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
DOCKER_FOLDER = .docker
DOCKER_DIR = cd $(DOCKER_FOLDER) &&
HOST_OWNER = $(shell id -u):$(shell id -g)
HOST_UID = $(shell id -u)
HOST_GID = $(shell id -g)
HOST_OWNER = $(HOST_UID):$(HOST_GID)
FILES_OWNERSHIP = sudo chown -R $(HOST_OWNER) .
DB_USER = $(shell cat .docker/.env | grep DB_USER | cut -d '=' -f2)
DB_PASSWORD = $(shell cat .docker/.env | grep DB_PASSWORD | cut -d '=' -f2)
DB_NAME = $(shell cat .docker/.env | grep DB_NAME | cut -d '=' -f2)

export HOST_UID
export HOST_GID

default: help

# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"require-dev": {
"lucatume/wp-browser": "^4.5",
"phpspec/prophecy-phpunit": "^2.0",
"dg/bypass-finals": "^1.9",

"codeception/module-asserts": "^3.0",
"codeception/module-phpbrowser": "^3.0",
Expand All @@ -55,15 +56,16 @@
"phpcompatibility/php-compatibility": "*",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",

"phpstan/phpstan": "^1.12",
"phpstan/phpstan": "^2.1",

"phpbench/phpbench": "^1.2",
"phpmetrics/phpmetrics": "^2.8",

"infection/infection": "^0.26.6",
"infection/codeception-adapter": "^0.4.1",

"rector/rector": "^0.19.0",
"rector/rector": "^2.4",
"rector/swiss-knife": "^2.3",
"symplify/easy-coding-standard": "^12.0",

"italystrap/debug": "dev-master"
Expand Down
13 changes: 9 additions & 4 deletions namespace-bc-aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

declare(strict_types=1);

\class_alias(
'ItalyStrap\ThemeJsonGenerator\Api\ThemeJson',
'ItalyStrap\ThemeJsonGenerator\Application\Config\Blueprint'
);
$aliases = [
'ItalyStrap\ThemeJsonGenerator\Api\ThemeJson' => 'ItalyStrap\ThemeJsonGenerator\Application\Config\Blueprint',
];

foreach ($aliases as $class => $alias) {
if (!\class_exists($alias)) {
\class_alias($class, $alias);
}
}
51 changes: 26 additions & 25 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,39 @@

use Rector\Config\RectorConfig;
use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Strict\Rector\Ternary\DisallowedShortTernaryRuleFixerRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
return RectorConfig::configure()
->withPaths([
__DIR__ . '/bin',
__DIR__ . '/functions',
__DIR__ . '/src',
__DIR__ . '/tests',
]);

$rectorConfig->skip([
DisallowedShortTernaryRuleFixerRector::class,
])
->withSkip([
__DIR__ . '/tests/_data',
__DIR__ . '/tests/_output',
__DIR__ . '/tests/_support/_generated',
__DIR__ . '/tests/integration/Domain/Input/Styles/ProcessBlocksCustomCssTrait.php',
]);

// register a single rule
$rectorConfig->rule(StaticDataProviderClassMethodRector::class);

// define sets of rules
$rectorConfig->sets([
SetList::CODE_QUALITY,
SetList::CODING_STYLE,
// SetList::DEAD_CODE,
SetList::EARLY_RETURN,
SetList::TYPE_DECLARATION,
SetList::STRICT_BOOLEANS,
SetList::INSTANCEOF,
LevelSetList::UP_TO_PHP_74
]);
};
])
->withRules([
StaticDataProviderClassMethodRector::class,
])
->withPreparedSets(
// deadCode: true, // Not yet, this removes also some commented code that I need to keep.
codeQuality: true,
codingStyle: true,
typeDeclarations: true,
privatization: true,
instanceOf: true,
earlyReturn: true,
// carbon: true,
phpunitCodeQuality: true,
)
->withImportNames(
importDocBlockNames: false,
importShortClasses: false,
removeUnusedImports: true,
)
->withPhpSets()
->withoutParallel();
20 changes: 6 additions & 14 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;

/**
* @template TKey as array-key
* @template TValue
* @template-extends Config<TKey,TValue>
* @extends Config<array-key, mixed>
*/
final class ThemeJson extends Config implements \JsonSerializable
final class ThemeJson extends Config
{
public function setGlobalCss(string $css): bool
{
Expand All @@ -28,7 +26,9 @@ public function setGlobalCss(string $css): bool

public function appendGlobalCss(string $css): bool
{
$currentCss = (string)$this->get(SectionNames::STYLES . '.css');
$currentCss = $this->get(SectionNames::STYLES . '.css');
$currentCss = \is_string($currentCss) ? $currentCss : '';

return $this->set(SectionNames::STYLES . '.css', $currentCss . $css);
}

Expand Down Expand Up @@ -76,19 +76,11 @@ public function setPresets(PresetsInterface $presets): bool
foreach ($keys as $key => $value) {
try {
$this->set($key, $presets->toArrayByCategory($value));
} catch (\Exception $e) {
} catch (\Exception) {
continue;
}
}

return true;
}

/**
* @return array<array-key, mixed>
*/
public function jsonSerialize(): array
{
return $this->getArrayCopy();
}
}
6 changes: 1 addition & 5 deletions src/Application/Commands/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;

#[AsCommand(name: DumpCommand::NAME, description: DumpCommand::DESCRIPTION)]
final class DumpCommand extends Command
Expand Down Expand Up @@ -46,12 +45,9 @@ final class DumpCommand extends Command
*/
public const FILE = 'file';

private ConsoleHandler $handler;

public function __construct(
ConsoleHandler $handler
private ConsoleHandler $handler
) {
$this->handler = $handler;
parent::__construct();
}

Expand Down
8 changes: 3 additions & 5 deletions src/Application/Commands/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: InfoCommand::NAME, description: InfoCommand::DESCRIPTION)]
class InfoCommand extends Command
final class InfoCommand extends Command
{
use RootFolderTrait;

public const NAME = 'info';
public const DESCRIPTION = 'Show info about JSON theme';

private ConsoleHandler $handler;
public const DESCRIPTION = 'Show info about JSON theme';

public function __construct(
ConsoleHandler $handler
private ConsoleHandler $handler
) {
$this->handler = $handler;
parent::__construct();
}

Expand Down
10 changes: 4 additions & 6 deletions src/Application/Commands/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace ItalyStrap\ThemeJsonGenerator\Application\Commands;

use Symfony\Component\Console\Input\InputOption;
use ItalyStrap\ThemeJsonGenerator\Application\Commands\Utils\RootFolderTrait;
use ItalyStrap\ThemeJsonGenerator\Application\Message;
use ItalyStrap\ThemeJsonGenerator\Infrastructure\Filesystem\DataFromJsonTrait;
Expand All @@ -14,7 +15,7 @@
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: InitCommand::NAME, description: InitCommand::DESCRIPTION)]
class InitCommand extends Command
final class InitCommand extends Command
{
use RootFolderTrait;
use DataFromJsonTrait;
Expand All @@ -23,12 +24,9 @@ class InitCommand extends Command

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

private ConsoleHandler $handler;

public function __construct(
ConsoleHandler $handler,
private readonly ConsoleHandler $handler,
) {
$this->handler = $handler;
parent::__construct();
}

Expand All @@ -40,7 +38,7 @@ protected function configure(): void
$this->addOption(
'styles',
's',
\Symfony\Component\Console\Input\InputOption::VALUE_OPTIONAL,
InputOption::VALUE_OPTIONAL,
'Init JSON file inside styles folder'
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Application/Commands/ValidateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: ValidateCommand::NAME, description: ValidateCommand::DESCRIPTION)]
class ValidateCommand extends Command
final class ValidateCommand extends Command
{
use RootFolderTrait;
use DataFromJsonTrait;

public const NAME = 'validate';

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


public function __construct(
ConsoleHandler $handler
private readonly ConsoleHandler $handler
) {
$this->handler = $handler;
parent::__construct();
}

Expand Down
21 changes: 5 additions & 16 deletions src/Application/DumpMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,14 @@

namespace ItalyStrap\ThemeJsonGenerator\Application;

class DumpMessage
final readonly class DumpMessage
{
private string $rootFolder = '';

private bool $dry_run;

private string $sassFolder;
private string $file;

public function __construct(
string $rootFolder,
string $sassFolder,
bool $dry_run,
string $file
private string $rootFolder,
private string $sassFolder,
private bool $dry_run,
private string $file
) {
$this->rootFolder = $rootFolder;
$this->dry_run = $dry_run;
$this->sassFolder = $sassFolder;
$this->file = $file;
}

public function getRootFolder(): string
Expand Down
10 changes: 4 additions & 6 deletions src/Application/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

namespace ItalyStrap\ThemeJsonGenerator\Application;

class Message
final readonly class Message
{
private string $rootFolder = '';

public function __construct(string $rootFolder)
{
$this->rootFolder = $rootFolder;
public function __construct(
private string $rootFolder
) {
}

public function getRootFolder(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Middlewares/DeleteSchemaJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use ItalyStrap\ThemeJsonGenerator\Application\ValidateMessage;
use ItalyStrap\ThemeJsonGenerator\Infrastructure\Handler\ConsoleHandler;

class DeleteSchemaJson implements MiddlewareInterface
final class DeleteSchemaJson implements MiddlewareInterface
{
/**
* @phpstan-param ValidateMessage $message
Expand Down
Loading
Loading