Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"ast"
],
"require": {
"rector/rector": "^1 || ^2",
"rector/rector": "^1 || ^2.4.1",
Comment thread
bbrala marked this conversation as resolved.
Outdated
"webflo/drupal-finder": "^1.2"
},
"license": "MIT",
Expand Down
16 changes: 12 additions & 4 deletions src/Rector/Convert/HookConvertRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@

public function refactor(Node $node): Node|int|null
{
$filePath = $this->file->getFilePath();
$filePath = method_exists($this, 'getFile')

Check failure on line 130 in src/Rector/Convert/HookConvertRector.php

View workflow job for this annotation

GitHub Actions / Static analysis with PHPStan (8.2, ^2, phpstan.neon)

Call to function method_exists() with $this(DrupalRector\Rector\Convert\HookConvertRector) and 'getFile' will always evaluate to true.
? $this->getFile()->getFilePath()
: $this->file->getFilePath();
$ext = pathinfo($filePath, \PATHINFO_EXTENSION);
if (!in_array($ext, ['inc', 'module'])) {
return null;
Expand Down Expand Up @@ -181,7 +183,9 @@
protected function initializeHookClass(): void
{
$this->__destruct();
$this->moduleDir = $this->file->getFilePath();
$this->moduleDir = method_exists($this, 'getFile')

Check failure on line 186 in src/Rector/Convert/HookConvertRector.php

View workflow job for this annotation

GitHub Actions / Static analysis with PHPStan (8.2, ^2, phpstan.neon)

Call to function method_exists() with $this(DrupalRector\Rector\Convert\HookConvertRector) and 'getFile' will always evaluate to true.
? $this->getFile()->getFilePath()
: $this->file->getFilePath();
$this->inputFilename = $this->moduleDir;
// Find the relevant info.yml: it's either in the current directory or
// one of the parents.
Expand All @@ -190,7 +194,7 @@
if (!empty($info)) {
$infoFile = reset($info);
$this->module = basename($infoFile, '.info.yml');
$filename = pathinfo($this->file->getFilePath(), \PATHINFO_FILENAME);
$filename = pathinfo(method_exists($this, 'getFile') ? $this->getFile()->getFilePath() : $this->file->getFilePath(), \PATHINFO_FILENAME);

Check failure on line 197 in src/Rector/Convert/HookConvertRector.php

View workflow job for this annotation

GitHub Actions / Static analysis with PHPStan (8.2, ^2, phpstan.neon)

Call to function method_exists() with $this(DrupalRector\Rector\Convert\HookConvertRector) and 'getFile' will always evaluate to true.
$hookClassName = ucfirst(CaseStringHelper::camelCase(str_replace('.', '_', $filename).'_hooks'));
$counter = '';
do {
Expand All @@ -217,7 +221,11 @@
$hookClassStmts = [
new Node\Stmt\Namespace_(new Node\Name($namespace)),
...$this->useStmts,
new Use_([new Node\Stmt\UseUse(new Node\Name('Drupal\Core\Hook\Attribute\Hook'))]),
new Use_([
class_exists('PhpParser\Node\UseItem')
? new Node\UseItem(new Node\Name('Drupal\Core\Hook\Attribute\Hook'))
: new Node\Stmt\UseUse(new Node\Name('Drupal\Core\Hook\Attribute\Hook')),
]),
$this->hookClass,
];
$this->hookClass->setDocComment(new \PhpParser\Comment\Doc("/**\n * Hook implementations for $this->module.\n */"));
Expand Down
Loading