Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to PHP 8, tests passing #64

Merged
merged 5 commits into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build/
coverage/
.idea/
composer.lock
*.cache
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: php
php:
- 8.0
- 8.1
- 8.2

script:
- make coverage
Expand Down
41 changes: 4 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

[![Build Status](https://travis-ci.org/hughgrigg/php-business-time.svg?branch=master)](https://travis-ci.org/hughgrigg/php-business-time)
[![Coverage Status](https://coveralls.io/repos/github/hughgrigg/php-business-time/badge.svg)](https://coveralls.io/github/hughgrigg/php-business-time)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/ef5b774bce624ab2b1f3632e9307a909)](https://app.codacy.com/app/hugh_2/php-business-time?utm_source=github.com&utm_medium=referral&utm_content=hughgrigg/php-business-time&utm_campaign=badger)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/hughgrigg/php-business-time/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/hughgrigg/php-business-time/?branch=master)
[![StyleCI](https://styleci.io/repos/126614310/shield?branch=master)](https://styleci.io/repos/126614310)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Expand All @@ -14,9 +12,8 @@ This library provides an extension for the `Carbon` class in the
[Carbon](http://carbon.nesbot.com/docs/) date time library.

While Carbon already has methods like `diffInWeekendDays()`, this extension lets
you handle business time more precisely and flexibly. It can consider public
holidays from WebCal.fi, as well as your own customised times which can be
specified directly or with constraint-matching.
you handle business time more precisely and flexibly. It can use your own
customised times which can be specified directly or with constraint-matching.

[Official music video for this library](https://www.youtube.com/watch?v=WGOohBytKTU)

Expand All @@ -41,7 +38,6 @@ specified directly or with constraint-matching.
- [Custom business time constraints](#custom-business-time-constraints)
- [Business time constraints example](#business-time-constraints-example)
* [Incorporating business time data from a remote source](#incorporating-business-time-data-from-a-remote-source)
+ [WebCal.fi](#webcalfi)
+ [Custom remote sources](#custom-remote-sources)
* [Recurring business deadlines](#recurring-business-deadlines)
* [Business time factory](#business-time-factory)
Expand Down Expand Up @@ -266,7 +262,7 @@ class like this:

```php
$businessTime = new BusinessTime\BusinessTime();
$businessTime->setBusinessTimeConstraints(
$businessTime->setConstraints(
new BusinessTime\Constraint\WeekDays(),
new BusinessTime\Constraint\BetweenHoursOfDay(9, 17),
);
Expand Down Expand Up @@ -373,7 +369,7 @@ Here's a somewhat complicated example of using business time constraints:

```php
$businessTime = new BusinessTime\BusinessTime();
$businessTime->setBusinessTimeConstraints(
$businessTime->setConstraints(
(new BusinessTime\Constraint\BetweenHoursOfDay(10, 18))->except(
new BusinessTime\Constraint\BetweenTimesOfDay('13:00', '14:00')
), // 9-6 every day, with an hour for lunch.
Expand All @@ -393,35 +389,6 @@ $businessTime->setBusinessTimeConstraints(
Whilst you could try to set up constraints covering all the public holidays in
your country, it's probably easier to just retrieve them from a remote source.

BusinessTime supports this for WebCal.fi out of the box.

### WebCal.fi

WebCal.fi is easy to use as its data is provided publicly without any
authentication. You do need to include the
[Guzzle](https://github.com/guzzle/guzzle) library in your project to use this,
though.

```php
$factory = new BusinessTime\Remote\WebCalFiFactory(
new GuzzleHttp\Client(),
'https://www.webcal.fi/cal.php?id=83&format=json' // for example
);
$dates = $factory->getDates();
// = array of date objects from the specified calendar.
$webCalFiConstraint = $factory->makeConstraint();
// = a constraint containing the retrieved dates and their descriptions.
```

The constraint will be set up with names and dates from the WebCal.fi calendar
you specify.

You can find WebCal.fi calendars to suit your needs at e.g.
https://www.webcal.fi/en-GB/other_file_formats.php

Note that you can also use the `except()` method on the WebCalFi constraint to
add customised exceptions to the dates it provides.

### Custom remote sources

You can add any other source you like by implementing the `Constraint` interface
Expand Down
3 changes: 0 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
<testsuite name="unit">
<directory>./tests/Unit/</directory>
</testsuite>
<testsuite name="functional">
<directory>./tests/Functional/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
Expand Down
12 changes: 6 additions & 6 deletions src/BusinessTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class BusinessTime extends Carbon
{
/** @var All|BusinessTimeConstraint[] */
private $businessTimeConstraints;
private $constraints;

/** @var Interval */
private $lengthOfBusinessDay;
Expand Down Expand Up @@ -602,10 +602,10 @@ public function determineLengthOfBusinessDay(
*
* @return BusinessTime
*/
public function setBusinessTimeConstraints(
public function setConstraints(
BusinessTimeConstraint ...$constraints
): self {
$this->businessTimeConstraints = new All(...$constraints);
$this->constraints = new All(...$constraints);

return $this;
}
Expand All @@ -617,15 +617,15 @@ public function setBusinessTimeConstraints(
*/
public function businessTimeConstraints(): All
{
if ($this->businessTimeConstraints === null) {
if ($this->constraints === null) {
// Default to week days 09:00 - 17:00.
$this->businessTimeConstraints = new All(
$this->constraints = new All(
new WeekDays(),
new BetweenHoursOfDay(9, 17)
);
}

return $this->businessTimeConstraints;
return $this->constraints;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/BusinessTimeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(
public function make(string $time): BusinessTime
{
$businessTime = new BusinessTime($time);
$businessTime->setBusinessTimeConstraints(...$this->constraints);
$businessTime->setConstraints(...$this->constraints);
$businessTime->setPrecision($this->precision);
$businessTime->setIterationLimit($this->iterationLimit);

Expand Down
70 changes: 0 additions & 70 deletions src/Remote/WebCalFi/WebCalFiConstraint.php

This file was deleted.

45 changes: 0 additions & 45 deletions src/Remote/WebCalFi/WebCalFiDate.php

This file was deleted.

Loading