Skip to content

Commit

Permalink
refactor: check for type rather than null value to be more explicit. …
Browse files Browse the repository at this point in the history
…Untangle nested ifs to early returns allowing for quick exit.

Signed-off-by: Sacha Telgenhof <me@sachatelgenhof.com>
  • Loading branch information
stelgenhof committed Jun 25, 2023
1 parent 3b0da70 commit 6f87212
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/Yasumi/Yasumi.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static function create(string $class, int $year = self::YEAR_LOWER_BOUND,
}

// Load internal translations variable
if (null === self::$globalTranslations) {
if (! self::$globalTranslations instanceof Translations) {
self::$globalTranslations = new Translations(self::$locales);
self::$globalTranslations->loadTranslations(__DIR__.'/data/translations');
}
Expand Down Expand Up @@ -237,9 +237,16 @@ public static function getProviders(): array
$class = new \ReflectionClass(sprintf('Yasumi\Provider\%s', str_replace('/', '\\', $provider)));

$key = 'ID';
if ($class->isSubclassOf(AbstractProvider::class) && $class->hasConstant($key)) {
$providers[strtoupper($class->getConstant($key))] = $provider;

if (! $class->isSubclassOf(AbstractProvider::class)) {
continue;
}

if (! $class->hasConstant($key)) {
continue;
}

$providers[strtoupper($class->getConstant($key))] = $provider;
}

return $providers;
Expand Down
3 changes: 2 additions & 1 deletion tests/Ukraine/SubstitutedHolidayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public function assertHolidayWithSubstitution(
self::assertEquals(Holiday::TYPE_OFFICIAL, $holidayOfficial->getType());

$holidaySubstitution = $holidays->getHoliday('substituteHoliday:'.$holidayOfficial->getKey());
if (null === $expectedSubstitution) {

if (! $expectedSubstitution instanceof \DateTimeInterface) {
// without substitution
self::assertNull($holidaySubstitution);
} else {
Expand Down

0 comments on commit 6f87212

Please sign in to comment.