Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated code to comply with PHPStan level 7. #274

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .ahoy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,19 @@ commands:
lint:
usage: Lint code.
cmd: |
ahoy cli "cp -Rf phpcs.xml phpstan.neon phpmd.xml gherkinlint.json build > /dev/null" \
ahoy cli "cp -Rf phpcs.xml phpstan.neon phpmd.xml gherkinlint.json rector.php build > /dev/null" \
&& ahoy cli "cd /app/build && ./vendor/bin/phpcs" \
&& ahoy cli "cd /app/build && ./vendor/bin/phpstan" \
&& ahoy cli "cd /app/build && ./vendor/bin/rector --clear-cache --dry-run" \
&& ahoy cli "cd /app/build && ./vendor/bin/phpmd ../src text phpmd.xml" \
&& ahoy cli "cd /app/build && ./vendor/bin/phpmd ../tests/behat/bootstrap text phpmd.xml" \
&& ahoy cli "cd /app/build && ./vendor/bin/phpstan" \
&& ahoy cli "cd /app/build && ./vendor/bin/rector process ../src --clear-cache --dry-run" \
&& ahoy cli "cd /app/build && ./vendor/bin/gherkinlint lint ../tests/behat/features"

lint-fix:
usage: Fix code.
cmd: |
ahoy cli "cp -Rf phpcs.xml phpstan.neon build > /dev/null" \
&& ahoy cli "cd /app/build && ./vendor/bin/rector process ../src --clear-cache" \
ahoy cli "cp -Rf phpcs.xml phpstan.neon phpmd.xml gherkinlint.json rector.php build > /dev/null" \
&& ahoy cli "cd /app/build && ./vendor/bin/rector --clear-cache" \
&& ahoy cli "cd /app/build && ./vendor/bin/phpcbf"

test-bdd:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"source": "https://github.com/drevops/behat-steps"
},
"require": {
"php": ">=8.1",
"php": ">=8.2",
"behat/behat": "^3",
"behat/mink": ">=1.11",
"behat/mink-selenium2-driver": ">=1.7",
Expand Down
7 changes: 7 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@

<!-- Coding standard. -->
<rule ref="Drupal"/>
<rule ref="Generic.PHP.RequireStrictTypes" />
<rule ref="PHPCompatibility"/>

<!-- Show sniff codes in all reports -->
<arg value="s"/>
<!-- Show progress of the run. -->
<arg value="p"/>
<arg name="colors"/>

<arg name="parallel" value="75"/>

<!-- Lint code against min PHP version specified in composer.json. -->
<config name="testVersion" value="8.2"/>

<file>../src</file>
<file>../tests/behat/bootstrap</file>

Expand Down
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

parameters:

level: 5
level: 7

phpVersion: 80224

paths:
- ../src
Expand All @@ -13,6 +15,7 @@ parameters:
excludePaths:
- vendor/*
- node_modules/*
- ../tests/behat/bootstrap/BehatCliContext.php

scanFiles:
- vendor/behat/behat/bin/behat
48 changes: 21 additions & 27 deletions tests/behat/fixtures/d10/rector.php → rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

declare(strict_types=1);

use DrupalFinder\DrupalFinder;
use DrupalFinder\DrupalFinderComposerRuntime;
use DrupalRector\Set\Drupal10SetList;
use DrupalRector\Set\Drupal8SetList;
use DrupalRector\Set\Drupal9SetList;
Expand All @@ -23,11 +23,28 @@
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
use Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector;
use Rector\Php81\Rector\Array_\FirstClassCallableRector;
use Rector\Set\ValueObject\SetList;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;

return static function (RectorConfig $rectorConfig): void {
$drupalFinder = new DrupalFinderComposerRuntime();
$drupalRoot = $drupalFinder->getDrupalRoot();

$rectorConfig->autoloadPaths([
$drupalRoot . '/core',
$drupalRoot . '/modules',
$drupalRoot . '/themes',
$drupalRoot . '/profiles',
]);

$rectorConfig->paths([
$drupalRoot . '/../../src',
$drupalRoot . '/../../tests/behat/bootstrap',
]);

$rectorConfig->sets([
// Provided by Rector.
SetList::PHP_80,
Expand All @@ -46,21 +63,12 @@

$rectorConfig->rule(DeclareStrictTypesRector::class);

$drupalFinder = new DrupalFinder();
$drupalFinder->locateRoot(__DIR__);

$drupalRoot = $drupalFinder->getDrupalRoot();
$rectorConfig->autoloadPaths([
$drupalRoot . '/core',
$drupalRoot . '/modules',
$drupalRoot . '/themes',
$drupalRoot . '/profiles',
]);

$rectorConfig->skip([
// Rules added by Rector's rule sets.
ChangeSwitchToMatchRector::class,
CountArrayToEmptyArrayComparisonRector::class,
DisallowedEmptyRuleFixerRector::class,
FirstClassCallableRector::class,
InlineArrayReturnAssignRector::class,
NewlineAfterStatementRector::class,
NewlineBeforeNewAssignSetRector::class,
Expand All @@ -69,21 +77,7 @@
// Dependencies.
'*/vendor/*',
'*/node_modules/*',
// Core and contribs.
'*/core/*',
'*/modules/contrib/*',
'*/themes/contrib/*',
'*/profiles/contrib/*',
'*/sites/default/default.settings.php',
// Files.
'*/sites/default/files/*',
'*/sites/simpletest/*',
// Scaffold files.
'*/autoload.php',
'*/index.php',
'*/update.php',
// Composer scripts.
'*/scripts/composer/*',
$drupalRoot . '/../../tests/behat/bootstrap/BehatCliContext.php',
]);

$rectorConfig->fileExtensions([
Expand Down
16 changes: 8 additions & 8 deletions src/ContentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function contentRemoveContentType(string $type): void {
* @When I visit :type :title
*/
public function contentVisitPageWithTitle(string $type, string $title): void {
$nids = $this->contentNodeLoadMultiple($type, [
$nids = $this->contentLoadMultiple($type, [
'title' => $title,
]);

Expand All @@ -67,7 +67,7 @@ public function contentVisitPageWithTitle(string $type, string $title): void {
* @When I edit :type :title
*/
public function contentEditPageWithTitle(string $type, string $title): void {
$nids = $this->contentNodeLoadMultiple($type, [
$nids = $this->contentLoadMultiple($type, [
'title' => $title,
]);

Expand All @@ -87,7 +87,7 @@ public function contentEditPageWithTitle(string $type, string $title): void {
* @When I delete :type :title
*/
public function contentDeletePageWithTitle(string $type, string $title): void {
$nids = $this->contentNodeLoadMultiple($type, [
$nids = $this->contentLoadMultiple($type, [
'title' => $title,
]);

Expand Down Expand Up @@ -115,7 +115,7 @@ public function contentDeletePageWithTitle(string $type, string $title): void {
*/
public function contentDelete(string $type, TableNode $nodesTable): void {
foreach ($nodesTable->getHash() as $nodeHash) {
$nids = $this->contentNodeLoadMultiple($type, $nodeHash);
$nids = $this->contentLoadMultiple($type, $nodeHash);

$controller = \Drupal::entityTypeManager()->getStorage('node');
$entities = $controller->loadMultiple($nids);
Expand Down Expand Up @@ -161,7 +161,7 @@ public function contentModeratePageWithTitle(string $type, string $title, string
* @When I visit :type :title scheduled transitions
*/
public function contentVisitScheduledTransitionsPageWithTitle(string $type, string $title): void {
$nids = $this->contentNodeLoadMultiple($type, [
$nids = $this->contentLoadMultiple($type, [
'title' => $title,
]);

Expand All @@ -180,13 +180,13 @@ public function contentVisitScheduledTransitionsPageWithTitle(string $type, stri
*
* @param string $type
* The node type.
* @param array $conditions
* @param array<string, mixed> $conditions
* Conditions keyed by field names.
*
* @return array
* @return array<int, string>
* Array of node ids.
*/
protected function contentNodeLoadMultiple(string $type, array $conditions = []) {
protected function contentLoadMultiple(string $type, array $conditions = []): array {
$query = \Drupal::entityQuery('node')
->accessCheck(FALSE)
->condition('type', $type);
Expand Down
Loading