From f1dc69956022977baa5b8bede66620e72a4dfcc7 Mon Sep 17 00:00:00 2001 From: Hugo Thunnissen Date: Wed, 14 Aug 2024 13:07:01 +0200 Subject: [PATCH] Detect types used with "instanceoff" --- phpinspect-index.el | 2 +- test/test-index.el | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/phpinspect-index.el b/phpinspect-index.el index 913c2f6..861e355 100644 --- a/phpinspect-index.el +++ b/phpinspect-index.el @@ -513,7 +513,7 @@ Returns a list of type name strings." (let ((token (pop tokens)) (previous-token (car previous-tokens))) (cond ((and (phpinspect-word-p previous-token) - (string= "new" (cadr previous-token)) + (member (cadr previous-token) `("new" "instanceof")) (phpinspect-word-p token)) (let ((type (cadr token))) (when (not (string-match-p "\\\\" type)) diff --git a/test/test-index.el b/test/test-index.el index 31635b9..faf243e 100644 --- a/test/test-index.el +++ b/test/test-index.el @@ -96,7 +96,11 @@ public function makeThing(): Thing if ((new Monkey())->tree() === true) { return new ExtendedThing(); } -return StaticThing::create(new ThingFactory())->makeThing((((new Potato())->antiPotato(new OtherThing(function (InnerFunctionParam $param) {}))))); +return StaticThing::create(new ThingFactory())->makeThing((((new Potato())->antiPotato(new OtherThing(function (InnerFunctionParam $param) { +if ($param instanceof InstanceOffed) { +// nothing +} +}))))); }"))) (used-types (alist-get 'used-types (car (alist-get 'classes result))))) (should (equal @@ -105,7 +109,7 @@ return StaticThing::create(new ThingFactory())->makeThing((((new Potato())->anti (copy-sequence '("Cheese" "Bacon" "Ham" "Bagel" "Monkey" "ExtendedThing" "StaticThing" "Thing" "ThingFactory" "Potato" "OtherThing" - "InnerFunctionParam" "PropertyType")) + "InnerFunctionParam" "PropertyType" "InstanceOffed")) #'string<)) (sort used-types (lambda (s1 s2) (string< (phpinspect-name-string s1) (phpinspect-name-string s2))))))))