From dff18a054af585603f080715ab2ff0149d712cf7 Mon Sep 17 00:00:00 2001 From: Emilien Escalle Date: Mon, 5 Dec 2022 20:17:00 +0100 Subject: [PATCH] feat: remove support for php 7.4 --- .github/dependabot.yml | 4 ++-- .github/workflows/continuous-integration.yml | 7 +++---- Makefile | 2 ++ composer.json | 10 ++++----- src/Documentation/Test/Config.php | 4 ++-- src/Documentation/Test/SnapshotService.php | 2 +- .../View/Helper/DescriptionList.php | 6 +++--- src/TwbsHelper/View/Helper/Dropdown.php | 12 +++++------ src/TwbsHelper/View/Helper/GridColumn.php | 2 +- .../View/Helper/HtmlAttributes/HtmlClass.php | 3 ++- .../HtmlClass/HelperPluginManager.php | 8 ++++++- .../View/Helper/Navigation/Menu.php | 16 +++++++------- .../Helper/HtmlAttributes/HtmlClassTest.php | 21 +++++++++++++++++++ .../View/Helper/Navigation/MenuTest.php | 19 +++++++++++++++++ 14 files changed, 82 insertions(+), 34 deletions(-) create mode 100644 tests/TestSuite/TwbsHelper/View/Helper/HtmlAttributes/HtmlClassTest.php create mode 100644 tests/TestSuite/TwbsHelper/View/Helper/Navigation/MenuTest.php diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 113367f81..433e9a496 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -2,14 +2,14 @@ version: 2 updates: - package-ecosystem: composer open-pull-requests-limit: 20 - versioning-strategy: increase + versioning-strategy: widen directory: "/" schedule: interval: weekly day: friday - package-ecosystem: npm open-pull-requests-limit: 20 - versioning-strategy: increase + versioning-strategy: widen directory: "/website" schedule: interval: weekly diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 4555ffe39..3a5b4b5b9 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -13,7 +13,6 @@ jobs: strategy: matrix: include: - - php-versions: "7.4" - php-versions: "8.0" - php-versions: "8.1" stable: true @@ -27,7 +26,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} - extensions: none, json, dom, tokenizer, xml, xmlwriter, simplexml, iconv, mbstring, intl, sodium + extensions: none, curl, json, dom, tokenizer, xml, xmlwriter, simplexml, iconv, mbstring, intl, sodium coverage: pcov - name: โ™ป๏ธ Get composer cache directory @@ -42,7 +41,7 @@ jobs: restore-keys: ${{ runner.os }}-composer- - name: โš™๏ธ Install dependencies - run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader + run: composer install --no-progress --prefer-dist --optimize-autoloader - name: ๐Ÿ‘• Lint run: composer cs @@ -61,7 +60,7 @@ jobs: - name: ๐Ÿงช Test run: composer test:ci - - name: ๐Ÿ“Š Upload coverage results to Coveralls + - name: ๐Ÿ“Š Upload coverage results to Codecov if: matrix.stable uses: codecov/codecov-action@v3 with: diff --git a/Makefile b/Makefile index ebf104bb1..784fb4db0 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,9 @@ build-php: ## Build PHP image for given version @DOCKER_BUILDKIT=1 docker build -t "twbs-helper-php:$(filter-out $@,$(MAKECMDGOALS))" --build-arg "VERSION=$(filter-out $@,$(MAKECMDGOALS))" . install: + rm -f composer.lock @$(call run-php,$(filter-out $@,$(MAKECMDGOALS)) composer install --no-progress --prefer-dist --optimize-autoloader) + rm -f composer.lock shell: @$(call run-php,$(filter-out $@,$(MAKECMDGOALS)) bash) diff --git a/composer.json b/composer.json index 65527ba00..e29c3057f 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "twitter/bootstrap": "Twitter bootstrap assets" }, "require": { - "php": "^7.4 || ~8.0.0 || ~8.1.0", + "php": "~8.0.0 || ~8.1.0", "laminas/laminas-escaper": "^2.12", "laminas/laminas-form": "^3.4", "laminas/laminas-i18n": "^2.17", @@ -43,11 +43,11 @@ "laminas/laminas-mvc": "^3.3", "mikey179/vfsstream": "^1.6", "pcov/clobber": "^2.0", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", + "phpstan/extension-installer": "^1.2", + "phpstan/phpstan": "^1.9", + "phpstan/phpstan-phpunit": "^1.2", "phpunit/phpunit": "^9.5.26", - "slam/phpstan-laminas-framework": "^0.12", + "slam/phpstan-laminas-framework": "^1.3", "spatie/phpunit-snapshot-assertions": "^4.2", "squizlabs/php_codesniffer": "^3.7" }, diff --git a/src/Documentation/Test/Config.php b/src/Documentation/Test/Config.php index 367915f66..61427b795 100644 --- a/src/Documentation/Test/Config.php +++ b/src/Documentation/Test/Config.php @@ -7,9 +7,9 @@ class Config public static $TITLE_SEPARATOR = ' / '; /** - * @var string + * @var string|null */ - public $title; + public $title = null; /** * @var string diff --git a/src/Documentation/Test/SnapshotService.php b/src/Documentation/Test/SnapshotService.php index ccc36096e..8f04770ad 100644 --- a/src/Documentation/Test/SnapshotService.php +++ b/src/Documentation/Test/SnapshotService.php @@ -26,6 +26,6 @@ public function getSnapshotPathFromTitle(string $title, $incrementor = 1): strin $snapshotFile = $safePath . '__' . $incrementor . '.html'; return $this->testsDirectoryPath . DIRECTORY_SEPARATOR . - static::$SNAPSHOT_ROOT_DIRECTORY . DIRECTORY_SEPARATOR . $snapshotFile; + self::$SNAPSHOT_ROOT_DIRECTORY . DIRECTORY_SEPARATOR . $snapshotFile; } } diff --git a/src/TwbsHelper/View/Helper/DescriptionList.php b/src/TwbsHelper/View/Helper/DescriptionList.php index 276f0875e..b0fd39f0d 100644 --- a/src/TwbsHelper/View/Helper/DescriptionList.php +++ b/src/TwbsHelper/View/Helper/DescriptionList.php @@ -49,7 +49,7 @@ public function render(array $items, iterable $optionsAndAttributes = [], bool $ } $attributes = $this->getView()->plugin('htmlattributes') - ->__invoke($optionsAndAttributes ?? []) + ->__invoke($optionsAndAttributes ?: []) ->merge(['class' => ['row']]); return $this->renderContainer( @@ -175,7 +175,7 @@ protected function renderListItemTerm( unset($termOptionsAndAttributes['column']); $attributes = $this->getView()->plugin('htmlattributes') - ->__invoke($termOptionsAndAttributes ?? []) + ->__invoke($termOptionsAndAttributes ?: []) ->merge([ 'class' => $this->getView()->plugin('htmlClass')->plugin('column')->getClassesFromOption( $columSize @@ -211,7 +211,7 @@ protected function renderListItemDetail( unset($detailOptionsAndAttributes['column']); $attributes = $this->getView()->plugin('htmlattributes') - ->__invoke($detailOptionsAndAttributes ?? []) + ->__invoke($detailOptionsAndAttributes ?: []) ->merge([ 'class' => $this->getView()->plugin('htmlClass')->plugin('column')->getClassesFromOption( $columSize diff --git a/src/TwbsHelper/View/Helper/Dropdown.php b/src/TwbsHelper/View/Helper/Dropdown.php index 44b0c468e..f1e74dd6b 100644 --- a/src/TwbsHelper/View/Helper/Dropdown.php +++ b/src/TwbsHelper/View/Helper/Dropdown.php @@ -109,7 +109,7 @@ protected function createDropdown($dropdown) throw new \InvalidArgumentException(sprintf( 'Argument "$dropdown" expects %s, "%s" given', 'an instanceof \Laminas\Form\ElementInterface or an iterable', - is_object($dropdown) ? get_class($dropdown) : gettype($dropdown) + get_class($dropdown) )); } return $dropdown; @@ -175,9 +175,9 @@ protected function renderToggle(\Laminas\Form\ElementInterface $dropdown): strin $toogleElementAttributes = $toogleElement->getAttributes(); foreach ( [ - 'data-bs-toggle' => 'dropdown', - 'data-bs-offset' => $dropdownOptions['offset'] ?? null, - 'aria-expanded' => 'false', + 'data-bs-toggle' => 'dropdown', + 'data-bs-offset' => $dropdownOptions['offset'] ?? null, + 'aria-expanded' => 'false', ] as $attributeName => $defaultValue ) { if ($defaultValue !== null && !isset($toogleElementAttributes[$attributeName])) { @@ -478,8 +478,8 @@ protected function renderItem(array $itemOptions, bool $escape): string foreach ( [ - 'active' => ['aria-current' => 'true'], - 'disabled' => ['tabindex' => '-1', 'aria-disabled' => 'true'], + 'active' => ['aria-current' => 'true'], + 'disabled' => ['tabindex' => '-1', 'aria-disabled' => 'true'], ] as $option => $optionAttributes ) { if (empty($itemOptions[$option])) { diff --git a/src/TwbsHelper/View/Helper/GridColumn.php b/src/TwbsHelper/View/Helper/GridColumn.php index feadc460f..3077e1c5f 100644 --- a/src/TwbsHelper/View/Helper/GridColumn.php +++ b/src/TwbsHelper/View/Helper/GridColumn.php @@ -121,7 +121,7 @@ protected function prepareAttributes(iterable $optionsAndAttributes): iterable ); } - $colOption = $optionsAndAttributes['column'] ?? $options['column'] ?? true; + $colOption = $optionsAndAttributes['column'] ?? true; $attributes['class']->merge( $this->getView()->plugin('htmlClass')->plugin('column')->getClassesFromOption($colOption) ); diff --git a/src/TwbsHelper/View/Helper/HtmlAttributes/HtmlClass.php b/src/TwbsHelper/View/Helper/HtmlAttributes/HtmlClass.php index 99288052b..e32351a45 100644 --- a/src/TwbsHelper/View/Helper/HtmlAttributes/HtmlClass.php +++ b/src/TwbsHelper/View/Helper/HtmlAttributes/HtmlClass.php @@ -49,11 +49,12 @@ public function setHelperPluginManager($helperPluginManager) } $helperPluginManager = new $helperPluginManager(new \Laminas\ServiceManager\ServiceManager()); } + if (!$helperPluginManager instanceof \TwbsHelper\View\Helper\HtmlAttributes\HtmlClass\HelperPluginManager) { throw new \InvalidArgumentException(sprintf( 'Helper helpers must extend %s; got type "%s" instead', \TwbsHelper\View\Helper\HtmlAttributes\HtmlClass\HelperPluginManager::class, - (is_object($helperPluginManager) ? get_class($helperPluginManager) : gettype($helperPluginManager)) + get_class($helperPluginManager) )); } $this->helperPluginManager = $helperPluginManager; diff --git a/src/TwbsHelper/View/Helper/HtmlAttributes/HtmlClass/HelperPluginManager.php b/src/TwbsHelper/View/Helper/HtmlAttributes/HtmlClass/HelperPluginManager.php index cd96eeede..1f17536b5 100644 --- a/src/TwbsHelper/View/Helper/HtmlAttributes/HtmlClass/HelperPluginManager.php +++ b/src/TwbsHelper/View/Helper/HtmlAttributes/HtmlClass/HelperPluginManager.php @@ -2,6 +2,8 @@ namespace TwbsHelper\View\Helper\HtmlAttributes\HtmlClass; +use Laminas\ServiceManager\ConfigInterface; + /** * Plugin manager implementation for HTML class attribute helpers * @@ -31,8 +33,10 @@ class HelperPluginManager extends \Laminas\ServiceManager\AbstractPluginManager /** * Default factories + * * @var array */ + /** @phpstan-ignore-next-line */ protected $factories = [ \TwbsHelper\View\Helper\HtmlAttributes\HtmlClass\Helper\Align::class => \Laminas\ServiceManager\Factory\InvokableFactory::class, @@ -63,6 +67,8 @@ class HelperPluginManager extends \Laminas\ServiceManager\AbstractPluginManager * Sets the provided $parentLocator as the creation context for all * factories; for $config, {@see \Laminas\ServiceManager\ServiceManager::configure()} * for details on its accepted structure. + * @param null|ConfigInterface|\Psr\Container\ContainerInterface $configInstanceOrParentLocator + * @param array $config */ public function __construct($configInstanceOrParentLocator = null, array $config = []) { @@ -76,7 +82,7 @@ public function __construct($configInstanceOrParentLocator = null, array $config */ public function injectHtmlClassHelper($first, $second) { - $helper = ($first instanceof \Interop\Container\ContainerInterface) + $helper = ($first instanceof \Psr\Container\ContainerInterface) ? $second : $first; diff --git a/src/TwbsHelper/View/Helper/Navigation/Menu.php b/src/TwbsHelper/View/Helper/Navigation/Menu.php index 29b99313b..e8fcc7dd1 100644 --- a/src/TwbsHelper/View/Helper/Navigation/Menu.php +++ b/src/TwbsHelper/View/Helper/Navigation/Menu.php @@ -96,7 +96,7 @@ function ($matches) { $content = $this->renderMenuItemsLink($content, $options); - return $content ?? ''; + return $content ?: ''; } protected function renderMenuItemsNav(string $content, iterable $options): string @@ -214,13 +214,13 @@ protected function getMenuItemsNavClasses(iterable $options, bool $isRoot): iter $classes = []; foreach ( [ - 'tabs' => 'nav-tabs', - 'pills' => 'nav-pills', - 'fill' => 'nav-fill', - 'justified' => 'nav-justified', - 'centered' => 'justify-content-center', - 'right_aligned' => 'justify-content-end', - 'vertical' => 'flex-column', + 'tabs' => 'nav-tabs', + 'pills' => 'nav-pills', + 'fill' => 'nav-fill', + 'justified' => 'nav-justified', + 'centered' => 'justify-content-center', + 'right_aligned' => 'justify-content-end', + 'vertical' => 'flex-column', ] as $option => $className ) { if (!empty($options[$option])) { diff --git a/tests/TestSuite/TwbsHelper/View/Helper/HtmlAttributes/HtmlClassTest.php b/tests/TestSuite/TwbsHelper/View/Helper/HtmlAttributes/HtmlClassTest.php new file mode 100644 index 000000000..eaf39bd2d --- /dev/null +++ b/tests/TestSuite/TwbsHelper/View/Helper/HtmlAttributes/HtmlClassTest.php @@ -0,0 +1,21 @@ +expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage( + 'Helper helpers must extend TwbsHelper\View\Helper\HtmlAttributes\HtmlClass\HelperPluginManager; ' . + 'got type "stdClass" instead' + ); + $this->helper->setHelperPluginManager(\stdClass::class); + } +} diff --git a/tests/TestSuite/TwbsHelper/View/Helper/Navigation/MenuTest.php b/tests/TestSuite/TwbsHelper/View/Helper/Navigation/MenuTest.php new file mode 100644 index 000000000..1398f3ff2 --- /dev/null +++ b/tests/TestSuite/TwbsHelper/View/Helper/Navigation/MenuTest.php @@ -0,0 +1,19 @@ +assertEquals( + '', + $this->helper->renderMenu() + ); + } +}