Skip to content

Commit

Permalink
Merge pull request #457 from TheoD02/feat/generate_stubs_in_same_loca…
Browse files Browse the repository at this point in the history
…tion_of_castor_file

feat: Generate stubs in same location where `castor.php` is located by default
  • Loading branch information
lyrixx committed May 17, 2024
2 parents cd471ae + 2033d8e commit 2744629
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions src/Stub/StubsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(''),
],
]));
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2744629

Please sign in to comment.