Skip to content

Commit

Permalink
Merge pull request #39 from sanmai/php7.0
Browse files Browse the repository at this point in the history
Support installing on PHP 7.0 with some minor sacrifice
  • Loading branch information
hughgrigg authored Nov 7, 2018
2 parents 45ee10b + 4beaec1 commit befe187
Show file tree
Hide file tree
Showing 53 changed files with 120 additions and 123 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: php

php:
- 7.0
- 7.1
- 7.2
- 7.3
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
"version": "1.0.1",
"type": "library",
"require": {
"php": "^7.1",
"php": "^7.0",
"nesbot/carbon": "^1.25"
},
"require-dev": {
"phpunit/phpunit": "^7.0",
"phpunit/phpunit": "^6.5 || ^7.4",
"phpmd/phpmd": "@stable",
"squizlabs/php_codesniffer": "@stable",
"johnkary/phpunit-speedtrap": "^3.0",
"johnkary/phpunit-speedtrap": "^2.0 || ^3.0",
"php-coveralls/php-coveralls": "^2.0",
"guzzlehttp/guzzle": "^6.3",
"psr/http-message": "^1.0",
"phpunit/phpunit-mock-objects": "^6.1",
"phpunit/phpunit-mock-objects": "^5.0 || ^6.1",
"guzzlehttp/psr7": "^1.4"
},
"suggest": {
Expand Down
20 changes: 10 additions & 10 deletions src/BusinessTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public function subBusinessHours(float $businessHoursToSub): self
* @return int
*/
public function diffInBusinessDays(
?DateTimeInterface $time = null,
DateTimeInterface $time = null,
bool $absolute = true
): int {
return (int) $this->diffInPartialBusinessDays($time, $absolute);
Expand All @@ -282,7 +282,7 @@ public function diffInBusinessDays(
* @return int
*/
public function diffInBusinessHours(
?DateTimeInterface $time = null,
DateTimeInterface $time = null,
bool $absolute = true
): int {
return (int) $this->diffInPartialBusinessHours($time, $absolute);
Expand All @@ -302,7 +302,7 @@ public function diffInBusinessHours(
* @return float
*/
public function diffInPartialBusinessDays(
?DateTimeInterface $time = null,
DateTimeInterface $time = null,
bool $absolute = true
): float {
return $this->diffInBusinessTime($time, $absolute)
Expand All @@ -321,7 +321,7 @@ public function diffInPartialBusinessDays(
* @return float
*/
public function diffInPartialBusinessHours(
?DateTimeInterface $time = null,
DateTimeInterface $time = null,
bool $absolute = true
): float {
return $this->diffInBusinessTime($time, $absolute)
Expand All @@ -341,7 +341,7 @@ public function diffInPartialBusinessHours(
* @return Interval
*/
public function diffBusiness(
?DateTimeInterface $time = null,
DateTimeInterface $time = null,
bool $absolute = true
): Interval {
return Interval::seconds(
Expand Down Expand Up @@ -404,7 +404,7 @@ public function endOfBusinessDay(): self
*
* @return BusinessTime
*/
public function floor(?DateInterval $precision = null): self
public function floor(DateInterval $precision = null): self
{
$seconds = Interval::instance($precision ?: $this->precision())
->inSeconds();
Expand All @@ -423,7 +423,7 @@ public function floor(?DateInterval $precision = null): self
*
* @return BusinessTime
*/
public function round(?DateInterval $precision = null): self
public function round(DateInterval $precision = null): self
{
$seconds = Interval::instance($precision ?: $this->precision())
->inSeconds();
Expand All @@ -445,7 +445,7 @@ public function round(?DateInterval $precision = null): self
*
* @return BusinessTime
*/
public function ceil(?DateInterval $precision = null): self
public function ceil(DateInterval $precision = null): self
{
$seconds = Interval::instance($precision ?: $this->precision())
->inSeconds();
Expand Down Expand Up @@ -509,7 +509,7 @@ public function setLengthOfBusinessDay(DateInterval $length): self
* @return BusinessTime
*/
public function determineLengthOfBusinessDay(
?DateTime $typicalDay = null
DateTime $typicalDay = null
): self {
if ($typicalDay === null) {
// Default to the length of a reasonable guess at a typical day.
Expand Down Expand Up @@ -638,7 +638,7 @@ public static function fromDti(DateTimeInterface $dti): self
* @return int
*/
private function diffInBusinessTime(
?DateTimeInterface $time = null,
DateTimeInterface $time = null,
bool $absolute = true
): int {
// We're taking a basic approach with some variables and a loop here as
Expand Down
2 changes: 1 addition & 1 deletion src/BusinessTimeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BusinessTimeFactory
* @param BusinessTimeConstraint ...$constraints
*/
public function __construct(
?Interval $precision = null,
Interval $precision = null,
BusinessTimeConstraint ...$constraints
) {
// Default to hour precision.
Expand Down
2 changes: 1 addition & 1 deletion src/Constraint/Dates.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
class Dates extends FormatConstraint
{
private const FORMAT = 'Y-m-d';
const FORMAT = 'Y-m-d';

/**
* @param string ...$dates e.g. '2018-05-23', '2019-04-01'
Expand Down
2 changes: 1 addition & 1 deletion src/Constraint/DaysOfWeek.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class DaysOfWeek extends FormatConstraint
{
public const NAME_INDEX = [
const NAME_INDEX = [
'Monday' => 1,
'Tuesday' => 2,
'Wednesday' => 3,
Expand Down
2 changes: 1 addition & 1 deletion src/Constraint/DaysOfYear.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
class DaysOfYear extends FormatConstraint
{
private const FORMAT = 'F j';
const FORMAT = 'F j';

/**
* @param string ...$daysOfYear e.g. "December 25th", "1st April"
Expand Down
2 changes: 1 addition & 1 deletion src/Constraint/MonthsOfYear.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class MonthsOfYear extends FormatConstraint
{
public const NAME_INDEX = [
const NAME_INDEX = [
'January' => 1,
'Jan' => 1,
'February' => 2,
Expand Down
4 changes: 2 additions & 2 deletions src/Constraint/Narration/BusinessTimeNarrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

interface BusinessTimeNarrator
{
public const DEFAULT_BUSINESS = 'business hours';
public const DEFAULT_NON_BUSINESS = 'outside business hours';
const DEFAULT_BUSINESS = 'business hours';
const DEFAULT_NON_BUSINESS = 'outside business hours';

/**
* Get a business-relevant description for the given time.
Expand Down
2 changes: 1 addition & 1 deletion src/Constraint/RangeConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(int $min, int $max)

// Allow backwards order.
if ($min > $max) {
[$min, $max] = [$max, $min];
list($min, $max) = [$max, $min];
}

$this->min = $min;
Expand Down
4 changes: 1 addition & 3 deletions src/Deadline/RecurringDeadline.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,14 @@ public function hasPassedBetween(
public function firstTimePassedBetween(
BusinessTime $start,
BusinessTime $end
): ?BusinessTime {
) {
$time = $start->copy();
while ($time->lte($end)) {
if ($this->isDeadline($time)) {
return $time->floor();
}
$time = $time->add($time->precision());
}

return null;
}

/**
Expand Down
6 changes: 2 additions & 4 deletions src/Remote/WebCalFi/WebCalFiConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class WebCalFiConstraint implements BusinessTimeConstraint, BusinessTimeNarrator
{
private const FORMAT = 'Y-m-d';
const FORMAT = 'Y-m-d';

/** @var WebCalFiDate[] */
private $dates = [];
Expand Down Expand Up @@ -61,12 +61,10 @@ public function narrate(DateTimeInterface $time): string
*
* @return WebCalFiDate|null
*/
private function dateFor(DateTimeInterface $time): ?WebCalFiDate
private function dateFor(DateTimeInterface $time)
{
if (isset($this->dates[$time->format(self::FORMAT)])) {
return $this->dates[$time->format(self::FORMAT)];
}

return null;
}
}
4 changes: 2 additions & 2 deletions tests/Functional/Remote/WebCalFi/WebCalFiFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function setUp()
*
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function testUkHolidaysContainsChristmas(): void
public function testUkHolidaysContainsChristmas()
{
// Given we have a WebCalFiFactory;
$factory = new WebCalFiFactory(new Client());
Expand Down Expand Up @@ -66,7 +66,7 @@ public function testUkHolidaysContainsChristmas(): void
*
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function testUsHolidaysHolidaysContainsIndependenceDay(): void
public function testUsHolidaysHolidaysContainsIndependenceDay()
{
// Given we have a WebCalFiFactory;
$factory = new WebCalFiFactory(new Client());
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/BusinessTime/AddBusinessDaysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AddBusinessDaysTest extends TestCase
public function testAddBusinessDayDefault(
string $time,
string $expectedNewTime
): void {
) {
// Given we have a business time for a specific time;
$businessTime = new BusinessTime($time);

Expand Down Expand Up @@ -74,7 +74,7 @@ public function testAddBusinessDaysDefault(
string $time,
float $businessDaysToAdd,
string $expectedNewTime
): void {
) {
// Given we have a business time for a specific time;
$businessTime = new BusinessTime($time);

Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/BusinessTime/AddBusinessHoursTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AddBusinessHoursTest extends TestCase
public function testAddBusinessHourDefault(
string $time,
string $expectedNewTime
): void {
) {
// Given we have a business time for a specific time;
$businessTime = new BusinessTime($time);

Expand Down Expand Up @@ -88,7 +88,7 @@ public function testAddBusinessHoursDefault(
string $time,
float $businessHoursToAdd,
string $expectedNewTime
): void {
) {
// Given we have a business time for a specific time;
$businessTime = new BusinessTime($time);

Expand Down Expand Up @@ -162,7 +162,7 @@ public function testAddBusinessHoursConstraint(
BusinessTimeConstraint $constraint,
float $businessHoursToAdd,
string $expectedNewTime
): void {
) {
// Given we have a business time for a specific time;
$businessTime = new BusinessTime($time);

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/BusinessTime/BusinessNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BusinessNameTest extends TestCase
public function testBusinessNameDefault(
string $time,
string $expectedBusinessName
): void {
) {
// Given we have a business time for a particular time;
$businessTime = new BusinessTime($time);

Expand Down Expand Up @@ -58,7 +58,7 @@ public function businessNameDefaultProvider(): array
* A fall-back business name should be used if there are no business time
* constraints.
*/
public function testFallBackBusinessName(): void
public function testFallBackBusinessName()
{
// Given we have a business time for a particular time;
$businessTime = new BusinessTime('2018-05-23 13:00');
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/BusinessTime/DiffInBusinessDaysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testDiffInBusinessDaysDefault(
string $day,
string $otherDay,
int $expectedDiff
): void {
) {
// Given we have a business time for a particular day;
$businessTime = new BusinessTime($day);

Expand Down Expand Up @@ -100,7 +100,7 @@ public function testDiffInPartialBusinessDaysDefault(
string $time,
string $otherTime,
float $expectedDiff
): void {
) {
// Given we have a business time for a particular time;
$businessTime = new BusinessTime($time);

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/BusinessTime/DiffInBusinessHoursTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testDiffInBusinessHoursDefault(
string $time,
string $otherTime,
int $expectedDiff
): void {
) {
// Given we have a business time for a particular time;
$businessTime = new BusinessTime($time);

Expand Down Expand Up @@ -119,7 +119,7 @@ public function testDiffInPartialBusinessHoursDefault(
string $time,
string $otherTime,
float $expectedDiff
): void {
) {
// Given we have a business time for a particular time;
$businessTime = new BusinessTime($time);

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/BusinessTime/IsBusinessTimeDefaultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class IsBusinessTimeDefaultTest extends TestCase
public function testIsBusinessTimeDefault(
string $time,
bool $expectedToBeBusinessTime
): void {
) {
// Given we have a time with default behaviour;
$businessTime = new BusinessTime($time);

Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/BusinessTime/LengthOfBusinessDayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LengthOfBusinessDayTest extends TestCase
/**
* Test that the length of a business day is 8 hours by default.
*/
public function testLengthOfBusinessDayDefault(): void
public function testLengthOfBusinessDayDefault()
{
// Given we have a business time with the default behaviour;
$time = new BusinessTime();
Expand All @@ -44,7 +44,7 @@ public function testLengthOfBusinessDayDefault(): void
public function testSetLengthOfBusinessDay(
Interval $length,
string $expectedDescription
): void {
) {
// Given we have a business time;
$time = new BusinessTime();

Expand Down Expand Up @@ -87,7 +87,7 @@ public function lengthOfBusinessDayProvider(): array
public function testDetermineLengthOfBusinessDay(
BusinessTimeConstraint $constraint,
string $expectedDescription
): void {
) {
// Given we have a business time with certain constraints;
$time = new BusinessTime();
$time->setBusinessTimeConstraints($constraint);
Expand Down Expand Up @@ -144,7 +144,7 @@ public function determineLengthOfBusinessDayProvider(): array
/**
* Should not be able to set a business day to zero length.
*/
public function testCantSetZeroLengthBusinessDay(): void
public function testCantSetZeroLengthBusinessDay()
{
// We should get an error;
$this->expectException(InvalidArgumentException::class);
Expand All @@ -157,7 +157,7 @@ public function testCantSetZeroLengthBusinessDay(): void
/**
* Should not be able to set the length of a business day over one day.
*/
public function testCantSetBusinessDayLengthOverOneDay(): void
public function testCantSetBusinessDayLengthOverOneDay()
{
// We should get an error;
$this->expectException(InvalidArgumentException::class);
Expand Down
Loading

0 comments on commit befe187

Please sign in to comment.