Skip to content

Commit

Permalink
chore(NEXT-35679): Code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mitelg committed May 29, 2024
1 parent 1111a8f commit 700211c
Show file tree
Hide file tree
Showing 50 changed files with 378 additions and 249 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [8.2, 8.3]
php: [ 8.2, 8.3 ]
steps:
- uses: actions/checkout@v4

Expand All @@ -24,7 +24,7 @@ jobs:
run: composer install

- name: Run tests
run: vendor/bin/phpunit --coverage-cobertura coverage.xml
run: composer test-coverage-cobertura

- name: Upload coverage
uses: codecov/codecov-action@v4
Expand All @@ -46,7 +46,7 @@ jobs:
run: composer install

- name: Run PHPStan
run: vendor/bin/phpstan analyse
run: composer phpstan

cs:
runs-on: ubuntu-latest
Expand All @@ -62,4 +62,4 @@ jobs:
run: composer install

- name: Run PHP CS Fixer
run: vendor/bin/php-cs-fixer fix --dry-run --diff
run: composer cs-dry
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
/composer.lock
/.php-cs-fixer.cache
/.phpunit.cache
/var/cache
/build/coverage
27 changes: 11 additions & 16 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,24 @@

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

return (new Config())
->setRiskyAllowed(true)
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@PER-CS2.0' => true,
'@PER-CS2.0:risky' => true,
// Ensure there is no code on the same line as the PHP open tag and it is followed by a blank line.
'blank_line_after_opening_tag' => false,
// Ensure there is no code on the same line as the PHP open tag.
'linebreak_after_opening_tag' => false,
// We use the attribute CoversClass which is not recognized by php-cs-fixer
'php_unit_test_class_requires_covers' => false,
'yoda_style' => [
'equal' => false,
'identical' => false,
'less_and_greater' => false,
],
'no_unused_imports' => true,
'declare_strict_types' => true,
'@PER-CS' => true,
'@PER-CS:risky' => true,
'@PHP84Migration' => true,
'@PHP80Migration:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
'concat_space' => ['spacing' => 'one'],
])
->setFinder(
Finder::create()
->exclude('vendor')
->name('shopware-deployment-helper')
->in(__DIR__),
)
;
6 changes: 4 additions & 2 deletions bin/shopware-deployment-helper
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

use Shopware\Deployment\Application;

error_reporting(-1);
Expand All @@ -10,7 +12,7 @@ $includables = [
__DIR__ . '/../../../autoload.php',
__DIR__ . '/../../vendor/autoload.php',
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/vendor/autoload.php'
__DIR__ . '/vendor/autoload.php',
];

if (str_contains(__DIR__, 'custom/plugins')) {
Expand All @@ -19,7 +21,7 @@ if (str_contains(__DIR__, 'custom/plugins')) {

foreach ($includables as $file) {
if (file_exists($file)) {
include_once ($file);
include_once $file;

break;
}
Expand Down
46 changes: 33 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,56 @@
],
"require": {
"php": ">=8.2",
"ext-pdo": "*",
"ext-dom": "*",
"ext-pdo": "*",
"digilist/dependency-graph": ">=0.4.1",
"doctrine/dbal": "^3.0 || ^4.0",
"symfony/dotenv": "^7.0 || ^6.0",
"symfony/process": "^7.0 || ^6.0",
"symfony/event-dispatcher": "^7.0 || ^6.0",
"symfony/dependency-injection": "^7.0 || ^6.0",
"symfony/config": "^7.0 || ^6.0",
"symfony/console": "^7.0 || ^6.0",
"symfony/yaml": "^7.0 || ^6.0",
"symfony/dependency-injection": "^7.0 || ^6.0",
"symfony/dotenv": "^7.0 || ^6.0",
"symfony/event-dispatcher": "^7.0 || ^6.0",
"symfony/filesystem": "^7.0 || ^6.0",
"symfony/finder": "^7.0 || ^6.0",
"digilist/dependency-graph": "*"
"symfony/process": "^7.0 || ^6.0",
"symfony/yaml": "^7.0 || ^6.0"
},
"require-dev": {
"symfony/var-dumper": "^7.0 || ^6.0",
"phpunit/phpunit": "^11.0",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-symfony": "^1.3",
"friendsofphp/php-cs-fixer": "3.57.2",
"phpstan/extension-installer": "1.3.1",
"friendsofphp/php-cs-fixer": "~3.53.0"
"phpstan/phpstan": "1.11.2",
"phpstan/phpstan-deprecation-rules": "1.2.0",
"phpstan/phpstan-phpunit": "1.4.0",
"phpstan/phpstan-strict-rules": "1.6.0",
"phpstan/phpstan-symfony": "1.4.1",
"phpunit/phpunit": "11.1.3",
"symfony/var-dumper": "^7.0 || ^6.0"
},
"autoload": {
"psr-4": {
"Shopware\\Deployment\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Shopware\\Deployment\\Tests\\": "tests/"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"scripts": {
"cs-dry": "php-cs-fixer fix --dry-run --diff",
"cs-fix": "php-cs-fixer fix",
"phpstan": [
"DEV_MODE=true PROJECT_ROOT=. bin/shopware-deployment-helper -q",
"phpstan"
],
"test": "phpunit",
"test-coverage-html": "phpunit --coverage-html=build/coverage",
"test-coverage-cobertura": "phpunit --coverage-cobertura coverage.xml"
}
}
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
includes:
- phar://phpstan.phar/conf/bleedingEdge.neon

parameters:
level: 8
treatPhpDocTypesAsCertain: false
paths:
- src
symfony:
containerXmlPath: var/cache/container.xml
5 changes: 3 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="false"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true">
Expand All @@ -15,7 +14,9 @@
</testsuite>
</testsuites>

<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
<source ignoreIndirectDeprecations="true"
restrictNotices="true"
restrictWarnings="true">
<include>
<directory>src</directory>
</include>
Expand Down
11 changes: 8 additions & 3 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\XmlDumper;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
use Symfony\Component\Filesystem\Filesystem;

class Application extends SymfonyApplication
{
Expand All @@ -24,9 +26,7 @@ public function __construct()
{
parent::__construct('Shopware Deployment Helper', '__VERSION__');
$this->container = $this->createContainer();
// @phpstan-ignore-next-line
$this->setDispatcher($this->container->get('event_dispatcher'));
// @phpstan-ignore-next-line
$this->setCommandLoader($this->container->get('console.command_loader'));
}

Expand Down Expand Up @@ -54,6 +54,10 @@ private function createContainer(): ContainerBuilder
$loader->load('services.xml');
$container->compile();

if (EnvironmentHelper::hasVariable('DEV_MODE')) {
(new Filesystem())->dumpFile(\dirname(__DIR__) . '/var/cache/container.xml', (new XmlDumper($container))->dump());
}

return $container;
}

Expand All @@ -62,7 +66,8 @@ private function createContainer(): ContainerBuilder
*/
private function getProjectDir(): string
{
if ($root = EnvironmentHelper::getVariable('PROJECT_ROOT')) {
$root = EnvironmentHelper::getVariable('PROJECT_ROOT');
if (\is_string($root) && $root !== '') {
return $root;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Command/OneTimeTaskListCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Shopware\Deployment\Command;

Expand Down
8 changes: 5 additions & 3 deletions src/Command/OneTimeTaskMarkCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Shopware\Deployment\Command;

Expand All @@ -12,7 +14,7 @@

#[AsCommand(
name: 'one-time-task:mark',
description: 'Mark a one-time task as run without executing it',
description: 'Mark an one-time task as run without executing it',
)]
class OneTimeTaskMarkCommand extends Command
{
Expand All @@ -31,7 +33,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io = new SymfonyStyle($input, $output);

try {
$this->oneTimeTasks->markAsRun($input->getArgument('id'));
$this->oneTimeTasks->markAsRun((string) $input->getArgument('id'));
} catch (\Throwable) {
$io->error('Could not mark one-time task as run, as it has been marked as run before.');

Expand Down
8 changes: 5 additions & 3 deletions src/Command/OneTimeTaskUnmarkCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Shopware\Deployment\Command;

Expand All @@ -12,7 +14,7 @@

#[AsCommand(
name: 'one-time-task:unmark',
description: 'Unmark a one-time task as run without executing it',
description: 'Unmark an one-time task as run without executing it',
)]
class OneTimeTaskUnmarkCommand extends Command
{
Expand All @@ -30,7 +32,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$this->oneTimeTasks->remove($input->getArgument('id'));
$this->oneTimeTasks->remove((string) $input->getArgument('id'));

$io->success('One-time task mark has been removed, this script will be executed on next deployment.');

Expand Down
17 changes: 9 additions & 8 deletions src/Command/RunCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Shopware\Deployment\Command;

Expand Down Expand Up @@ -27,33 +29,32 @@ public function __construct(

protected function configure(): void
{
$this->addOption('skip-theme-compile', null, InputOption::VALUE_OPTIONAL, 'Skip theme compile (should be used when the Theme has been compiled before in the CI/CD)', false);
$this->addOption('skip-asset-install', null, InputOption::VALUE_OPTIONAL, 'Skip asset install (should be used when the Assets has been copied before in the CI/CD)', false);
$this->addOption('timeout', null, InputOption::VALUE_OPTIONAL, 'Set script execution timeout (is seconds). Set to null to disable timeout', 300);
$this->addOption('skip-theme-compile', null, InputOption::VALUE_OPTIONAL, 'Skip theme compile (Should be used when the theme has been compiled before in the CI/CD)', false);
$this->addOption('skip-asset-install', null, InputOption::VALUE_OPTIONAL, 'Skip asset install (Should be used when the assets have been copied before in the CI/CD)', false);
$this->addOption('timeout', null, InputOption::VALUE_OPTIONAL, 'Set script execution timeout (in seconds). Set to null to disable timeout', 300);
}


protected function execute(InputInterface $input, OutputInterface $output): int
{
$timeout = $input->getOption('timeout');

$config = new RunConfiguration(
skipThemeCompile: (bool) $input->getOption('skip-theme-compile'),
skipAssetInstall: (bool) $input->getOption('skip-asset-install'),
timeout: $timeout ? (float) $timeout : null,
timeout: is_numeric($timeout) ? (float) $timeout : null,
);

$installed = $this->state->isInstalled();

$this->hookExecutor->execute(HookExecutor::PRE);
$this->hookExecutor->execute(HookExecutor::HOOK_PRE);

if ($installed) {
$this->upgradeManager->run($config, $output);
} else {
$this->installationManager->run($config, $output);
}

$this->hookExecutor->execute(HookExecutor::POST);
$this->hookExecutor->execute(HookExecutor::HOOK_POST);

return Command::SUCCESS;
}
Expand Down
Loading

0 comments on commit 700211c

Please sign in to comment.