Skip to content

Commit 542cb5d

Browse files
skip classes with errors when discovering settings
1 parent 90c62ba commit 542cb5d

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `laravel-settings` will be documented in this file
44

5+
## 2.1.2 - 2020-04-08
6+
7+
- skip classes with errors when discovering settings
8+
59
## 2.1.1 - 2020-04-07
610

711
- add better support for nullable types in docblocks

src/Support/DiscoverSettings.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Spatie\LaravelSettings\Settings;
77
use SplFileInfo;
88
use Symfony\Component\Finder\Finder;
9+
use Throwable;
910

1011
class DiscoverSettings
1112
{
@@ -59,9 +60,15 @@ public function discover(): array
5960
$files = (new Finder())->files()->in($this->directories);
6061

6162
return collect($files)
62-
->reject(fn (SplFileInfo $file) => in_array($file->getPathname(), $this->ignoredFiles))
63-
->map(fn (SplFileInfo $file) => $this->fullQualifiedClassNameFromFile($file))
64-
->filter(fn (string $settingsClass) => is_subclass_of($settingsClass, Settings::class))
63+
->reject(fn(SplFileInfo $file) => in_array($file->getPathname(), $this->ignoredFiles))
64+
->map(fn(SplFileInfo $file) => $this->fullQualifiedClassNameFromFile($file))
65+
->filter(function (string $settingsClass) {
66+
try {
67+
return is_subclass_of($settingsClass, Settings::class);
68+
} catch (Throwable $e) {
69+
return false;
70+
}
71+
})
6572
->flatten()
6673
->toArray();
6774
}

src/Support/PropertyReflector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private static function reflectCompound(
103103
Compound $compound
104104
): Nullable {
105105
if ($compound->getIterator()->count() !== 2 || ! $compound->contains(new Null_())) {
106-
throw CouldNotResolveDocblockType::create($compound, $reflectionProperty);
106+
throw CouldNotResolveDocblockType::create((string) $compound, $reflectionProperty);
107107
}
108108

109109
$other = current(array_filter(

tests/TestClasses/CrashingClass.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Spatie\LaravelSettings\Tests\TestClasses;
4+
5+
class CrashingClass extends DoesNotExist
6+
{
7+
// This class should be skipped bu the settings discoverer
8+
// since it extends from a class that DoesNotExists
9+
}

0 commit comments

Comments
 (0)