Skip to content

Commit

Permalink
Merge pull request #29 from andegna/develop
Browse files Browse the repository at this point in the history
More polishing and bump up too php 7.0
  • Loading branch information
SamAsEnd authored Oct 8, 2017
2 parents 7056ec1 + 30855a4 commit e72a7d9
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2

install: travis_retry composer install --no-interaction --prefer-source

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"php": "^5.6 || ^7.0",
"php": ">=7.0.0",
"ext-calendar": "*",
"geezify/geezify-php": "^1.2"
},
Expand All @@ -30,7 +30,7 @@
},
"extra": {
"branch-alias": {
"develope": "2.1-dev"
"develop": "2.1-dev"
}
}
}
8 changes: 4 additions & 4 deletions src/Converter/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class Converter
*
* @return int
*/
public function getDay()
public function getDay(): int
{
return $this->day;
}
Expand All @@ -41,7 +41,7 @@ public function getDay()
*
* @return int
*/
public function getMonth()
public function getMonth(): int
{
return $this->month;
}
Expand All @@ -51,7 +51,7 @@ public function getMonth()
*
* @return int
*/
public function getYear()
public function getYear(): int
{
return $this->year;
}
Expand All @@ -61,7 +61,7 @@ public function getYear()
*
* @return int
*/
public function getJdn()
public function getJdn(): int
{
return $this->jdn;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Converter/FromJdnConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FromJdnConverter extends Converter
*
* @throws \Andegna\Exception\InvalidDateException
*/
public function __construct($jdn)
public function __construct(int $jdn)
{
$this->set($jdn);
}
Expand All @@ -30,7 +30,7 @@ public function __construct($jdn)
*
* @return $this
*/
public function set($jdn)
public function set(int $jdn)
{
if (!$this->isValidInteger($jdn)) {
throw new InvalidDateException();
Expand All @@ -48,7 +48,7 @@ public function set($jdn)
*
* @return array
*/
protected static function process($jdn)
protected static function process(int $jdn): array
{
$r = (($jdn - 1723856) % 1461);
$n = ($r % 365) + 365 * (int) ($r / 1460);
Expand All @@ -64,9 +64,9 @@ protected static function process($jdn)
/**
* @param $date array
*
* @return $this
* @return $this|Converter
*/
protected function setDate(array $date)
protected function setDate(array $date): Converter
{
$this->day = $date['day'];
$this->month = $date['month'];
Expand Down
4 changes: 2 additions & 2 deletions src/Converter/ToJdnConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ToJdnConverter extends Converter
*
* @throws \Andegna\Exception\InvalidDateException
*/
public function __construct($day, $month, $year)
public function __construct(int $day, int $month, int $year)
{
$this->set($day, $month, $year);
}
Expand All @@ -35,7 +35,7 @@ public function __construct($day, $month, $year)
*
* @return $this
*/
public function set($day, $month, $year)
public function set(int $day, int $month, int $year)
{
$validator = new DateValidator($day, $month, $year);

Expand Down
2 changes: 1 addition & 1 deletion src/Exception/InvalidDateException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class InvalidDateException extends Exception
*
* @param $message string
*/
public function __construct($message = 'Invalid date was given')
public function __construct(string $message = 'Invalid date was given')
{
parent::__construct($message);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Holiday/Easter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(DateTimeZone $dateTimeZone = null)
*
* @return \Andegna\DateTime
*/
public function get($year)
public function get(int $year)
{
// convert the Ethiopian year to a Julian year
// ሚያዝያ 1 is just a random day after the Gregorian new year
Expand Down
46 changes: 24 additions & 22 deletions src/Operations/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait Formatter
*
* @return string
*/
public function format($format)
public function format(string $format)
{
$result = '';
$length = \mb_strlen($format);
Expand All @@ -47,7 +47,7 @@ public function format($format)
*
* @return string
*/
protected function getValueOfFormatCharacter($name, &$skip = false)
protected function getValueOfFormatCharacter(string $name, bool &$skip = false): string
{
if (($r = $this->shouldWeSkip($name, $skip)) !== false) {
return ''.$r;
Expand All @@ -65,7 +65,7 @@ protected function getValueOfFormatCharacter($name, &$skip = false)
*
* @return string
*/
public function getDayTwoDigit()
public function getDayTwoDigit(): string
{
$day = $this->getValueOfFormatCharacter('j');

Expand All @@ -77,7 +77,7 @@ public function getDayTwoDigit()
*
* return string
*/
public function getTextualDay()
public function getTextualDay(): string
{
return Constants::WEEK_NAME[$this->getDayOfWeek()];
}
Expand All @@ -87,7 +87,7 @@ public function getTextualDay()
*
* return string
*/
public function getTextualDayShort()
public function getTextualDayShort(): string
{
$week = $this->getValueOfFormatCharacter('l');

Expand All @@ -99,7 +99,7 @@ public function getTextualDayShort()
*
* @return string
*/
public function getTextualMonth()
public function getTextualMonth(): string
{
return Constants::MONTHS_NAME[$this->getMonth()];
}
Expand All @@ -109,7 +109,7 @@ public function getTextualMonth()
*
* @return string
*/
public function getTextualMonthShort()
public function getTextualMonthShort(): string
{
$F = $this->getValueOfFormatCharacter('F');

Expand All @@ -121,19 +121,19 @@ public function getTextualMonthShort()
*
* @return string
*/
public function getMonthTwoDigit()
public function getMonthTwoDigit(): string
{
$n = $this->getValueOfFormatCharacter('n');

return (strlen($n) == 1) ? "0$n" : "$n";
return (strlen($n) === 1) ? "0$n" : "$n";
}

/**
* (1 or 0) Whether it's a leap year.
*
* @return string
*/
public function getLeapYearString()
public function getLeapYearString(): string
{
return $this->isLeapYear() ? '1' : '0';
}
Expand All @@ -143,7 +143,7 @@ public function getLeapYearString()
*
* @return string
*/
public function getYearShort()
public function getYearShort(): string
{
$Y = $this->getValueOfFormatCharacter('Y');

Expand All @@ -163,7 +163,7 @@ public function getYearShort()
*
* @return string
*/
public function getTimeOfDay()
public function getTimeOfDay(): string
{
$array = [
'እኩለ፡ሌሊት' => [23, 0],
Expand All @@ -181,7 +181,7 @@ public function getTimeOfDay()
$hour = $this->getHour();

$result = array_filter($array, function ($value) use ($hour) {
return false !== array_search($hour, $value, true);
return in_array($hour, $value, true);
});

return key($result);
Expand All @@ -192,7 +192,7 @@ public function getTimeOfDay()
*
* @return string the ethiopian orthodox day name
*/
public function getOrthodoxDay()
public function getOrthodoxDay(): string
{
return Constants::ORTHODOX_DAY_NAME[$this->getDay()];
}
Expand All @@ -202,7 +202,7 @@ public function getOrthodoxDay()
*
* @return string
*/
public function getTextualEra()
public function getTextualEra(): string
{
return $this->getYear() > 0 ? 'ዓ/ም' : 'ዓ/ዓ';
}
Expand All @@ -212,17 +212,19 @@ public function getTextualEra()
*
* @return string the ethiopian orthodox year name
*/
public function getOrthodoxYear()
public function getOrthodoxYear(): string
{
return Constants::ORTHODOX_YEAR_NAME[$this->getYear() % 4];
}

/**
* Return the year in geez number.
*
* @throws \Geezify\Exception\NotAnIntegerArgumentException
*
* @return string
*/
public function getYearInGeez()
public function getYearInGeez(): string
{
return Geezify::create()->toGeez($this->getYear());
}
Expand All @@ -232,7 +234,7 @@ public function getYearInGeez()
*
* @return string
*/
public function getDayInGeez()
public function getDayInGeez(): string
{
return Geezify::create()->toGeez($this->getDay());
}
Expand All @@ -242,7 +244,7 @@ public function getDayInGeez()
*
* @return bool
*/
protected function isOverrideFormatCharacter($name)
protected function isOverrideFormatCharacter($name): bool
{
return array_key_exists($name, Constants::FORMAT_MAPPER);
}
Expand All @@ -268,7 +270,7 @@ protected function shouldWeSkip($name, &$skip)
*
* @return bool
*/
protected function shouldWeSkip4Real($name, &$skip)
protected function shouldWeSkip4Real($name, &$skip): bool
{
return $this->isSkipCharacter($name) || $skip;
}
Expand All @@ -279,7 +281,7 @@ protected function shouldWeSkip4Real($name, &$skip)
*
* @return string
*/
protected function skipCharacter($name, &$skip)
protected function skipCharacter($name, &$skip): string
{
if ($skip) {
$skip = false;
Expand All @@ -299,7 +301,7 @@ protected function skipCharacter($name, &$skip)
*
* @return bool
*/
protected function isSkipCharacter($name)
protected function isSkipCharacter($name): bool
{
return $name === '\\';
}
Expand Down
13 changes: 4 additions & 9 deletions src/Operations/Initiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Andegna\Converter\Converter;
use Andegna\Converter\FromJdnConverter;
use Andegna\DateTime;
use Andegna\Validator\LeapYearValidator;
use DateTime as GregorianDateTime;

Expand Down Expand Up @@ -37,7 +36,7 @@ protected function updateComputedFields()
*
* @return int
*/
protected function getJdnFromBase(GregorianDateTime $dateTime)
protected function getJdnFromBase(GregorianDateTime $dateTime): int
{
$year = $dateTime->format('Y');
$month = $dateTime->format('m');
Expand Down Expand Up @@ -100,7 +99,7 @@ protected function computeLeapYear()
*/
protected function computeDayOfYear()
{
$this->dayOfYear = ($this->month - 1) * 30 + ($this->day);
$this->dayOfYear = ($this->month - 1) * 30 + $this->day;
}

/**
Expand All @@ -110,11 +109,7 @@ protected function computeDayOfYear()
*/
protected function computeDaysInMonth()
{
if ($this->month === 13) {
$this->daysInMonth = $this->leapYear ? 6 : 5;
}

$this->daysInMonth = 30;
$this->daysInMonth = $this->month === 13 ? ($this->leapYear ? 6 : 5) : 30;
}

/**
Expand All @@ -124,6 +119,6 @@ protected function computeDaysInMonth()
*/
protected function cacheDayOfWeek()
{
$this->dayOfWeek = intval($this->dateTime->format('N'));
$this->dayOfWeek = (int) $this->dateTime->format('N');
}
}
2 changes: 1 addition & 1 deletion src/Validator/ValidIntegerValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait ValidIntegerValidator
*
* @return bool returns true if all the elements in the array are integer
*/
public function isValidInteger(...$integers)
public function isValidInteger(...$integers): bool
{
return array_reduce($integers, function ($carry, $integer) {
return $carry && is_int($integer);
Expand Down
Loading

0 comments on commit e72a7d9

Please sign in to comment.