From 50bbc9ddc2d60a52736ab5c03e36392454e08745 Mon Sep 17 00:00:00 2001 From: nikita tarasov Date: Wed, 15 May 2024 16:11:30 +0300 Subject: [PATCH] modernize --- .gitattributes | 2 +- .github/workflows/grumphp.yml | 48 +++++++++++++++++++++++++++++++++++ .gitignore | 4 ++- .php-cs-fixer.php | 15 +++++++++++ .php_cs | 11 -------- .travis.yml | 24 ------------------ Console/Command/Dump.php | 12 +++++---- Console/Command/Sync.php | 21 ++++++++------- README.md | 38 ++++++++++++++------------- composer.json | 14 +++++++--- grumphp.yml | 41 ++++++++++++++++-------------- phpcs.xml | 1 - phpstan.neon | 6 +++++ registration.php | 2 +- 14 files changed, 144 insertions(+), 95 deletions(-) create mode 100644 .github/workflows/grumphp.yml create mode 100644 .php-cs-fixer.php delete mode 100644 .php_cs delete mode 100644 .travis.yml create mode 100644 phpstan.neon diff --git a/.gitattributes b/.gitattributes index 08157f8..8c913d3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11,4 +11,4 @@ magento.rb export-ignore .php_cs export-ignore grumphp.yml export-ignore phpcs.xml export-ignore -psalm.xml export-ignore \ No newline at end of file +phpstan.neon export-ignore \ No newline at end of file diff --git a/.github/workflows/grumphp.yml b/.github/workflows/grumphp.yml new file mode 100644 index 0000000..ef6f095 --- /dev/null +++ b/.github/workflows/grumphp.yml @@ -0,0 +1,48 @@ +name: Static Test + +on: + workflow_dispatch: + pull_request: + branches: + - v2.4 + push: + branches: + - v2.4 + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php-versions: ['7.4', '8.1', '8.2', '8.3'] + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, xml, ctype, iconv, intl, mysql + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Cache composer dependencies + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + - run: composer self-update --2 + - run: echo "{\"http-basic\":{\"repo.magento.com\":{\"username\":\"${MAGE_LOGIN}\",\"password\":\"${MAGE_PWD}\"}}}" > auth.json + env: + MAGE_LOGIN: ${{ secrets.MAGE_LOGIN }} + MAGE_PWD: ${{ secrets.MAGE_PWD }} + - name: Install Composer dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader + - run: php vendor/bin/phpcs --config-set ignore_warnings_on_exit 1 + - run: php vendor/bin/phpcs --config-set show_warnings 0 + - name: Run Tests + run: php vendor/bin/grumphp run diff --git a/.gitignore b/.gitignore index 6469a82..b775b26 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ /composer.lock .DS_Store .php_cs.cache - +.php-cs-fixer.cache +auth.json +/generate diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..ec5589e --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,15 @@ +in('.') + ->exclude('Test/tmp') + ->name('*.phtml') + ->ignoreVCSIgnored(true); +$config = new \Mygento\CS\Config\Module($header); +$config->setFinder($finder); +return $config; diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 658a2a6..0000000 --- a/.php_cs +++ /dev/null @@ -1,11 +0,0 @@ -in('.')->name('*.phtml'); -$config = new \Mygento\CS\Config\Module($header); -$config->setFinder($finder); -return $config; diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b448c51..0000000 --- a/.travis.yml +++ /dev/null @@ -1,24 +0,0 @@ -language: php - -php: -- 7.3 -- 7.4 - -cache: - directories: - - $HOME/.composer/cache - -before_script: -- sudo apt-get install libxml2-utils -- composer self-update -- echo "{\"http-basic\":{\"repo.magento.com\":{\"username\":\"${MAGENTO_USERNAME}\",\"password\":\"${MAGENTO_PASSWORD}\"}}}" > auth.json -- phpenv config-rm xdebug.ini -- composer install --no-interaction --prefer-dist --quiet -- php vendor/bin/phpcs --config-set ignore_warnings_on_exit 1 -- php vendor/bin/phpcs --config-set show_warnings 0 - -script: -- php vendor/bin/grumphp run -env: - global: - secure: DcJb3EOTdOg/y3OeCCb8eP+dSI40G5d+JX0xWw7XZQ5E41id9NGVOnGbzN8Uer0WKfkiailZa/rSbYeISWIESDtMDiWe0dNSPT6xGLOlNdHR39MxDVFP2/QJWscSuW7ajKxNih7Qx+y93oLx73CyxM/H+quHlBL6jpj1j/RpYjIg/oQ7RKvhahI7L0CW337Cre2MfHAVXKNSBRnQPBNFc2OaqWtWb/LBbwj+CmfvdR9I62jxSuqz7Ce/4QpLipqrRTyB/RUbw8bAL0mALWg5jVQQ9DG3iM1iPKsaIKrPkTHbXv1tSx9Td5E1VItpJMXjCgZDjTxq7y++k+QwdVM9K9THDD7eQdlHiHJTEqFUcofZbivNRzlB7NVb46SO1/3BqO/ngp0CG7WcZo7y85QrXRz367KHFoO96FAjKctMmFwmDZkNfuquKFT8hH39qZ/P3eGp9idWoYpj+ADNlc2ALyASkWRfDfg1Zni5FPPBHRAgwAUUe04B8pucDW+1aQyR3GqvWYt2uf1Wt/ocD+Ic/sIp+eRCAGLO7KJZFMcxv4Xf+JuGejw3yD0ezI4MuImsLhUhJftiollDkuBQJaf541A6vNd296WpSBqutl1atduHvh6VAjB9cFYfRe3JM7kTOGWVhR3dTygojTy1yG1eGE4Y3UX0SJqS74aRArtMZew= diff --git a/Console/Command/Dump.php b/Console/Command/Dump.php index 9feb594..98fe61f 100644 --- a/Console/Command/Dump.php +++ b/Console/Command/Dump.php @@ -2,7 +2,7 @@ /** * @author Mygento Team - * @copyright 2017-2020 Mygento (https://www.mygento.ru) + * @copyright 2017-2024 Mygento (https://www.mygento.com) * @package Mygento_Configsync */ @@ -12,7 +12,7 @@ class Dump extends \Symfony\Component\Console\Command\Command { - const CONFIG_DIR = 'config'; + private const CONFIG_DIR = 'config'; /** * @var \Magento\Framework\App\Config\ConfigResource\ConfigInterface @@ -91,15 +91,16 @@ protected function configure() protected function execute( \Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output - ) { + ): int { $this->output = $output; $section = $input->getArgument('section'); $env = $input->getArgument('env'); $filename = $input->getArgument('filename'); $this->output->writeln("Starting dump. Section: {$section}. Env: {$env}"); - - $conf = $this->scopeConfig->get('system', 'default/' . $section); + /** @var \Magento\Framework\App\Config $c */ + $c = $this->scopeConfig; + $conf = $c->get('system', 'default/' . $section); if (empty($conf)) { throw new \Exception('No config.'); @@ -128,6 +129,7 @@ protected function execute( //Should we overwrite the file? if ($this->file->fileExists($filename)) { + /** @var \Symfony\Component\Console\Helper\QuestionHelper $helper */ $helper = $this->getHelper('question'); $question = new ChoiceQuestion( 'File already exists! Overwrite?', diff --git a/Console/Command/Sync.php b/Console/Command/Sync.php index b68cfa8..5787622 100644 --- a/Console/Command/Sync.php +++ b/Console/Command/Sync.php @@ -2,7 +2,7 @@ /** * @author Mygento Team - * @copyright 2017-2020 Mygento (https://www.mygento.ru) + * @copyright 2017-2024 Mygento (https://www.mygento.com) * @package Mygento_Configsync */ @@ -10,7 +10,7 @@ class Sync extends \Symfony\Component\Console\Command\Command { - const DELETE = '%DELETE%'; + private const DELETE = '%DELETE%'; /** * @var \Magento\Framework\App\Config\ConfigResource\ConfigInterface @@ -70,7 +70,7 @@ protected function configure() protected function execute( \Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output - ) { + ): int { $this->output = $output; $envData = $this->getEnvData( @@ -115,8 +115,7 @@ protected function execute( $line = sprintf( '[%s] %s -> DELETED', $scopeKey, - $path, - $newValue ?: 'null' + $path ); $this->output->writeln($line); @@ -172,18 +171,18 @@ private function getEnvData($yamlFile, $env) if (!$this->isFileCorrect($data)) { throw new \Exception( "File format is incorrect.\r\n\r\n" - . "For example the correct format:\r\n\r\n" - . "production:\r\n" - . " default:\r\n" - . " web/secure/base_url: https://domain.com/\r\n" - . ' web/secure/use_in_frontend: 1' + . "For example the correct format:\r\n\r\n" + . "production:\r\n" + . " default:\r\n" + . " web/secure/base_url: https://domain.com/\r\n" + . ' web/secure/use_in_frontend: 1' ); } if (!isset($data[$env])) { $this->output->writeln( 'The environment doesn\'t exists in the file.' - . ' Nothing to import' + . ' Nothing to import' ); return 0; diff --git a/README.md b/README.md index 1d1082d..a8874c6 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,13 @@ A module to store Magento configuration with multiple environments in the version control - -[![Build Status](https://travis-ci.com/mygento/configsync.svg?branch=v2.4)](https://travis-ci.com/mygento/configsync) +[![Build Status](https://github.com/mygento/configsync/actions/workflows/grumphp.yml/badge.svg)](https://github.com/mygento/configsync/actions/workflows/grumphp.yml) [![Latest Stable Version](https://poser.pugx.org/mygento/module-configsync/v/stable)](https://packagist.org/packages/mygento/module-configsync) [![Total Downloads](https://poser.pugx.org/mygento/module-configsync/downloads)](https://packagist.org/packages/mygento/module-configsync) ## File Syntax -The configuration values are stored in a YAML file. The format of the file is as follows: +The configuration values are stored in a YAML file. The format of the file is as follows: environment: scope_key: @@ -32,30 +31,35 @@ For example: Valid scope keys are: -* default -* stores-`$id` -* websites-`$id` - +- default +- stores-`$id` +- websites-`$id` -Use ```%DELETE%``` to delete config path +Use `%DELETE%` to delete config path ## Usage + #### Sync config from file + php bin/magento setup:config:sync [options] [--] - Arguments: - * **env** - environment for import. - * **config_yaml_file** - the YAML file containing the configuration settings. +Arguments: - Options: - * **--detailed** - display detailed information (1 - display, otherwise - not display). +- **env** - environment for import. +- **config_yaml_file** - the YAML file containing the configuration settings. + +Options: + +- **--detailed** - display detailed information (1 - display, otherwise - not display). #### Dump config + php bin/magento setup:config:dump [--]
Note: only `default` scope is implemented - Arguments: - * **env** - environment name. - * **section** - name of the section to export its config. - * **filename** - name of the output file (Optional). +Arguments: + +- **env** - environment name. +- **section** - name of the section to export its config. +- **filename** - name of the output file (Optional). diff --git a/composer.json b/composer.json index 4ba2f6c..cccb952 100644 --- a/composer.json +++ b/composer.json @@ -2,11 +2,10 @@ "name": "mygento/module-configsync", "description": "A module to store Magento configuration with multiple environments in the version control", "type": "magento2-module", - "version": "2.4.0", "license": "OSL-3.0", "authors": [{ "name": "Nikita Tarasov", - "email": "nikita@mygento.ru" + "email": "nikita@mygento.com" }], "keywords": [ "magento", @@ -17,7 +16,7 @@ "mustangostang/spyc": "^0.6.2" }, "require-dev": { - "mygento/coding-standard": "~2.14.0-beta1" + "mygento/coding-standard": "~2.14.0" }, "autoload": { "files": [ @@ -32,5 +31,12 @@ "type": "composer", "url": "https://repo.magento.com" } - ] + ], + "config": { + "allow-plugins": { + "magento/composer-dependency-version-audit-plugin": false, + "magento/magento-composer-installer": false, + "phpro/grumphp": true + } + } } diff --git a/grumphp.yml b/grumphp.yml index e6c9dab..c822ac1 100644 --- a/grumphp.yml +++ b/grumphp.yml @@ -1,19 +1,22 @@ -parameters: - git_dir: . - bin_dir: vendor/bin - tasks: - composer: - no_check_lock: true - git_blacklist: - keywords: - - "die(" - - "var_dump(" - - "exit;" - phplint: - phpcsfixer2: - config: '.php_cs' - phpmd: - ruleset: ['vendor/mygento/coding-standard/Mygento-Mage2/phpmd.xml'] - phpcs: - warning_severity: null - xmllint: +grumphp: + tasks: + composer: + no_check_lock: true + git_blacklist: + keywords: + - 'die(' + - 'var_dump(' + - 'exit;' + phplint: + phpcsfixer: + config: '.php-cs-fixer.php' + phpmd: + ruleset: ['vendor/mygento/coding-standard/Mygento-Mage2/phpmd.xml'] + exclude: ['Test'] + phpcs: + warning_severity: 0 + xmllint: + phpstan: + autoload_file: 'vendor/mygento/coding-standard/stan/autoload.php' + ignore_patterns: ['Test'] + level: 2 diff --git a/phpcs.xml b/phpcs.xml index 43a6761..69393e6 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,5 +1,4 @@ - diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..b5f5d2a --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,6 @@ +includes: + - vendor/mygento/coding-standard/stan/extension.neon + +parameters: + bootstrapFiles: + - 'vendor/mygento/coding-standard/stan/autoload.php' diff --git a/registration.php b/registration.php index 5ea557c..307eba6 100644 --- a/registration.php +++ b/registration.php @@ -2,7 +2,7 @@ /** * @author Mygento Team - * @copyright 2017-2020 Mygento (https://www.mygento.ru) + * @copyright 2017-2024 Mygento (https://www.mygento.com) * @package Mygento_Configsync */