diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dd01da5..8b08168 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: ['8.2'] + php-versions: ['8.0', '8.1', '8.2', '8.3'] name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} steps: diff --git a/composer.json b/composer.json index 2f95717..23dee9b 100644 --- a/composer.json +++ b/composer.json @@ -10,16 +10,16 @@ "license": "MIT", "authors": [ { - "name": "Moamen Eltouny", - "email": "support@raggitech.com" + "name": "Moamen Eltouny (Raggi)", + "email": "raggigroup@gmail.com" } ], "require": { - "php": "^8.2", - "nesbot/carbon": "^3.0" + "php": ">=8.0", + "nesbot/carbon": ">=2.20.0" }, "require-dev": { - "phpunit/phpunit": ">=5.0" + "orchestra/testbench": "^7.0" }, "config": { "sort-packages": true diff --git a/phpunit.xml b/phpunit.xml.dist similarity index 100% rename from phpunit.xml rename to phpunit.xml.dist diff --git a/src/Hijri.php b/src/Hijri.php index 44b16ab..bc5d8a0 100644 --- a/src/Hijri.php +++ b/src/Hijri.php @@ -3,9 +3,7 @@ namespace Pharaonic\Hijri; use Carbon\Carbon; -use Carbon\Month; use Carbon\Translator; -use Carbon\WeekDay; use DateTimeInterface; use DateTimeZone; @@ -65,8 +63,6 @@ class Hijri extends Carbon */ protected $CURRENT_DAY = null; - - /** * Getting an instance of Hijri class. * @@ -142,11 +138,16 @@ private function convertToHijri() * as it allows you to do Carbon::parse('Monday next week')->fn() rather * than (new Carbon('Monday next week'))->fn(). * + * @param string|DateTimeInterface|null $time + * @param DateTimeZone|string|null $tz + * * @throws InvalidFormatException + * + * @return static */ - public static function parse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null): static + public static function parse($time = null, $tz = null) { - return self::$HIJRI_INSTANCE->prepare(parent::parse($time, $timezone)); + return self::$HIJRI_INSTANCE->prepare(parent::parse($time, $tz)); } /** @@ -157,7 +158,7 @@ public static function parse(DateTimeInterface|WeekDay|Month|string|int|float|nu * * @return $this|string */ - public function locale(?string $locale = null, string ...$fallbackLocales): static|string + public function locale(string $locale = null, ...$fallbackLocales) { if ($locale === null) { return $this->getTranslatorLocale(); @@ -197,8 +198,10 @@ public function locale(?string $locale = null, string ...$fallbackLocales): stat * @param string|null $context whole format string * @param string $keySuffix "", "_short" or "_min" * @param string|null $defaultValue default value if translation missing + * + * @return string */ - public function getTranslatedDayName(?string $context = null, string $keySuffix = '', ?string $defaultValue = null): string + public function getTranslatedDayName($context = null, $keySuffix = '', $defaultValue = null) { return $this->getTranslatedFormByRegExp('weekdays', $keySuffix, $context, $this->CURRENT_DAY, $defaultValue ?: $this->englishDayOfWeek); } @@ -229,8 +232,10 @@ protected function getTranslatedFormByRegExp($baseKey, $keySuffix, $context, $su * @param string|null $context whole format string * @param string $keySuffix "" or "_short" * @param string|null $defaultValue default value if translation missing + * + * @return string */ - public function getTranslatedMonthName(?string $context = null, string $keySuffix = '', ?string $defaultValue = null): string + public function getTranslatedMonthName($context = null, $keySuffix = '', $defaultValue = null) { return $this->getTranslatedFormByRegExp('months', $keySuffix, $context, $this->month - 1, $defaultValue ?: $this->englishMonth); } @@ -239,21 +244,29 @@ public function getTranslatedMonthName(?string $context = null, string $keySuffi * Returns the formatted date string on success or FALSE on failure. * * @see https://php.net/manual/en/datetime.format.php + * + * @param string $format + * + * @return string */ - public function format(string $format): string + public function format($format): string { - return str_replace([ - $this->englishDayOfWeek, - $this->englishMonth, - - $this->shortEnglishDayOfWeek, - $this->shortEnglishMonth - ], [ - $this->dayName, - $this->monthName, - - $this->shortDayName, - $this->monthName, - ], parent::format($format)); + return str_replace( + [ + $this->englishDayOfWeek, + $this->englishMonth, + + $this->shortEnglishDayOfWeek, + $this->shortEnglishMonth + ], + [ + $this->dayName, + $this->monthName, + + $this->shortDayName, + $this->monthName, + ], + parent::format($format) + ); } } diff --git a/tests/HijriTest.php b/tests/HijriTest.php index 1cfcc1c..904b23c 100644 --- a/tests/HijriTest.php +++ b/tests/HijriTest.php @@ -24,11 +24,17 @@ protected function setUp(): void public function testHijri() { - $this->assertEquals('Monday, Sha\'aban 8, 1413 7:00 PM', $this->dt->toHijri()->isoFormat('LLLL')); + $this->assertEquals( + 'Monday, Sha\'aban 8, 1413 7:00 PM', + $this->dt->toHijri()->isoFormat('LLLL') + ); } public function testLocalizaedHijri() { - $this->assertEquals('الاثنين 8 شَعبان 1413 19:00', $this->dt->toHijri()->locale('ar')->isoFormat('LLLL')); + $this->assertEquals( + 'الاثنين 8 شَعبان 1413 19:00', + $this->dt->toHijri()->locale('ar')->isoFormat('LLLL') + ); } }