From 66511daa882699e846b37824f2e3e35c5f2f7f8e Mon Sep 17 00:00:00 2001 From: "tan.nguyen" Date: Wed, 21 Feb 2024 17:04:14 +0700 Subject: [PATCH 1/7] Update to scaffold 0.12.1 --- .editorconfig | 29 -------- .github/PULL_REQUEST_TEMPLATE.md | 16 +++++ .github/release-drafter.yml | 8 ++- ...assign-pr-author.yml => assign-author.yml} | 4 +- .github/workflows/draft-release-notes.yml | 25 +++++++ .github/workflows/release.yml | 34 +++++----- README.md | 6 ++ composer.json | 8 ++- phpmd.xml | 15 +++++ rector.php | 66 +++++++++++++++++++ .../Context/ScreenshotContext.php | 19 ++---- .../BehatScreenshotExtension.php | 17 +++-- 12 files changed, 174 insertions(+), 73 deletions(-) delete mode 100644 .editorconfig create mode 100644 .github/PULL_REQUEST_TEMPLATE.md rename .github/workflows/{auto-assign-pr-author.yml => assign-author.yml} (71%) create mode 100644 .github/workflows/draft-release-notes.yml create mode 100644 phpmd.xml create mode 100644 rector.php diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0f0cdf4..0000000 --- a/.editorconfig +++ /dev/null @@ -1,29 +0,0 @@ -# This is the top-most .editorconfig file; do not search in parent directories. -root = true - -# All files. -[*] -end_of_line = LF -indent_style = space -indent_size = 4 -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -[*.{json,lock}] -indent_size = 4 - -[*.{yml,yaml}] -indent_size = 2 - -[*.yml.dist] -indent_size = 2 - -[*.{sh,bash,bats}] -indent_size = 2 - -[*.xml] -indent_size = 4 - -[*.feature] -indent_size = 2 diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..95cbae2 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,16 @@ +## Checklist before requesting a review + +- [ ] I have formatted the subject to include ticket number as `[#123] Verb in past tense with dot at the end.` +- [ ] I have added a link to the issue tracker +- [ ] I have provided information in `Changed` section about WHY something was done if this was not a normal implementation +- [ ] I have performed a self-review of my code +- [ ] I have commented my code, particularly in hard-to-understand areas +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] I have run new and existing relevant tests locally with my changes, and they passed +- [ ] I have provided screenshots, where applicable + +## Changed + +1. + +## Screenshots diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 699ff47..8b07383 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,12 +1,14 @@ -name-template: '$NEXT_MINOR_VERSION' -tag-template: '$NEXT_MINOR_VERSION' +name-template: '$RESOLVED_VERSION' +tag-template: '$RESOLVED_VERSION' change-template: '- $TITLE @$AUTHOR (#$NUMBER)' change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. +version-resolver: + default: minor template: | ## What's new since $PREVIOUS_TAG $CHANGES - **Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...$NEXT_MINOR_VERSION + **Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...$RESOLVED_VERSION $CONTRIBUTORS diff --git a/.github/workflows/auto-assign-pr-author.yml b/.github/workflows/assign-author.yml similarity index 71% rename from .github/workflows/auto-assign-pr-author.yml rename to .github/workflows/assign-author.yml index df73ac4..466655f 100644 --- a/.github/workflows/auto-assign-pr-author.yml +++ b/.github/workflows/assign-author.yml @@ -12,5 +12,7 @@ permissions: jobs: assign-author: runs-on: ubuntu-latest + steps: - - uses: toshimaru/auto-author-assign@v2.1.0 + - name: Assign author + uses: toshimaru/auto-author-assign@v2.1.0 diff --git a/.github/workflows/draft-release-notes.yml b/.github/workflows/draft-release-notes.yml new file mode 100644 index 0000000..c9e0353 --- /dev/null +++ b/.github/workflows/draft-release-notes.yml @@ -0,0 +1,25 @@ +name: Draft release notes + +on: + push: + tags: + - '*' + branches: + - main + +permissions: + contents: write + +jobs: + release-drafter: + permissions: + contents: write + pull-requests: write + + runs-on: ubuntu-latest + + steps: + - name: Draft release notes + uses: release-drafter/release-drafter@v6 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e44cd9e..c14bf68 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,35 +4,37 @@ on: push: tags: - '*' - branches: - - main permissions: contents: write jobs: - release-drafter: - permissions: - contents: write - pull-requests: write - runs-on: ubuntu-latest - steps: - - uses: release-drafter/release-drafter@v6 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} release-php: - if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v4 - - uses: actions/cache@v4 + - name: Checkout code + uses: actions/checkout@v4 + + - name: Cache Composer dependencies + uses: actions/cache@v4 with: path: /tmp/composer-cache key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} - - uses: php-actions/composer@v6 - - name: Get Tag Name + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + + - name: Install dependencies + run: composer install + + + - name: Get tag name id: get-version run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + - name: Create Release uses: softprops/action-gh-release@v1 with: diff --git a/README.md b/README.md index a089d37..7d7c628 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,12 @@ docker compose exec phpserver composer install --ansi docker compose exec phpserver composer lint ``` +### Lint fix + +```bash +docker compose exec phpserver composer lint-fix +``` + ### Run tests ```bash diff --git a/composer.json b/composer.json index 97cffb7..2799eb3 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "phpmd/phpmd": "^2.13", "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^11.0", + "rector/rector": "^1.0.0", "squizlabs/php_codesniffer": "^3", "symfony/process": "^6.4 || ^7.0" }, @@ -43,9 +44,12 @@ "scripts": { "lint": [ "phpcs", - "phpstan" + "phpmd --exclude vendor,tests . text phpmd.xml", + "phpstan", + "rector --clear-cache --dry-run" ], - "lint:fix": [ + "lint-fix": [ + "rector --clear-cache", "phpcbf" ], "test": [ diff --git a/phpmd.xml b/phpmd.xml new file mode 100644 index 0000000..7d3cedb --- /dev/null +++ b/phpmd.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..c088341 --- /dev/null +++ b/rector.php @@ -0,0 +1,66 @@ +paths([ + __DIR__ . '/**', + ]); + + $rectorConfig->sets([ + SetList::PHP_80, + SetList::PHP_81, + SetList::CODE_QUALITY, + SetList::CODING_STYLE, + SetList::DEAD_CODE, + SetList::INSTANCEOF, + SetList::TYPE_DECLARATION, + ]); + + $rectorConfig->skip([ + // Rules added by Rector's rule sets. + ArraySpreadInsteadOfArrayMergeRector::class, + CountArrayToEmptyArrayComparisonRector::class, + DisallowedEmptyRuleFixerRector::class, + InlineArrayReturnAssignRector::class, + NewlineAfterStatementRector::class, + NewlineBeforeNewAssignSetRector::class, + PostIncDecToPreIncDecRector::class, + RemoveAlwaysTrueIfConditionRector::class, + SimplifyEmptyCheckOnEmptyArrayRector::class, + // Dependencies. + '*/vendor/*', + '*/node_modules/*', + '*/tests/*', + ]); + + $rectorConfig->fileExtensions([ + 'php', + 'inc', + ]); + + $rectorConfig->importNames(TRUE, FALSE); + $rectorConfig->importShortClasses(FALSE); +}; diff --git a/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php b/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php index fa8d5ed..b486c69 100644 --- a/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php +++ b/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php @@ -39,24 +39,18 @@ class ScreenshotContext extends RawMinkContext implements SnippetAcceptingContex /** * Screenshot directory name. - * - * @var string */ - private $dir; + private string $dir = ''; /** * Makes screenshot when fail. - * - * @var bool */ - private $fail; + private ?bool $fail = null; /** * Prefix for failed screenshot files. - * - * @var string */ - private $failPrefix; + private string $failPrefix = ''; /** * {@inheritdoc} @@ -94,7 +88,6 @@ public function beforeScenarioInit(BeforeScenarioScope $scope): void /** * Init values required for snapshot. * - * @param BeforeStepScope $scope * * @BeforeStep */ @@ -141,7 +134,7 @@ public function iSaveScreenshot($fail = false): void try { $data = $driver->getContent(); - } catch (DriverException $exception) { + } catch (DriverException) { // Do not do anything if the driver does not have any content - most // likely the page has not been loaded yet. return; @@ -158,7 +151,7 @@ public function iSaveScreenshot($fail = false): void // content and screenshot files together by name. $fileName = substr($fileName, 0, -1 * strlen('html')).'png'; $this->saveScreenshotData($fileName, $data); - } catch (UnsupportedDriverActionException $exception) { + } catch (UnsupportedDriverActionException) { // Nothing to do here - drivers without support for screenshots // simply do not have them created. } @@ -177,7 +170,7 @@ public function iSaveSizedScreenshot(string|int $width = 1440, string|int $heigh { try { $this->getSession()->resizeWindow((int) $width, (int) $height, 'current'); - } catch (UnsupportedDriverActionException $exception) { + } catch (UnsupportedDriverActionException) { // Nothing to do here - drivers without resize support may proceed. } $this->iSaveScreenshot(); diff --git a/src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php b/src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php index d8d9430..9515844 100644 --- a/src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php +++ b/src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php @@ -7,6 +7,7 @@ namespace DrevOps\BehatScreenshotExtension\ServiceContainer; +use DrevOps\BehatScreenshotExtension\Context\Initializer\ScreenshotContextInitializer; use Behat\Behat\Context\ServiceContainer\ContextExtension; use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface; use Behat\Testwork\ServiceContainer\ExtensionManager; @@ -55,14 +56,12 @@ public function initialize(ExtensionManager $extensionManager): void public function configure(ArrayNodeDefinition $builder): void { $definitionChildren = $builder->children(); - if ($definitionChildren instanceof NodeBuilder) { - // @phpstan-ignore-next-line - $definitionChildren - ->scalarNode('dir')->cannotBeEmpty()->defaultValue('%paths.base%/screenshots')->end() - ->scalarNode('fail')->cannotBeEmpty()->defaultValue(true)->end() - ->scalarNode('fail_prefix')->cannotBeEmpty()->defaultValue('failed_')->end() - ->scalarNode('purge')->cannotBeEmpty()->defaultValue(false)->end(); - } + // @phpstan-ignore-next-line + $definitionChildren + ->scalarNode('dir')->cannotBeEmpty()->defaultValue('%paths.base%/screenshots')->end() + ->scalarNode('fail')->cannotBeEmpty()->defaultValue(true)->end() + ->scalarNode('fail_prefix')->cannotBeEmpty()->defaultValue('failed_')->end() + ->scalarNode('purge')->cannotBeEmpty()->defaultValue(false)->end(); } /** @@ -70,7 +69,7 @@ public function configure(ArrayNodeDefinition $builder): void */ public function load(ContainerBuilder $container, array $config): void { - $definition = new Definition('DrevOps\BehatScreenshotExtension\Context\Initializer\ScreenshotContextInitializer', [ + $definition = new Definition(ScreenshotContextInitializer::class, [ $config['dir'], $config['fail'], $config['fail_prefix'], From f0fa7533585ec0ebea8089e1699e51983146324a Mon Sep 17 00:00:00 2001 From: "tan.nguyen" Date: Wed, 21 Feb 2024 21:26:02 +0700 Subject: [PATCH 2/7] Lint PHP. --- .../ScreenshotContextInitializer.php | 51 +++---------------- 1 file changed, 6 insertions(+), 45 deletions(-) diff --git a/src/DrevOps/BehatScreenshotExtension/Context/Initializer/ScreenshotContextInitializer.php b/src/DrevOps/BehatScreenshotExtension/Context/Initializer/ScreenshotContextInitializer.php index 7d84ca4..14f4616 100644 --- a/src/DrevOps/BehatScreenshotExtension/Context/Initializer/ScreenshotContextInitializer.php +++ b/src/DrevOps/BehatScreenshotExtension/Context/Initializer/ScreenshotContextInitializer.php @@ -18,56 +18,17 @@ class ScreenshotContextInitializer implements ContextInitializer { - /** - * Screenshot directory name. - * - * @var string - */ - protected $dir; - - /** - * Makes screenshot when fail. - * - * @var bool - */ - protected $fail; - - /** - * Prefix for failed screenshot files. - * - * @var string - */ - private $failPrefix; - - /** - * Purge dir before start test. - * - * @var bool - */ - protected $purge; - - /** - * Check if need to actually purge. - * - * @var bool - */ - protected $needsPurging; - /** * ScreenshotContextInitializer constructor. * - * @param string $dir Screenshot dir. - * @param bool $fail Screenshot when fail. - * @param string $failPrefix File name prefix for a failed test. - * @param bool $purge Purge dir before start script. + * @param string $dir Screenshot dir. + * @param bool $fail Screenshot when fail. + * @param string $failPrefix File name prefix for a failed test. + * @param bool $purge Purge dir before start script. + * @param bool $needsPurging Check if need to actually purge. */ - public function __construct(string $dir, bool $fail, string $failPrefix, bool $purge) + public function __construct(protected string $dir, protected bool $fail, private readonly string $failPrefix, protected bool $purge, protected bool $needsPurging = true) { - $this->needsPurging = true; - $this->dir = $dir; - $this->purge = $purge; - $this->fail = $fail; - $this->failPrefix = $failPrefix; } /** From 22eccd0983c9b9fc3471bb51a8a845fde55a1db8 Mon Sep 17 00:00:00 2001 From: "tan.nguyen" Date: Wed, 21 Feb 2024 21:28:08 +0700 Subject: [PATCH 3/7] Add back .editorconfig. --- .editorconfig | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0f0cdf4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,29 @@ +# This is the top-most .editorconfig file; do not search in parent directories. +root = true + +# All files. +[*] +end_of_line = LF +indent_style = space +indent_size = 4 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.{json,lock}] +indent_size = 4 + +[*.{yml,yaml}] +indent_size = 2 + +[*.yml.dist] +indent_size = 2 + +[*.{sh,bash,bats}] +indent_size = 2 + +[*.xml] +indent_size = 4 + +[*.feature] +indent_size = 2 From b816c1e26a8d722843be90ea0d5f2ea0bc48e2c7 Mon Sep 17 00:00:00 2001 From: "tan.nguyen" Date: Wed, 21 Feb 2024 21:35:58 +0700 Subject: [PATCH 4/7] Lint PHP. --- .../ServiceContainer/BehatScreenshotExtension.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php b/src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php index 9515844..e895851 100644 --- a/src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php +++ b/src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php @@ -12,8 +12,6 @@ use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface; use Behat\Testwork\ServiceContainer\ExtensionManager; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; -use Symfony\Component\Config\Definition\Builder\NodeBuilder; -use Symfony\Component\Config\Definition\Builder\NodeParentInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; From f5259c66a5bd8da85d091bdac3ea059f92701bc1 Mon Sep 17 00:00:00 2001 From: "tan.nguyen" Date: Wed, 21 Feb 2024 21:41:59 +0700 Subject: [PATCH 5/7] Lint PHP. --- .../Context/ScreenshotContext.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php b/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php index b486c69..bac7f7d 100644 --- a/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php +++ b/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php @@ -38,14 +38,14 @@ class ScreenshotContext extends RawMinkContext implements SnippetAcceptingContex protected $stepLine; /** - * Screenshot directory name. + * Makes screenshot when fail. */ - private string $dir = ''; + private bool $fail; /** - * Makes screenshot when fail. + * Screenshot directory name. */ - private ?bool $fail = null; + private string $dir = ''; /** * Prefix for failed screenshot files. From 6afd5ed030c13a006390d3e3975f13c12afd2761 Mon Sep 17 00:00:00 2001 From: "tan.nguyen" Date: Wed, 21 Feb 2024 21:45:53 +0700 Subject: [PATCH 6/7] Lint php. --- .../BehatScreenshotExtension/Context/ScreenshotContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php b/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php index bac7f7d..c1bde83 100644 --- a/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php +++ b/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php @@ -40,7 +40,7 @@ class ScreenshotContext extends RawMinkContext implements SnippetAcceptingContex /** * Makes screenshot when fail. */ - private bool $fail; + private bool $fail = false; /** * Screenshot directory name. From 246ccd153978c53eda13279978beca453f472de7 Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Thu, 22 Feb 2024 12:44:54 +1100 Subject: [PATCH 7/7] Removed obsolete release GHA. --- .github/workflows/release.yml | 41 ----------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index c14bf68..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Release - -on: - push: - tags: - - '*' - -permissions: - contents: write - -jobs: - release-php: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Cache Composer dependencies - uses: actions/cache@v4 - with: - path: /tmp/composer-cache - key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.1 - - - name: Install dependencies - run: composer install - - - - name: Get tag name - id: get-version - run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT - - - name: Create Release - uses: softprops/action-gh-release@v1 - with: - files: |