branch: externals/phpinspect commit 4793b78ad5776746a22c14b9e4d0218c12e78e73 Author: Hugo Thunnissen <de...@hugot.nl> Commit: Hugo Thunnissen <de...@hugot.nl>
Detect use of type for casting and try/catch exception types --- phpinspect-index.el | 10 ++++++++++ test/test-index.el | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/phpinspect-index.el b/phpinspect-index.el index 015a36a7a5..220df3d6fc 100644 --- a/phpinspect-index.el +++ b/phpinspect-index.el @@ -599,6 +599,16 @@ Returns a list of type name strings." (phpinspect-var-annotation-type token)) (setq used-types-rear (setcdr used-types-rear (cons (phpinspect-var-annotation-type token) nil)))) + + ((and (phpinspect-list-p token) + (phpinspect-word-p (cadr token)) + (or + ;; type cast + (= 1 (length (cdr token))) + ;; Try/catch + (and (phpinspect-word-p previous-token) + (string= "catch" (cadr previous-token))))) + (setq used-types-rear (setcdr used-types-rear (cons (cadadr token) nil)))) ((and (phpinspect-static-attrib-p token) (phpinspect-word-p previous-token)) (let ((type (cadr previous-token))) diff --git a/test/test-index.el b/test/test-index.el index 0f9e7c2fc2..fe57c66cd2 100644 --- a/test/test-index.el +++ b/test/test-index.el @@ -105,9 +105,12 @@ if ((new Monkey())->tree() === true) { return StaticThing::create(new ThingFactory())->makeThing((((new Potato())->antiPotato(new OtherThing(function (InnerFunctionParam $param) { if ($param instanceof InstanceOffed) { /** @var VarAnnotation $bing */ - $bing = [ 'bong' => [ 'nested' => NestedArray::call(), ], ]; +try { + $bing = [ 'bong' => [ 'nested' => (CastedType) NestedArray::call(), ], ]; +} catch (CaughtException $e) { // nothing } +} }))))); }"))) (used-types (alist-get 'used-types (car (alist-get 'classes result))))) @@ -119,7 +122,7 @@ if ($param instanceof InstanceOffed) { "StaticThing" "Thing" "ThingFactory" "Potato" "OtherThing" "InnerFunctionParam" "PropertyType" "InstanceOffed" "NestedArray" "UsedTrait" "VarAnnotation" "ParamAnnotation" - "ThrowAnnotationException")) + "ThrowAnnotationException" "CaughtException" "CastedType")) #'string<)) (sort used-types (lambda (s1 s2) (string< (phpinspect-name-string s1) (phpinspect-name-string s2))))))))