Skip to content

Commit

Permalink
skip classes with errors when discovering settings
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Apr 8, 2021
1 parent 90c62ba commit 542cb5d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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

## 2.1.2 - 2020-04-08

- skip classes with errors when discovering settings

## 2.1.1 - 2020-04-07

- add better support for nullable types in docblocks
Expand Down
13 changes: 10 additions & 3 deletions src/Support/DiscoverSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Spatie\LaravelSettings\Settings;
use SplFileInfo;
use Symfony\Component\Finder\Finder;
use Throwable;

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

return collect($files)
->reject(fn (SplFileInfo $file) => in_array($file->getPathname(), $this->ignoredFiles))
->map(fn (SplFileInfo $file) => $this->fullQualifiedClassNameFromFile($file))
->filter(fn (string $settingsClass) => is_subclass_of($settingsClass, Settings::class))
->reject(fn(SplFileInfo $file) => in_array($file->getPathname(), $this->ignoredFiles))
->map(fn(SplFileInfo $file) => $this->fullQualifiedClassNameFromFile($file))
->filter(function (string $settingsClass) {
try {
return is_subclass_of($settingsClass, Settings::class);
} catch (Throwable $e) {
return false;
}
})
->flatten()
->toArray();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Support/PropertyReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static function reflectCompound(
Compound $compound
): Nullable {
if ($compound->getIterator()->count() !== 2 || ! $compound->contains(new Null_())) {
throw CouldNotResolveDocblockType::create($compound, $reflectionProperty);
throw CouldNotResolveDocblockType::create((string) $compound, $reflectionProperty);
}

$other = current(array_filter(
Expand Down
9 changes: 9 additions & 0 deletions tests/TestClasses/CrashingClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Spatie\LaravelSettings\Tests\TestClasses;

class CrashingClass extends DoesNotExist
{
// This class should be skipped bu the settings discoverer
// since it extends from a class that DoesNotExists
}

0 comments on commit 542cb5d

Please sign in to comment.