From 2066c122d0fa0c74263be10c0f73fda0861684f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Wed, 9 Nov 2022 23:29:03 +0100 Subject: [PATCH 1/3] Add support for Attributes --- specs/misc/attributes.php | 80 +++++++++++++++++++ .../NodeVisitor/NameStmtPrefixer.php | 14 ++-- 2 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 specs/misc/attributes.php diff --git a/specs/misc/attributes.php b/specs/misc/attributes.php new file mode 100644 index 00000000..d8a3f4da --- /dev/null +++ b/specs/misc/attributes.php @@ -0,0 +1,80 @@ +, + * Pádraic Brady + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +return [ + 'meta' => [ + 'title' => 'Attributes', + // Default values. If not specified will be the one used + 'prefix' => 'Humbug', + + 'expose-global-constants' => false, + 'expose-global-classes' => false, + 'expose-global-functions' => false, + 'expose-namespaces' => [], + 'expose-constants' => [], + 'expose-classes' => [], + 'expose-functions' => [], + + 'exclude-namespaces' => [], + 'exclude-constants' => [], + 'exclude-classes' => [], + 'exclude-functions' => [], + + 'expected-recorded-classes' => [], + 'expected-recorded-functions' => [], + ], + + 'FQCN attribute' => <<<'PHP' + <<<'PHP' + $parentNode instanceof $supportedClassName, + self::SUPPORTED_PARENT_NODE_CLASS_NAMES, + ); } private function isNamePrefixable(Name $resolvedName): bool From 9f710d3f2792e5db8f4f6ba0486cb093aebf460a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Wed, 9 Nov 2022 23:40:54 +0100 Subject: [PATCH 2/3] Revert --- src/PhpParser/NodeVisitor/NameStmtPrefixer.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/PhpParser/NodeVisitor/NameStmtPrefixer.php b/src/PhpParser/NodeVisitor/NameStmtPrefixer.php index 119a4440..7d03b0eb 100644 --- a/src/PhpParser/NodeVisitor/NameStmtPrefixer.php +++ b/src/PhpParser/NodeVisitor/NameStmtPrefixer.php @@ -48,7 +48,6 @@ use PhpParser\Node\UnionType; use PhpParser\NodeVisitorAbstract; use function in_array; -use function iter\any; use function strtolower; /** @@ -221,10 +220,13 @@ private function prefixName(Name $resolvedName, Node $parentNode): Node private static function isParentNodeSupported(Node $parentNode): bool { - return any( - static fn (string $supportedClassName) => $parentNode instanceof $supportedClassName, - self::SUPPORTED_PARENT_NODE_CLASS_NAMES, - ); + foreach (self::SUPPORTED_PARENT_NODE_CLASS_NAMES as $supportedClassName) { + if ($parentNode instanceof $supportedClassName) { + return true; + } + } + + return false; } private function isNamePrefixable(Name $resolvedName): bool From e89c5c3c54871be059238654bac84719827ace98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Wed, 9 Nov 2022 23:47:44 +0100 Subject: [PATCH 3/3] Fix unit tests --- specs/misc/first-class-callables.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/misc/first-class-callables.php b/specs/misc/first-class-callables.php index cdf66ecd..33c53a70 100644 --- a/specs/misc/first-class-callables.php +++ b/specs/misc/first-class-callables.php @@ -73,7 +73,7 @@ function b() {} new \Humbug\X\A(...); $this->foo(...); $this?->foo(...); - #[\X\A(...)] + #[A(...)] function b() { }