From c817a619546f3df2e1e35e4e8add1062c40bf899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20L=C3=B8vgaard?= Date: Tue, 25 May 2021 09:15:52 +0200 Subject: [PATCH] Upgrade project --- .editorconfig | 29 ----------------------------- .gitattributes | 4 ++-- .github/workflows/build.yaml | 4 ++-- LICENSE | 2 +- composer.json | 14 +++++++------- easy-coding-standard.yaml | 2 -- ecs.php | 23 +++++++++++++++++++++++ phpstan.neon | 7 ------- psalm-baseline.xml | 13 +++++++++++++ psalm.xml | 16 ++++++++++++++++ src/autoload.php | 2 +- src/task/dotenv.php | 29 ++++++++++++++++++++++++----- tests/recipe/DeployTest.php | 2 +- 13 files changed, 90 insertions(+), 57 deletions(-) delete mode 100644 easy-coding-standard.yaml create mode 100644 ecs.php delete mode 100644 phpstan.neon create mode 100644 psalm-baseline.xml create mode 100644 psalm.xml diff --git a/.editorconfig b/.editorconfig index e716f26..3b4108c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,42 +1,13 @@ root = true [*] -# Change these settings to your own preference indent_style = space indent_size = 4 - -# We recommend you to keep these unchanged end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[*.json] -indent_style = space -indent_size = 2 - [*.md] -indent_style = space -indent_size = 4 trim_trailing_whitespace = false - -[*.neon] -indent_style = tab -indent_size = 4 - -[*.php] -indent_style = space -indent_size = 4 - -[composer.json] -indent_style = space -indent_size = 4 - -[phpstan.neon] -indent_style = tab -indent_size = 4 - -[phpunit.xml{,.dist}] -indent_style = space -indent_size = 4 diff --git a/.gitattributes b/.gitattributes index 09f02f7..2f5a163 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,8 +1,8 @@ /.editorconfig export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/easy-coding-standard.yaml export-ignore -/phpstan.neon export-ignore +/ecs.php export-ignore +/psalm.xml export-ignore /phpunit.xml.dist export-ignore /README.md export-ignore /tests export-ignore diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6367507..1ad8cdf 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -27,10 +27,10 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v2.3.3" + uses: "actions/checkout@v2" - name: "Install PHP with extensions" - uses: "shivammathur/setup-php@2.7.0" + uses: "shivammathur/setup-php@v2" with: coverage: "none" extensions: "${{ env.PHP_EXTENSIONS }}" diff --git a/LICENSE b/LICENSE index e987d35..3f4cf03 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Setono +Copyright (c) 2021 Setono Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index ecc969a..d18e85a 100644 --- a/composer.json +++ b/composer.json @@ -10,15 +10,15 @@ } ], "require": { - "php": "^7.4", + "php": ">=7.4", "deployer/deployer": "^6.8", "symfony/console": "^4.4 || ^5.0", "symfony/dotenv": "^4.4 || ^5.0", - "thecodingmachine/safe": "^1.2" + "webmozart/assert": "^1.10" }, "require-dev": { - "phpunit/phpunit": "^9.4", - "setono/code-quality-pack": "^1.4" + "phpunit/phpunit": "^9.5", + "setono/code-quality-pack": "^2.1" }, "config": { "sort-packages": true @@ -43,9 +43,9 @@ }, "prefer-stable": true, "scripts": { - "analyse": "phpstan analyse -c phpstan.neon", - "check-style": "ecs check --ansi src/ tests/", - "fix-style": "ecs check --fix --ansi src/ tests/", + "analyse": "psalm", + "check-style": "ecs check", + "fix-style": "ecs check --fix", "phpunit": "phpunit" } } diff --git a/easy-coding-standard.yaml b/easy-coding-standard.yaml deleted file mode 100644 index 2403599..0000000 --- a/easy-coding-standard.yaml +++ /dev/null @@ -1,2 +0,0 @@ -imports: - - { resource: 'vendor/sylius-labs/coding-standard/easy-coding-standard.yml' } diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..3c0385e --- /dev/null +++ b/ecs.php @@ -0,0 +1,23 @@ +import('vendor/sylius-labs/coding-standard/ecs.php'); + $containerConfigurator->parameters()->set(Option::PATHS, [ + 'src', 'tests', + ]); + + /** + * Was added to fix this exception: + * + * PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException: [binary_operator_spaces] Invalid configuration: + * The options "align_double_arrow", "align_equals" do not exist. Defined options are: "default", "operators". + * in vendor/friendsofphp/php-cs-fixer/src/AbstractFixer.php on line 155 + */ + $containerConfigurator->services()->set(BinaryOperatorSpacesFixer::class); +}; diff --git a/phpstan.neon b/phpstan.neon deleted file mode 100644 index fdf4b5d..0000000 --- a/phpstan.neon +++ /dev/null @@ -1,7 +0,0 @@ -parameters: - reportUnmatchedIgnoredErrors: true - - level: max - - paths: - - src/ diff --git a/psalm-baseline.xml b/psalm-baseline.xml new file mode 100644 index 0000000..9bd999f --- /dev/null +++ b/psalm-baseline.xml @@ -0,0 +1,13 @@ + + + + + set_include_path + + + + + has + + + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..91b79c8 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/src/autoload.php b/src/autoload.php index b12b8e2..b11d2b7 100644 --- a/src/autoload.php +++ b/src/autoload.php @@ -2,4 +2,4 @@ declare(strict_types=1); -\Safe\set_include_path(get_include_path() . \PATH_SEPARATOR . __DIR__); +set_include_path(get_include_path() . \PATH_SEPARATOR . __DIR__); diff --git a/src/task/dotenv.php b/src/task/dotenv.php index 2db4609..dccc8ce 100644 --- a/src/task/dotenv.php +++ b/src/task/dotenv.php @@ -14,11 +14,11 @@ use function Deployer\set; use function Deployer\task; use function Deployer\test; -use function Safe\ksort; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Helper\TableSeparator; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Dotenv\Dotenv; +use Webmozart\Assert\Assert; /** * This step has to come AFTER the deploy:update_code step because @@ -66,6 +66,10 @@ new TableSeparator(), ]); + /** + * @var string $key + * @var string $val + */ foreach ($variables as $key => $val) { $table->addRow([$key, $val]); } @@ -76,10 +80,8 @@ /** * We want two arrays to begin with. This allows us to easily compare the two arrays later on * when the $variables may have been changed by the user - * - * @var array $variables */ - $variables = $initialVariables = eval('?>' . run('cat {{release_path}}/.env.local.php')); + $variables = $initialVariables = evalEnv(run('cat {{release_path}}/.env.local.php')); while (true) { $outputVariablesFunction($output, $variables); @@ -107,7 +109,11 @@ * See https://www.php.net/manual/en/language.operators.array.php */ if ($initialVariables != $variables) { - // This array contains the environment variables already overridden + /** + * This array contains the environment variables already overridden + * + * @var array $overriddenValues + */ $overriddenValues = (new Dotenv())->parse(run('cat {{release_path}}/.env.{{stage}}.local')); /** @@ -137,3 +143,16 @@ invoke('dotenv:generate'); } })->desc('Allows the user to update environment variables'); + +/** + * @return array + */ +function evalEnv(string $envContents): array +{ + /** @var array $res */ + $res = eval('?>' . $envContents); + Assert::isArray($res); + Assert::allScalar($res); + + return $res; +} diff --git a/tests/recipe/DeployTest.php b/tests/recipe/DeployTest.php index 0deffc0..8a0e0a3 100644 --- a/tests/recipe/DeployTest.php +++ b/tests/recipe/DeployTest.php @@ -18,7 +18,7 @@ final class DeployTest extends TestCase public static function setUpBeforeClass(): void { - \Safe\set_include_path(get_include_path() . \PATH_SEPARATOR . __DIR__ . '/../../vendor/deployer/deployer'); + set_include_path(get_include_path() . \PATH_SEPARATOR . __DIR__ . '/../../vendor/deployer/deployer'); // init repository $repository = __DIR__ . '/repository';