Skip to content

Commit

Permalink
Merge branch 'main' into apply-php-8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
JavierCane authored Dec 11, 2023
2 parents 9d3830c + c4d2f25 commit ff32293
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 1 addition & 18 deletions src/Shared/Domain/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit ff32293

Please sign in to comment.