Skip to content

Commit

Permalink
Drop Drupal 8 support (#311)
Browse files Browse the repository at this point in the history
* fix: codestyle fix for EntityManagerRector.php

* Fix DrupalFinder deprecation

* Add SetListInterface deprecation to phpstan-baseline.neon

* Generate missing rule doc

* Since we need to support old drupal versions still we cannot get rid of drupalfinders old pattern

* Try with differernt whitespace

* Another try with finder for older drupal versions

* feat: drop d8 support and testing on php 7.4

* feat: Try if we can test old fixtures/rules on next Drupal version

* feat: add fixture to job name

* feat: remove old fixtures since that will not work.

* feat: remove Drupal 8 rules from default set

* feat: reenable d8 rules.

* fix: remove fixture from job titles
  • Loading branch information
bbrala authored Oct 24, 2024
1 parent 50c742a commit 6d3a501
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 22 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/functional_test__rector_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,18 @@ on:

jobs:
run_functional_test:
name: Functional Test | PHP ${{ matrix.php-version }} | Drupal ${{ matrix.drupal }}"
name: Functional | PHP ${{ matrix.php-version }} | Drupal ${{ matrix.drupal }}"
strategy:
fail-fast: false
matrix:
include:
- php-version: "7.4"
drupal: "^8.9"
fixture: "d8"
- php-version: "7.4"
drupal: "^9.2"
fixture: "d9"
- php-version: "8.0"
drupal: "^9.2"
fixture: "d9"
- php-version: "8.1"
drupal: "^10.0"
fixture: "d10"
- php-version: "8.2"
- php-version: "8.3"
drupal: "^10.0"
fixture: "d10"
runs-on: ubuntu-latest
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"keywords": [
"code style",
"rector",
"drupal 8",
"drupal 9",
"drupal",
"ast"
],
"require": {
Expand Down
11 changes: 8 additions & 3 deletions config/drupal-phpunit-bootstrap-file.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
* This fixes Drupal testing namespace autoloading and PHPUnit compatibility.
*/

use DrupalFinder\DrupalFinder;
use Rector\Core\Autoloading\BootstrapFilesIncluder;
use Rector\Core\Exception\ShouldNotHappenException;

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

if (class_exists('DrupalFinder\DrupalFinderComposerRuntime')) {
$drupalFinder = new DrupalFinder\DrupalFinderComposerRuntime();
} else {
$drupalFinder = new DrupalFinder\DrupalFinder();
$drupalFinder->locateRoot(__DIR__);
}

$drupalRoot = $drupalFinder->getDrupalRoot();
$drupalVendorRoot = $drupalFinder->getVendorDir();

Expand Down
19 changes: 17 additions & 2 deletions docs/rules_overview.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# 54 Rules Overview
# 55 Rules Overview

<br>

## Categories

- [Drupal10](#drupal10) (3)
- [Drupal10](#drupal10) (4)

- [Drupal8](#drupal8) (18)

Expand Down Expand Up @@ -72,6 +72,21 @@ Fixes deprecated `system_time_zones()` calls

<br>

### VersionedFunctionToServiceRector

Fixes deprecated function to service calls, used in Drupal 8 and 9 deprecations

:wrench: **configure it!**

- class: [`DrupalRector\Drupal10\Rector\Deprecation\VersionedFunctionToServiceRector`](../src/Drupal10/Rector/Deprecation/VersionedFunctionToServiceRector.php)

```diff
-_drupal_flush_css_js();
+\Drupal::service('asset.query_string')->reset();
```

<br>

### WatchdogExceptionRector

Fixes deprecated watchdog_exception('update', `$exception)` calls
Expand Down
62 changes: 62 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
parameters:
ignoreErrors:
-
message: """
#^Call to deprecated method locateRoot\\(\\) of class DrupalFinder\\\\DrupalFinder\\:
Will be removed in v2\\. Future usage should instantiate
a new DrupalFinder object by passing the starting path to its
constructor\\.$#
"""
count: 1
path: config/drupal-phpunit-bootstrap-file.php

-
message: "#^Function drupal_phpunit_contrib_extension_directory_roots\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -35,6 +45,34 @@ parameters:
count: 1
path: config/drupal-phpunit-bootstrap-file.php

-
message: """
#^Instantiation of deprecated class DrupalFinder\\\\DrupalFinder\\:
in drupal\\-finder\\:1\\.3\\.0 and is removed from drupal\\-finder\\:2\\.0\\.0\\.
Use \\\\DrupalFinder\\\\DrupalFinderComposerRuntime instead\\.$#
"""
count: 1
path: config/drupal-phpunit-bootstrap-file.php

-
message: """
#^Call to deprecated method locateRoot\\(\\) of class DrupalFinder\\\\DrupalFinder\\:
Will be removed in v2\\. Future usage should instantiate
a new DrupalFinder object by passing the starting path to its
constructor\\.$#
"""
count: 1
path: rector.php

-
message: """
#^Instantiation of deprecated class DrupalFinder\\\\DrupalFinder\\:
in drupal\\-finder\\:1\\.3\\.0 and is removed from drupal\\-finder\\:2\\.0\\.0\\.
Use \\\\DrupalFinder\\\\DrupalFinderComposerRuntime instead\\.$#
"""
count: 1
path: rector.php

-
message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$value\\.$#"
count: 2
Expand Down Expand Up @@ -117,3 +155,27 @@ parameters:
"""
count: 1
path: src/Drupal9/Rector/Deprecation/PassRector.php

-
message: """
#^Class DrupalRector\\\\Set\\\\Drupal10SetList implements deprecated interface Rector\\\\Set\\\\Contract\\\\SetListInterface\\:
This interface needs a reflection to load and uses constant links\\. Now we changed to services provider architecture that can be used and registerd easily\\. Use$#
"""
count: 1
path: src/Set/Drupal10SetList.php

-
message: """
#^Class DrupalRector\\\\Set\\\\Drupal8SetList implements deprecated interface Rector\\\\Set\\\\Contract\\\\SetListInterface\\:
This interface needs a reflection to load and uses constant links\\. Now we changed to services provider architecture that can be used and registerd easily\\. Use$#
"""
count: 1
path: src/Set/Drupal8SetList.php

-
message: """
#^Class DrupalRector\\\\Set\\\\Drupal9SetList implements deprecated interface Rector\\\\Set\\\\Contract\\\\SetListInterface\\:
This interface needs a reflection to load and uses constant links\\. Now we changed to services provider architecture that can be used and registerd easily\\. Use$#
"""
count: 1
path: src/Set/Drupal9SetList.php
11 changes: 8 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);

use DrupalFinder\DrupalFinder;
use DrupalRector\Set\Drupal10SetList;
use DrupalRector\Set\Drupal8SetList;
use DrupalRector\Set\Drupal9SetList;
Expand All @@ -12,14 +11,20 @@
// Adjust the set lists to be more granular to your Drupal requirements.
// @todo find out how to only load the relevant rector rules.
// Should we try and load \Drupal::VERSION and check?
// new possible option with ComposerTriggeredSet
// https://github.com/rectorphp/rector-src/blob/b5a5739b7d7dde621053adff113449860ed5331f/src/Set/ValueObject/ComposerTriggeredSet.php
$rectorConfig->sets([
Drupal8SetList::DRUPAL_8,
Drupal9SetList::DRUPAL_9,
Drupal10SetList::DRUPAL_10,
]);

$drupalFinder = new DrupalFinder();
$drupalFinder->locateRoot(__DIR__);
if (class_exists('DrupalFinder\DrupalFinderComposerRuntime')) {
$drupalFinder = new DrupalFinder\DrupalFinderComposerRuntime();
} else {
$drupalFinder = new DrupalFinder\DrupalFinder();
$drupalFinder->locateRoot(__DIR__);
}
$drupalRoot = $drupalFinder->getDrupalRoot();
$rectorConfig->autoloadPaths([
$drupalRoot . '/core',
Expand Down
6 changes: 2 additions & 4 deletions src/Drupal8/Rector/Deprecation/EntityManagerRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ final class EntityManagerRector extends AbstractRector
*/
private AddCommentService $commentService;

public function __construct(
ParentClassScopeResolver $parentClassScopeResolver,
AddCommentService $commentService
) {
public function __construct(ParentClassScopeResolver $parentClassScopeResolver, AddCommentService $commentService)
{
$this->parentClassScopeResolver = $parentClassScopeResolver;
$this->commentService = $commentService;
}
Expand Down

0 comments on commit 6d3a501

Please sign in to comment.