mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-16 16:12:22 +00:00
Updated Rector to commit 7e7304b93cd03fda558ac8ebfbc682ffa4938fe0
7e7304b93c
[AutoImport] Handle DeclareStrictTypesRector on importNames() enabled on no namespace (#5241)
This commit is contained in:
parent
e41e10db62
commit
e26480f1cb
|
@ -52,28 +52,28 @@ CODE_SAMPLE
|
||||||
if ($newStmts === []) {
|
if ($newStmts === []) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$stmt = \current($newStmts);
|
$rootStmt = \current($newStmts);
|
||||||
if ($stmt instanceof FileWithoutNamespace) {
|
$stmt = $rootStmt;
|
||||||
$currentStmt = \current($stmt->stmts);
|
if ($rootStmt instanceof FileWithoutNamespace) {
|
||||||
|
$currentStmt = \current($rootStmt->stmts);
|
||||||
if (!$currentStmt instanceof Stmt) {
|
if (!$currentStmt instanceof Stmt) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$nodes = $stmt->stmts;
|
$nodes = $rootStmt->stmts;
|
||||||
$stmt = $currentStmt;
|
$stmt = $currentStmt;
|
||||||
}
|
}
|
||||||
// when first stmt is Declare_, verify if there is strict_types definition already,
|
if ($this->shouldSkip($stmt)) {
|
||||||
// as multiple declare is allowed, with declare(strict_types=1) only allowed on very first stmt
|
return null;
|
||||||
if ($stmt instanceof Declare_) {
|
|
||||||
foreach ($stmt->declares as $declare) {
|
|
||||||
if ($declare->key->toString() === 'strict_types') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$declareDeclare = new DeclareDeclare(new Identifier('strict_types'), new LNumber(1));
|
$declareDeclare = new DeclareDeclare(new Identifier('strict_types'), new LNumber(1));
|
||||||
$strictTypesDeclare = new Declare_([$declareDeclare]);
|
$strictTypesDeclare = new Declare_([$declareDeclare]);
|
||||||
$rectorWithLineChange = new RectorWithLineChange(self::class, $stmt->getLine());
|
$rectorWithLineChange = new RectorWithLineChange(self::class, $stmt->getLine());
|
||||||
$this->file->addRectorClassWithLine($rectorWithLineChange);
|
$this->file->addRectorClassWithLine($rectorWithLineChange);
|
||||||
|
if ($rootStmt instanceof FileWithoutNamespace) {
|
||||||
|
/** @var Stmt[] $nodes */
|
||||||
|
$rootStmt->stmts = \array_merge([$strictTypesDeclare, new Nop()], $nodes);
|
||||||
|
return [$rootStmt];
|
||||||
|
}
|
||||||
return \array_merge([$strictTypesDeclare, new Nop()], $nodes);
|
return \array_merge([$strictTypesDeclare, new Nop()], $nodes);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -91,4 +91,17 @@ CODE_SAMPLE
|
||||||
// workaroudn, as Rector now only hooks to specific nodes, not arrays
|
// workaroudn, as Rector now only hooks to specific nodes, not arrays
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
private function shouldSkip(Stmt $stmt) : bool
|
||||||
|
{
|
||||||
|
// when first stmt is Declare_, verify if there is strict_types definition already,
|
||||||
|
// as multiple declare is allowed, with declare(strict_types=1) only allowed on very first stmt
|
||||||
|
if ($stmt instanceof Declare_) {
|
||||||
|
foreach ($stmt->declares as $declare) {
|
||||||
|
if ($declare->key->toString() === 'strict_types') {
|
||||||
|
return \true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return \false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const PACKAGE_VERSION = '2f74b02ef6c754c68abcdd246837583967e24678';
|
public const PACKAGE_VERSION = '7e7304b93cd03fda558ac8ebfbc682ffa4938fe0';
|
||||||
/**
|
/**
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const RELEASE_DATE = '2023-11-11 02:09:43';
|
public const RELEASE_DATE = '2023-11-11 04:52:41';
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user