diff --git a/src/Support/LaravelDocumentationLinkFinder.php b/src/Support/LaravelDocumentationLinkFinder.php index c02115d1..568bb038 100644 --- a/src/Support/LaravelDocumentationLinkFinder.php +++ b/src/Support/LaravelDocumentationLinkFinder.php @@ -15,7 +15,7 @@ public function findLinkForThrowable(Throwable $throwable): ?string $throwable = $throwable->getPrevious(); } - $majorVersion = explode('.', app()->version())[0]; + $majorVersion = LaravelVersion::major(); if (str_contains($throwable->getMessage(), Collection::class)) { return "https://laravel.com/docs/{$majorVersion}.x/collections#available-methods"; diff --git a/src/Support/LaravelVersion.php b/src/Support/LaravelVersion.php index 81e7ade2..c1035783 100644 --- a/src/Support/LaravelVersion.php +++ b/src/Support/LaravelVersion.php @@ -6,6 +6,6 @@ class LaravelVersion { public static function major(): string { - return substr(app()->version(), 0, 1); + return explode('.', app()->version())[0]; } } diff --git a/tests/Support/LaravelDocumentationLinkFinderTest.php b/tests/Support/LaravelDocumentationLinkFinderTest.php index 857e9fc7..39b34cd4 100644 --- a/tests/Support/LaravelDocumentationLinkFinderTest.php +++ b/tests/Support/LaravelDocumentationLinkFinderTest.php @@ -2,6 +2,7 @@ use Illuminate\Auth\AuthenticationException; use Spatie\LaravelIgnition\Support\LaravelDocumentationLinkFinder; +use Spatie\LaravelIgnition\Support\LaravelVersion; beforeEach(function () { $this->finder = new LaravelDocumentationLinkFinder(); @@ -10,7 +11,7 @@ it('can find a link for a laravel exception', function () { $link = $this->finder->findLinkForThrowable(new AuthenticationException()); - $majorVersion = explode('.', app()->version())[0]; + $majorVersion = LaravelVersion::major(); expect($link)->toEqual("https://laravel.com/docs/{$majorVersion}.x/authentication"); });