From 52a2fa6b20d58a08829c32829be1ee9b509939c9 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Tue, 6 Apr 2021 13:40:59 +0200 Subject: [PATCH 1/5] deps: add laravel-ide-helper constraint This avoids a BC break in `barryvdh/laravel-ide-helper` 2.9.2, which changed the visibility of several methods from `protected` to `public`. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 91b8e76..2746fa7 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "require": { "php": "^7.3|^8", "ext-simplexml": "*", - "barryvdh/laravel-ide-helper": "^2.8.0", + "barryvdh/laravel-ide-helper": ">=2.8.0 <2.9.2", "illuminate/container": "^6.0 || ^7.0 || ^8.0", "illuminate/contracts": "^6.0 || ^7.0 || ^8.0", "illuminate/database": "^6.0 || ^7.0 || ^8.0", From b404a2706b2460fbf9ea86d44701437c787eb4fc Mon Sep 17 00:00:00 2001 From: yaegassy Date: Fri, 16 Apr 2021 13:41:45 +0900 Subject: [PATCH 2/5] Added support for not stopping the execution of psalm even when a error occurs. --- src/Plugin.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index 41e3a93..48608b7 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -25,17 +25,18 @@ class Plugin implements PluginEntryPointInterface public function __invoke(RegistrationInterface $registration, ?SimpleXMLElement $config = null) : void { - $app = ApplicationHelper::bootApp(); + try { + $app = ApplicationHelper::bootApp(); + $fake_filesystem = new FakeFilesystem(); + $view_factory = $this->getViewFactory($app, $fake_filesystem); + $cache_dir = __DIR__ . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR; - $fake_filesystem = new FakeFilesystem(); - - $view_factory = $this->getViewFactory($app, $fake_filesystem); - - $cache_dir = __DIR__ . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR; - - $this->ingestFacadeStubs($registration, $app, $fake_filesystem, $view_factory, $cache_dir); - $this->ingestMetaStubs($registration, $app, $fake_filesystem, $view_factory, $cache_dir); - $this->ingestModelStubs($registration, $app, $fake_filesystem, $cache_dir); + $this->ingestFacadeStubs($registration, $app, $fake_filesystem, $view_factory, $cache_dir); + $this->ingestMetaStubs($registration, $app, $fake_filesystem, $view_factory, $cache_dir); + $this->ingestModelStubs($registration, $app, $fake_filesystem, $cache_dir); + } catch (\Error $e) { + return; + } require_once 'ReturnTypeProvider/AuthReturnTypeProvider.php'; $registration->registerHooksFromClass(ReturnTypeProvider\AuthReturnTypeProvider::class); From 5753fef6377acf197138d50d1440786eaad205d6 Mon Sep 17 00:00:00 2001 From: yaegassy Date: Sun, 18 Apr 2021 05:15:43 +0900 Subject: [PATCH 3/5] fix: Change to catching "Throwable". --- src/Plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin.php b/src/Plugin.php index 48608b7..382d4c9 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -34,7 +34,7 @@ class Plugin implements PluginEntryPointInterface $this->ingestFacadeStubs($registration, $app, $fake_filesystem, $view_factory, $cache_dir); $this->ingestMetaStubs($registration, $app, $fake_filesystem, $view_factory, $cache_dir); $this->ingestModelStubs($registration, $app, $fake_filesystem, $cache_dir); - } catch (\Error $e) { + } catch (\Throwable $t) { return; } From 72aa7cae299e96ec39b2e59d2bb0e7a892d17960 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Sat, 1 May 2021 17:02:20 -0400 Subject: [PATCH 4/5] Fix #128 - prevent crash calling arbitrary methods on Application interface This adds a stub for the Container interface, adding a necessary mention for ArrayAccess --- src/AppInterfaceProvider.php | 2 -- src/Stubs/Container.stubphp | 26 ++++++++++++++++++++++++++ tests/acceptance/Container.feature | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/Stubs/Container.stubphp diff --git a/src/AppInterfaceProvider.php b/src/AppInterfaceProvider.php index 2d8b0bc..6a16c3f 100644 --- a/src/AppInterfaceProvider.php +++ b/src/AppInterfaceProvider.php @@ -35,7 +35,6 @@ class AppInterfaceProvider implements ) : ?bool { if ($method_name_lowercase === 'offsetget' || $method_name_lowercase === 'offsetset' - || $method_name_lowercase === '__call' ) { return true; } @@ -55,7 +54,6 @@ class AppInterfaceProvider implements ) : ?bool { if ($method_name_lowercase === 'offsetget' || $method_name_lowercase === 'offsetset' - || $method_name_lowercase === '__call' ) { return true; } diff --git a/src/Stubs/Container.stubphp b/src/Stubs/Container.stubphp new file mode 100644 index 0000000..0bba7ac --- /dev/null +++ b/src/Stubs/Container.stubphp @@ -0,0 +1,26 @@ + """ + Scenario: Application interface does not error + Given I have the following code + """ + app->foo("a", "b"); + } + } + """ + When I run Psalm + Then I see these errors + | Type | Message | + | UndefinedInterfaceMethod | Method Illuminate\Contracts\Foundation\Application::foo does not exist | + Scenario: the container resolves correct types Given I have the following code """ From 2b7fe4581a35cefcc656ba61664903a3950a675a Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Sat, 1 May 2021 17:05:01 -0400 Subject: [PATCH 5/5] Update failing test --- tests/acceptance/CollectionTypes.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/acceptance/CollectionTypes.feature b/tests/acceptance/CollectionTypes.feature index 7502827..b793f8f 100644 --- a/tests/acceptance/CollectionTypes.feature +++ b/tests/acceptance/CollectionTypes.feature @@ -146,6 +146,6 @@ Feature: collection types | InvalidReturnType | The declared return type 'bool' for CollectionTypes::failingTest is incorrect, got 'null\|string' | | NullableReturnStatement | The declared return type 'bool' for CollectionTypes::failingTest is not nullable, but the function returns 'null\|string' | | InvalidReturnStatement | The inferred type 'null\|string' does not match the declared return type 'bool' for CollectionTypes::failingTest | - | InvalidScalarArgument | Argument 2 of Illuminate\Support\Collection::put expects string, int(2) provided | + | InvalidScalarArgument | Argument 2 of Illuminate\Support\Collection::put expects string, 2 provided | And I see no other errors