Skip to content

Commit 01515ff

Browse files
committed
Refactor
1 parent b02cd0b commit 01515ff

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

src/Install/GuidelineComposer.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,13 @@ protected function getPackageGuidelines(): Collection
184184
}
185185
}
186186

187-
$guidelines = collect([$guidelineDir.'/core' => $this->resolveGuideline(
188-
$vendorPath ? $vendorPath.DIRECTORY_SEPARATOR.'core' : null,
189-
$guidelineDir.'/core',
190-
$guidelineDir.'/core',
191-
)]);
187+
$vendorCorePath = $vendorPath !== null
188+
? $vendorPath.DIRECTORY_SEPARATOR.'core'
189+
: null;
190+
191+
$guidelines = collect([
192+
$guidelineDir.'/core' => $this->resolveGuideline($vendorCorePath, $guidelineDir.'/core'),
193+
]);
192194

193195
$packageGuidelines = $this->guidelinesDir($guidelineDir.'/'.$package->majorVersion());
194196

@@ -208,17 +210,17 @@ protected function getPackageGuidelines(): Collection
208210
/**
209211
* @return array{content: string, name: string, description: string, path: ?string, custom: bool, third_party: bool}
210212
*/
211-
private function resolveGuideline(?string $vendorPath, string $aiFallback, string $overrideKey): array
213+
private function resolveGuideline(?string $vendorPath, string $guidelineKey): array
212214
{
213215
if ($vendorPath !== null) {
214216
foreach (['.blade.php', '.md'] as $ext) {
215217
if (file_exists($vendorPath.$ext)) {
216-
return $this->guideline($vendorPath.$ext, false, $overrideKey);
218+
return $this->guideline($vendorPath.$ext, false, $guidelineKey);
217219
}
218220
}
219221
}
220222

221-
return $this->guideline($aiFallback);
223+
return $this->guideline($guidelineKey);
222224
}
223225

224226
/**

tests/Feature/Install/GuidelineComposerTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@
813813
->makePartial()
814814
->shouldAllowMockingProtectedMethods();
815815
$composer->shouldReceive('resolveFirstPartyBoostPath')
816-
->andReturnUsing(fn (\Laravel\Roster\Package $package, string $subpath): ?string => $package->rawName() === 'pestphp/pest' ? $vendorFixture : null);
816+
->andReturnUsing(fn (Package $package, string $subpath): ?string => $package->rawName() === 'pestphp/pest' ? $vendorFixture : null);
817817

818818
$guidelines = $composer->compose();
819819

@@ -854,7 +854,7 @@
854854
->makePartial()
855855
->shouldAllowMockingProtectedMethods();
856856
$composer->shouldReceive('resolveFirstPartyBoostPath')
857-
->andReturnUsing(fn (\Laravel\Roster\Package $package, string $subpath): ?string => $package->rawName() === 'pestphp/pest' ? $vendorFixture : null);
857+
->andReturnUsing(fn (Package $package, string $subpath): ?string => $package->rawName() === 'pestphp/pest' ? $vendorFixture : null);
858858

859859
$keys = $composer->used();
860860

@@ -876,7 +876,7 @@
876876
$composer->shouldReceive('customGuidelinePath')
877877
->andReturnUsing(fn ($path = ''): string => realpath(testDirectory('Fixtures/.ai/guidelines')).'/'.ltrim((string) $path, '/'));
878878
$composer->shouldReceive('resolveFirstPartyBoostPath')
879-
->andReturnUsing(fn (\Laravel\Roster\Package $package, string $subpath): ?string => $package->rawName() === 'laravel/framework' ? $vendorFixture : null);
879+
->andReturnUsing(fn (Package $package, string $subpath): ?string => $package->rawName() === 'laravel/framework' ? $vendorFixture : null);
880880

881881
$guidelines = $composer->guidelines();
882882
$laravelCore = $guidelines->get('laravel/core');
@@ -915,7 +915,7 @@
915915
->makePartial()
916916
->shouldAllowMockingProtectedMethods();
917917
$composer->shouldReceive('resolveFirstPartyBoostPath')
918-
->andReturnUsing(fn (\Laravel\Roster\Package $package, string $subpath): ?string => $package->rawName() === '@inertiajs/react' ? $vendorFixture : null);
918+
->andReturnUsing(fn (Package $package, string $subpath): ?string => $package->rawName() === '@inertiajs/react' ? $vendorFixture : null);
919919

920920
$guidelines = $composer->compose();
921921

@@ -957,10 +957,10 @@
957957
->makePartial()
958958
->shouldAllowMockingProtectedMethods();
959959
$composer->shouldReceive('resolveFirstPartyBoostPath')
960-
->andReturnUsing(fn (\Laravel\Roster\Package $package, string $subpath): ?string => $package->rawName() === '@inertiajs/react' ? $vendorFixture : null);
960+
->andReturnUsing(fn (Package $package, string $subpath): ?string => $package->rawName() === '@inertiajs/react' ? $vendorFixture : null);
961961

962962
$guidelines = $composer->guidelines();
963-
$vendorEntries = $guidelines->filter(fn (array $g): bool => str_contains($g['content'], 'Vendor Core Guideline'));
963+
$vendorEntries = $guidelines->filter(fn (array $g): bool => str_contains((string) $g['content'], 'Vendor Core Guideline'));
964964

965965
expect($vendorEntries)->toHaveCount(1);
966966
});
@@ -983,7 +983,7 @@
983983
->makePartial()
984984
->shouldAllowMockingProtectedMethods();
985985
$composer->shouldReceive('resolveFirstPartyBoostPath')
986-
->andReturnUsing(fn (\Laravel\Roster\Package $package, string $subpath): ?string => $package->rawName() === 'pestphp/pest' ? $vendorFixture : null);
986+
->andReturnUsing(fn (Package $package, string $subpath): ?string => $package->rawName() === 'pestphp/pest' ? $vendorFixture : null);
987987
$composer->shouldReceive('customGuidelinePath')
988988
->andReturnUsing(fn ($path = ''): string => $mdOverrideDir.'/'.ltrim((string) $path, '/'));
989989

tests/Feature/Install/SkillComposerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
->makePartial()
145145
->shouldAllowMockingProtectedMethods();
146146
$composer->shouldReceive('resolveFirstPartyBoostPath')
147-
->andReturnUsing(fn (\Laravel\Roster\Package $package, string $subpath): ?string => $package->rawName() === 'livewire/livewire' ? $vendorFixture : null);
147+
->andReturnUsing(fn (Package $package, string $subpath): ?string => $package->rawName() === 'livewire/livewire' ? $vendorFixture : null);
148148

149149
$skills = $composer->skills();
150150

@@ -185,7 +185,7 @@
185185
->makePartial()
186186
->shouldAllowMockingProtectedMethods();
187187
$composer->shouldReceive('resolveFirstPartyBoostPath')
188-
->andReturnUsing(fn (\Laravel\Roster\Package $package, string $subpath): ?string => $package->rawName() === '@inertiajs/react' ? $vendorFixture : null);
188+
->andReturnUsing(fn (Package $package, string $subpath): ?string => $package->rawName() === '@inertiajs/react' ? $vendorFixture : null);
189189

190190
$skills = $composer->skills();
191191

0 commit comments

Comments
 (0)