Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix bug #7

Open
wants to merge 6 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Repositories/ObjectsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ private function directoriesByNamespace(string $name): array
if (str_starts_with($name, $prefix)) {
$directories = array_values(array_filter($directories, static fn (string $directory): bool => is_dir($directory)));

$prefix = str_replace('\\', DIRECTORY_SEPARATOR, ltrim(str_replace($prefix, '', $name), '\\'));
// Remove the first occurrence of the prefix, if any.
// This is needed to avoid having a prefix like "App" and a namespace like "App\Application\..."
// This would result in a directory like "\lication\..."
$posFirstPrefix = strpos($name, $prefix);
$nameWithoutPrefix = $posFirstPrefix !== false ? substr($name, $posFirstPrefix + strlen($prefix)) : $name;
nunomaduro marked this conversation as resolved.
Show resolved Hide resolved

$prefix = str_replace('\\', DIRECTORY_SEPARATOR, ltrim($nameWithoutPrefix, '\\'));

$directoriesByNamespace[$name] = [...$directoriesByNamespace[$name] ?? [], ...array_values(array_filter(array_map(static function (string $directory) use ($prefix): string {
$fileOrDirectory = $directory.DIRECTORY_SEPARATOR.$prefix;
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Tests\Fixtures\Contracts\Models\Fooable;
use Tests\Fixtures\Contracts\Models\Storable;

class Product implements Storable, Fooable, Barable
class Product implements Barable, Fooable, Storable
{
// ...
}
2 changes: 1 addition & 1 deletion tests/Layer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
expect($layer)->toUseNothing();
})->with(['App\Repositories', NonExistingClass::class, 'ray']);

it('it does include vendor dependencies', function () {
it('does include vendor dependencies', function () {
expect(DependsOnVendor::class)
->toOnlyUse('Pest')
->toOnlyUse('Pest\Support')
Expand Down
Loading