From 2033d8edf54dbdbe63b313df383d79a09eeb90ff Mon Sep 17 00:00:00 2001 From: Theo D Date: Fri, 17 May 2024 03:26:43 +0200 Subject: [PATCH] feat: Generate stubs in same location where `castor.php` is located by default --- CHANGELOG.md | 1 + src/Stub/StubsGenerator.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51e49e30..3b1f81bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - `null` is now the default value (only user notifications are displayed). - `true` to enable notifications globally (user and Castor generated notifications) - `false` to disable them globally +* `.castor.stub.php` is now generated in same location where `castor.php` is located ### Deprecations diff --git a/src/Stub/StubsGenerator.php b/src/Stub/StubsGenerator.php index 34cee734..7ed6c2f7 100644 --- a/src/Stub/StubsGenerator.php +++ b/src/Stub/StubsGenerator.php @@ -98,7 +98,8 @@ private function generateStubs(string $dest): void new \PhpParser\Comment\Doc('// This file has been generated by castor. Do not edit it manually.'), new \PhpParser\Comment\Doc('// It helps IDEs to provide better autocompletion and analysis.'), new \PhpParser\Comment\Doc('// You can safely ignore this file in your VCS.'), - new \PhpParser\Comment\Doc('// You can also move this file to ".castor/.castor.stub.php".'), + new \PhpParser\Comment\Doc('// ".castor.stub.php" by default is in the same location of "castor.php".'), + new \PhpParser\Comment\Doc('// You can also move this file at the root of your project or to ".castor/.castor.stub.php".'), new \PhpParser\Comment\Doc(''), ], ])); @@ -126,7 +127,12 @@ private function shouldGenerate(): ?string } } - return $files[0]; + $generateLocation = $files[0]; + if (file_exists($this->rootDir . '/.castor/castor.php')) { + $generateLocation = $files[1]; + } + + return $generateLocation; } private function isOutdated(string $file): bool