From ff6ba4c29a743f624c61005f153ee52c85ffa805 Mon Sep 17 00:00:00 2001 From: Nabeel S Date: Thu, 8 Aug 2019 12:50:32 -0400 Subject: [PATCH] Remove ext-cal from requirements list (#349) * Remove ext-cal from requirements list * Fix the travis phpunit config --- .travis/phpunit.travis.xml | 2 +- app/Contracts/Metar.php | 7 ++++--- app/Support/Dates.php | 18 +++++++++++++++++- composer.json | 1 - modules/Installer/Config/config.php | 1 - 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.travis/phpunit.travis.xml b/.travis/phpunit.travis.xml index a7c27627..30741227 100644 --- a/.travis/phpunit.travis.xml +++ b/.travis/phpunit.travis.xml @@ -22,7 +22,7 @@ - + diff --git a/app/Contracts/Metar.php b/app/Contracts/Metar.php index a06c2f7d..d5a205cb 100644 --- a/app/Contracts/Metar.php +++ b/app/Contracts/Metar.php @@ -2,8 +2,9 @@ namespace App\Contracts; -use Cache; -use Log; +use GuzzleHttp\Exception\GuzzleException; +use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Log; /** * Base class for implementing retrieving METARs @@ -43,7 +44,7 @@ abstract class Metar $raw_metar = Cache::remember($key, $cache['time'], function () use ($icao) { try { return $this->metar($icao); - } catch (\GuzzleHttp\Exception\GuzzleException $e) { + } catch (GuzzleException $e) { Log::error('Error getting METAR: '.$e->getMessage(), $e->getTrace()); return ''; } catch (\Exception $e) { diff --git a/app/Support/Dates.php b/app/Support/Dates.php index c404c0ad..a97cc457 100644 --- a/app/Support/Dates.php +++ b/app/Support/Dates.php @@ -38,11 +38,27 @@ class Dates public static function getMonthBoundary($month): array { [$year, $month] = explode('-', $month); - $days = \cal_days_in_month(CAL_GREGORIAN, $month, $year); + $days = static::getDaysInMonth($month, $year); return [ "$year-$month-01", "$year-$month-$days", ]; } + + /** + * Get the number of days in a month + * https://www.php.net/manual/en/function.cal-days-in-month.php#38666 + * + * @param int $month + * @param int $year + * + * @return int + */ + public static function getDaysInMonth($month, $year): int + { + $month = (int) $month; + $year = (int) $year; + return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31); + } } diff --git a/composer.json b/composer.json index f1d006e0..bb125dcf 100755 --- a/composer.json +++ b/composer.json @@ -8,7 +8,6 @@ "homepage": "http://www.phpvms.net", "require": { "php": ">=7.2", - "ext-calendar": "*", "ext-json": "*", "ext-mbstring": "*", "ext-simplexml": "*", diff --git a/modules/Installer/Config/config.php b/modules/Installer/Config/config.php index ef299cf6..637f4527 100644 --- a/modules/Installer/Config/config.php +++ b/modules/Installer/Config/config.php @@ -15,7 +15,6 @@ return [ ], 'extensions' => [ - 'calendar', 'openssl', 'pdo', 'mbstring',