Skip to content

Commit e6e7761

Browse files
Merge pull request #20 from stevegrunwell/release/v2.0.0
Version 2.0.0
2 parents acf6ad0 + 5d3ebc7 commit e6e7761

File tree

14 files changed

+353
-193
lines changed

14 files changed

+353
-193
lines changed

.github/workflows/coding-standards.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [pull_request]
44

55
jobs:
66
phpcs:
7-
name: PHP Coding Standards Fixer
7+
name: PHP_CodeSniffer
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Checkout
@@ -13,11 +13,11 @@ jobs:
1313
- name: Setup PHP
1414
uses: shivammathur/setup-php@v2
1515
with:
16-
php-version: '8.2'
16+
php-version: '8.3'
1717
coverage: none
1818

1919
- name: Install Composer dependencies
20-
uses: ramsey/composer-install@v2
20+
uses: ramsey/composer-install@v3
2121

2222
- name: Check coding standards
23-
run: vendor/bin/php-cs-fixer fix --dry-run --verbose
23+
run: make standards

.github/workflows/unit-tests.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,20 @@ on: [pull_request]
44

55
jobs:
66
phpunit:
7-
name: PHP ${{ matrix.php-version }}
7+
name: PHPUnit
88
runs-on: ubuntu-latest
9-
strategy:
10-
matrix:
11-
php-version: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
129
steps:
1310
- name: Checkout
1411
uses: actions/checkout@v4
1512

1613
- name: Setup PHP
1714
uses: shivammathur/setup-php@v2
1815
with:
19-
php-version: ${{ matrix.php-version }}
16+
php-version: '8.3'
2017
coverage: none
2118

22-
- name: Remove PHP-CS-Fixer as a dev dependency
23-
run: composer remove --dev --no-install friendsofphp/php-cs-fixer
24-
2519
- name: Install Composer dependencies
26-
uses: ramsey/composer-install@v2
20+
uses: ramsey/composer-install@v3
2721

2822
- name: Run test suite
29-
run: vendor/bin/phpunit --testdox
23+
run: make unit-tests

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
.php-cs-fixer.cache
2-
.phpunit.result.cache
1+
.DS_Store
2+
.phpunit.cache
33
.vscode
44
composer.lock
5+
phpcs.xml
6+
phpunit.xml
57
vendor

.php-cs-fixer.dist.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,54 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Version 2.0.0] — 2024-08-20
9+
10+
**⚠️ Please note:** this is a **major** release, as it contains a breaking change to how the constants are defined. An extra file has been included to help bridge the gap between versions if you wish to run version 2.x of this library without updating all references across your app(s).
11+
12+
* Introduce a Makefile for running dev commands ([#17])
13+
* Move the constants from the global namespace into the `TimeConstants` namespace ([#18])
14+
* Switch from PHP-CS-Fixer to PHP_CodeSniffer with the PHPCompatibility ruleset ([#19])
15+
* With this change, we can run **one** version of PHPUnit in CI, using PHP_CodeSniffer to detect any backwards compatibility breaks with this (admittedly simply) library
16+
* With only one version of PHPUnit necessary, tests have been upgraded for PHPUnit 11.x
17+
18+
### Breaking changes
19+
20+
This release moves the constants defined by this package from the global namespace into the `TimeConstants` namespace.
21+
22+
Your implementations of these constants can be updated in either of the following ways:
23+
24+
1. Explicitly import the constant(s) being used:
25+
```php
26+
use const TimeConstants\HOUR_IN_SECONDS;
27+
```
28+
2. Update references to use the constants new, fully-qualified names:
29+
```diff
30+
- cache($key, $value, HOUR_IN_SECONDS);
31+
+ cache($key, $value, \TimeConstants\HOUR_IN_SECONDS);
32+
```
33+
34+
#### Temporary aliases to help with migration
35+
36+
Alternatively, you may include the new `GlobalAliases.php` file as a short-term fix. This file will take the newly-namespaced constants and **also** define them in the global namespace.
37+
38+
Either of the following approaches will ensure the aliased versions are loaded:
39+
40+
1. (**Preferred**) Add the file to your `composer.json` file in the `autoload.files` array:
41+
```json
42+
"autoload": {
43+
"files": [
44+
"vendor/stevegrunwell/time-constants/src/GlobalAliases.php"
45+
]
46+
}
47+
```
48+
2. Explicitly requiring the file:
49+
```diff
50+
require_once __DIR__ . '/vendor/autoload.php';
51+
+ require_once __DIR__ . '/vendor/stevegrunwell/time-constants/src/GlobalAliases.php';
52+
```
53+
54+
Please note that this `GlobalAliases.php` file will be removed in the next **major** release (e.g. `v3.x`) of this library.
55+
856
## [Version 1.2.0] — 2023-12-18
957

1058
* Add the following multipliers to help with sub-second timings ([#13]):
@@ -51,6 +99,7 @@ Initial public release of the library, with the following constants:
5199

52100

53101
[Unreleased]: https://github.com/stevegrunwell/time-constants/compare/main...develop
102+
[Version 2.0.0]: https://github.com/stevegrunwell/time-constants/releases/tag/v2.0.0
54103
[Version 1.2.0]: https://github.com/stevegrunwell/time-constants/releases/tag/v1.2.0
55104
[Version 1.1.2]: https://github.com/stevegrunwell/time-constants/releases/tag/v1.1.2
56105
[Version 1.1.1]: https://github.com/stevegrunwell/time-constants/releases/tag/v1.1.1
@@ -64,3 +113,6 @@ Initial public release of the library, with the following constants:
64113
[#13]: https://github.com/stevegrunwell/time-constants/pull/13
65114
[#14]: https://github.com/stevegrunwell/time-constants/pull/14
66115
[#15]: https://github.com/stevegrunwell/time-constants/pull/15
116+
[#17]: https://github.com/stevegrunwell/time-constants/pull/17
117+
[#18]: https://github.com/stevegrunwell/time-constants/pull/18
118+
[#19]: https://github.com/stevegrunwell/time-constants/pull/19

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.PHONY: *
2+
3+
build:
4+
composer install
5+
6+
# Roll-up all of the test commands
7+
test: unit-tests standards
8+
9+
# Check coding standards with PHP_CodeSniffer
10+
standards:
11+
vendor/bin/phpcs
12+
13+
# Execute the PHPUnit test suite
14+
unit-tests:
15+
vendor/bin/phpunit --testdox --colors=always

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Time Constants
22

3-
[![CI Pipeline](https://github.com/stevegrunwell/time-constants/actions/workflows/ci-cd.yml/badge.svg?branch=develop)](https://github.com/stevegrunwell/time-constants/actions/workflows/ci-cd.yml)
3+
[![Unit Tests](https://github.com/stevegrunwell/time-constants/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/stevegrunwell/time-constants/actions/workflows/unit-tests.yml)
44
[![Packagist](https://img.shields.io/packagist/v/stevegrunwell/time-constants.svg)](https://packagist.org/packages/stevegrunwell/time-constants)
55

66

@@ -21,13 +21,13 @@ cache($cacheKey, $value, 24 * 60 * 60);
2121
Instead of spending the time figuring out what `24 * 60 * 60` means (or the fact that `86400` is meant to be one day in seconds), **Time Constants** allows you to represent the time using an easy-to-understand PHP constant:
2222

2323
```php
24-
cache($cacheKey, $value, DAY_IN_SECONDS);
24+
cache($cacheKey, $value, \TimeConstants\DAY_IN_SECONDS);
2525
```
2626

2727
If the requirements changed and we needed to cache the value for multiple days, we can rewrite it as:
2828

2929
```php
30-
cache($cacheKey, $value, 5 * DAY_IN_SECONDS);
30+
cache($cacheKey, $value, 5 * \TimeConstants\DAY_IN_SECONDS);
3131
```
3232

3333
These constants may seem familiar to WordPress developers, as they're absolutely [inspired by WordPress' use of time constants](https://codex.wordpress.org/Easier_Expression_of_Time_Constants). This package goes a bit further, however, adding `*_IN_MINUTES` constants, for easier use with libraries like [Laravel's `Cache` facade](https://laravel.com/docs/master/cache#cache-usage).
@@ -46,6 +46,8 @@ The package has been configured to automatically expose the `constants.php` file
4646

4747
This is a list of all constants defined by this package, along with their values. Each constant is wrapped in a `if (! defined(...))` conditional, ensuring these constants can easily be redefined if necessary and won't conflict with existing constants.
4848

49+
As of version 2.0.0 of this library, all of these constants are defined in the `TimeConstants` namespace. If you are upgrading from version 1.x, [please see the 2.0.0 release notes for notes about migration](https://github.com/stevegrunwell/time-constants/releases/tag/v2.0.0).
50+
4951
> Please note that these constants are defined for convenience, and not necessarily for accuracy; all months are treated as 30 days, and years as 365 days. If you need support for leap years or more advanced measures of time, you might consider [PHP's `DateTime` class](http://php.net/manual/en/book.datetime.php) or [Nesbot's Carbon package](https://carbon.nesbot.com/docs/).
5052
5153
### Time based in seconds

composer.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
"php": "^7.0 | ^8.0"
1919
},
2020
"require-dev": {
21-
"friendsofphp/php-cs-fixer": "^3.5",
22-
"phpunit/phpunit": "^6.5 | ^8.5 | ^9.5 | ^10.0"
21+
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
22+
"phpcompatibility/php-compatibility": "^9.3",
23+
"phpunit/phpunit": "^11.3",
24+
"squizlabs/php_codesniffer": "^3.10"
2325
},
2426
"autoload": {
25-
"files": ["constants.php"]
27+
"files": ["src/Constants.php"]
2628
},
2729
"autoload-dev": {
2830
"psr-4": {
@@ -32,11 +34,19 @@
3234
"config": {
3335
"preferred-install": "dist",
3436
"sort-packages": true,
35-
"optimize-autoloader": true
37+
"optimize-autoloader": true,
38+
"platform": {
39+
"php": "8.3"
40+
},
41+
"allow-plugins": {
42+
"dealerdirect/phpcodesniffer-composer-installer": true
43+
}
3644
},
3745
"archive": {
3846
"exclude": [
3947
".*",
48+
"Makefile",
49+
"phpcs.xml.dist",
4050
"phpunit.xml.dist",
4151
"tests"
4252
]

constants.php

Lines changed: 0 additions & 113 deletions
This file was deleted.

phpcs.xml.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="TimeConstants">
3+
<description>Rules for the stevegrunwell/time-constants library</description>
4+
<arg name="colors"/>
5+
<arg value="sp"/>
6+
<arg name="extensions" value="php"/>
7+
8+
<file>src</file>
9+
<file>tests</file>
10+
11+
<rule ref="PSR12"/>
12+
13+
<!-- Test (non-dev) code for compatibility issues with older versions of PHP.-->
14+
<rule ref="PHPCompatibility">
15+
<exclude-pattern>tests</exclude-pattern>
16+
</rule>
17+
<config name="testVersion" value="7.0-"/>
18+
19+
<!-- The compatibility layer is special, we don't care that it defines + executes code. -->
20+
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
21+
<exclude-pattern>src/GlobalAliases.php</exclude-pattern>
22+
</rule>
23+
</ruleset>

0 commit comments

Comments
 (0)