Skip to content

Commit

Permalink
updated Inject detection
Browse files Browse the repository at this point in the history
Signed-off-by: alexmerlin <[email protected]>
  • Loading branch information
alexmerlin committed Jun 13, 2024
1 parent 723248c commit 6f460a7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions di-converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,17 @@
* Replace @Inject(dependencies) with #[Inject(dependencies)] in all classes
*/
if (str_contains($after, '@Inject({')) {
preg_match('#/\*\*\n\s*\*\s*@Inject[\s\S\n]*?\*/#', $after, $injectTag);
preg_match('#/\**\n*\s*\**\s*@Inject[\s\S\n]*?\*/#', $after, $injectTag);

if (isset($injectTag[0])) {
$injectTag = $injectTag[0];

preg_match_all('/^\s*\*\s*(\b\w*\b::class,*|"[a-zA-Z0-9-._]*",*)$/m', $injectTag, $oldDependencies);
preg_match_all('/[^,\s{]+::class|".+?"/m', $injectTag, $oldDependencies);

$newDependencies = [];
if (isset($oldDependencies[1])) {
if (! empty($oldDependencies[0])) {
$newDependencies[] = '#[Inject(';
foreach ($oldDependencies[1] as $dependency) {
foreach ($oldDependencies[0] as $dependency) {
if (! str_ends_with($dependency, ',')) {
$dependency .= ',';
}
Expand Down

0 comments on commit 6f460a7

Please sign in to comment.