diff --git a/src/Mooc/Shared/Infrastructure/Doctrine/DbalTypesSearcher.php b/src/Mooc/Shared/Infrastructure/Doctrine/DbalTypesSearcher.php index 42c562543..34ec057f4 100644 --- a/src/Mooc/Shared/Infrastructure/Doctrine/DbalTypesSearcher.php +++ b/src/Mooc/Shared/Infrastructure/Doctrine/DbalTypesSearcher.php @@ -4,8 +4,6 @@ namespace CodelyTv\Mooc\Shared\Infrastructure\Doctrine; -use CodelyTv\Shared\Domain\Utils; - use function Lambdish\Phunctional\filter; use function Lambdish\Phunctional\map; use function Lambdish\Phunctional\reduce; @@ -51,7 +49,7 @@ private static function dbalClassesSearcher(string $contextName): callable { return static function (array $totalNamespaces, string $path) use ($contextName): array { $possibleFiles = scandir($path); - $files = filter(static fn (string $file): bool => Utils::endsWith('Type.php', $file), $possibleFiles); + $files = filter(static fn (string $file): bool => str_ends_with($file, 'Type.php'), $possibleFiles); $namespaces = map( static function (string $file) use ($path, $contextName): string { diff --git a/src/Shared/Domain/Utils.php b/src/Shared/Domain/Utils.php index 7939ff26b..a50521eea 100644 --- a/src/Shared/Domain/Utils.php +++ b/src/Shared/Domain/Utils.php @@ -6,21 +6,10 @@ use DateTimeImmutable; use DateTimeInterface; -use RuntimeException; use function Lambdish\Phunctional\filter; final class Utils { - public static function endsWith(string $needle, string $haystack): bool - { - $length = strlen($needle); - if ($length === 0) { - return true; - } - - return substr($haystack, -$length) === $needle; - } - public static function dateToString(DateTimeInterface $date): string { return $date->format(DateTimeInterface::ATOM); @@ -38,13 +27,7 @@ public static function jsonEncode(array $values): string public static function jsonDecode(string $json): array { - $data = json_decode($json, true); - - if (json_last_error() !== JSON_ERROR_NONE) { - throw new RuntimeException('Unable to parse response body into JSON: ' . json_last_error()); - } - - return $data; + return json_decode($json, true, flags: JSON_THROW_ON_ERROR); } public static function toSnakeCase(string $text): string