Skip to content

Commit 68cd668

Browse files
authored
Merge pull request #7 from AngryBytes/feat/php-8.3
Feat/php 8.3
2 parents b1de636 + 46b10aa commit 68cd668

File tree

20 files changed

+73
-60
lines changed

20 files changed

+73
-60
lines changed

.github/workflows/php-checks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
runs-on: ubuntu-latest
66
strategy:
77
matrix:
8-
php-versions: ['7.4', '8.0', '8.1', '8.2']
8+
php-versions: ['8.1', '8.2', '8.3']
99
name: PHP ${{ matrix.php-versions }} tests
1010
steps:
1111
- name: Checkout

.gitignore

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
/vendor/
2-
composer.lock
3-
.phpunit.result.cache
1+
/composer.lock
2+
/vendor
3+
4+
/.php-cs-fixer.cache
5+
/.phpunit.cache

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## 3.0.0
4+
5+
### PHP support
6+
7+
- Dropped support for PHP `8.0` and lower.
8+
- Added support for PHP `8.3`.
9+
10+
### 3rd party updates
11+
12+
- Updated `symfony/finder` to version `6`.
13+
314
## 2.0.1
415

516
### PHP support

composer.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@
4040
},
4141
"minimum-stability": "stable",
4242
"require": {
43-
"php": "7.4.* || 8.0.* || 8.1.* || 8.2.*",
43+
"php": "8.1.* || 8.2.* || 8.3.*",
4444
"ext-json": "*",
45-
"symfony/finder": "^5.0.0"
45+
"symfony/finder": "^6.0.0"
4646
},
4747
"require-dev": {
48-
"phpstan/phpstan": "1.9.12",
49-
"phpunit/phpunit": "9.5.28",
50-
"squizlabs/php_codesniffer": "3.7.1"
48+
"phpstan/phpstan": "1.10.46",
49+
"phpunit/phpunit": "10.4.2",
50+
"squizlabs/php_codesniffer": "3.7.2"
5151
}
5252
}

phpunit.xml.dist

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
<?xml version="1.0"?>
12
<phpunit
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.5/phpunit.xsd"
4-
backupGlobals="false"
5-
backupStaticAttributes="false"
6-
bootstrap="vendor/autoload.php"
7-
colors="true"
8-
>
9-
10-
<testsuites>
11-
<testsuite name="ProjectVersioner Test Suite">
12-
<directory>./tests/</directory>
13-
</testsuite>
14-
</testsuites>
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd"
5+
backupGlobals="false"
6+
bootstrap="vendor/autoload.php"
7+
colors="true"
8+
cacheDirectory=".phpunit.cache"
9+
backupStaticProperties="false"
10+
>
11+
<testsuites>
12+
<testsuite name="ProjectVersioner Test Suite">
13+
<directory>./tests/</directory>
14+
</testsuite>
15+
</testsuites>
1516
</phpunit>

src/Naneau/ProjectVersioner/Reader/Composer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* Composer
88
*
9-
* Finds version from composer lock file
9+
* Finds the version from composer lock file
1010
*/
1111
class Composer implements ReaderInterface
1212
{
@@ -21,7 +21,7 @@ public function canRead(string $directory): bool
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public function read(string $directory)
24+
public function read(string $directory): int|string|null
2525
{
2626
$contents = file_get_contents($directory . '/composer.lock');
2727
if (!$contents) {

src/Naneau/ProjectVersioner/Reader/ComposerJson.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Naneau\ProjectVersioner\Reader;
33

4+
use JsonException;
45
use Naneau\ProjectVersioner\ReaderInterface;
56

67
use stdClass;
@@ -21,14 +22,19 @@ public function canRead(string $directory): bool
2122
/**
2223
* {@inheritdoc}
2324
*/
24-
public function read(string $directory)
25+
public function read(string $directory): int|string|null
2526
{
2627
$json = @file_get_contents($directory . '/composer.json');
2728
if (!$json) {
2829
return null;
2930
}
3031

31-
$json = json_decode($json, false);
32+
try {
33+
$json = json_decode($json, false, 512, JSON_THROW_ON_ERROR);
34+
} catch (JsonException) {
35+
return null;
36+
}
37+
3238
if (!($json instanceof stdClass) || empty($json->version)) {
3339
return null;
3440
}

src/Naneau/ProjectVersioner/Reader/ComposerPackage.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Naneau\ProjectVersioner\Reader;
33

4+
use JsonException;
45
use Naneau\ProjectVersioner\ReaderInterface;
56

67
use stdClass;
@@ -15,10 +16,8 @@ class ComposerPackage implements ReaderInterface
1516
{
1617
/**
1718
* The page name to look for
18-
*
19-
* @var string
2019
*/
21-
private $package;
20+
private string $package;
2221

2322
public function __construct(string $package)
2423
{
@@ -46,7 +45,7 @@ public function canRead(string $directory): bool
4645
/**
4746
* {@inheritdoc}
4847
*/
49-
public function read(string $directory)
48+
public function read(string $directory): int|string|null
5049
{
5150
$package = $this->getPackageFromLockFile($directory);
5251

@@ -88,7 +87,12 @@ private function getPackageFromLockFile(string $directory): ?stdClass
8887
return null;
8988
}
9089

91-
$parsed = json_decode($contents, false);
90+
try {
91+
$parsed = json_decode($contents, false, 512, JSON_THROW_ON_ERROR);
92+
} catch (JsonException) {
93+
return null;
94+
}
95+
9296
if (!isset($parsed->packages)) {
9397
return null;
9498
}

src/Naneau/ProjectVersioner/Reader/File.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function canRead(string $directory): bool
3333
/**
3434
* {@inheritdoc}
3535
*/
36-
public function read(string $directory)
36+
public function read(string $directory): int|string|null
3737
{
3838
$contents = file_get_contents($directory . DIRECTORY_SEPARATOR . $this->getFile());
3939
if (!$contents) {

src/Naneau/ProjectVersioner/Reader/Finder/Contents.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Contents extends Finder
1111
/**
1212
* {@inheritdoc}
1313
*/
14-
public function read(string $directory)
14+
public function read(string $directory): string
1515
{
1616
$hash = '';
1717
foreach ($this->getFinder() as $file) {

src/Naneau/ProjectVersioner/Reader/Finder/Finder.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
/**
99
* Finder
1010
*
11-
* Base class for finder based readers
11+
* Base class for finder-based readers
1212
*/
1313
abstract class Finder implements ReaderInterface
1414
{
1515
/**
1616
* the finder
17-
*
18-
* @var SfFinder
1917
*/
20-
private $finder;
18+
private SfFinder $finder;
2119

2220
public function __construct(?string $name = null, ?SfFinder $finder = null)
2321
{

src/Naneau/ProjectVersioner/Reader/Finder/MTime.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class MTime extends Finder
1111
/**
1212
* {@inheritdoc}
1313
*/
14-
public function read(string $directory)
14+
public function read(string $directory): int|string|null
1515
{
1616
$highest = 0;
1717
foreach ($this->getFinder() as $file) {

src/Naneau/ProjectVersioner/Reader/Git/Commit/Exec.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ class Exec extends GitExec
1414
{
1515
/**
1616
* Use short hash?
17-
*
18-
* @var bool
1917
*/
20-
private $short = true;
18+
private bool $short = true;
2119

2220
public function __construct(bool $short = true)
2321
{

src/Naneau/ProjectVersioner/Reader/Git/Describe/Exec.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Reads the latest "described" version from git, which includes the latest
1010
* (reachable) tag, and a postfix for any commits added after that
1111
*
12-
* For example: 3.0.2-12-gd504031 for tag 3.0.2, with 12 additional commits,
12+
* For example, 3.0.2-12-gd504031 for tag 3.0.2, with 12 additional commits,
1313
* the latest being gd504031
1414
*
1515
* @see http://git-scm.com/docs/git-describe
@@ -18,9 +18,6 @@ class Exec extends GitExec
1818
{
1919
/**
2020
* Get command for directory
21-
*
22-
* @param string $directory
23-
* @return string
2421
*/
2522
protected function getCommandForDirectory(string $directory): string
2623
{

src/Naneau/ProjectVersioner/Reader/Git/Exec.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* Exec
1010
*
11-
* Base class for exec based git reading
11+
* Base class for exec-based git reading
1212
*/
1313
abstract class Exec implements ReaderInterface
1414
{
@@ -26,7 +26,7 @@ public function canRead(string $directory): bool
2626
/**
2727
* {@inheritDoc}
2828
*/
29-
public function read(string $directory)
29+
public function read(string $directory): int|string|null
3030
{
3131
return $this->exec(
3232
$this->getCommandForDirectory($directory)
@@ -63,7 +63,7 @@ private function canExec(string $command, string $directory): bool
6363
}
6464

6565
/**
66-
* Execute a git command and return first line of output
66+
* Execute a git command and return the first line of output
6767
*/
6868
private function exec(string $command): string
6969
{

src/Naneau/ProjectVersioner/Reader/Git/Tag/Exec.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
/**
77
* Exec
88
*
9-
* Reads the latest tag reachable from the current commit
9+
* Reads the latest tag, reachable from the current commit
1010
*
11-
* For example: 3.0.2
11+
* For example, 3.0.2
1212
*
1313
* @see http://git-scm.com/docs/git-describe
1414
*/

src/Naneau/ProjectVersioner/ReaderInterface.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ public function canRead(string $directory): bool;
1515

1616
/**
1717
* Read the version from a directory
18-
*
19-
* @return string|int|null
2018
*/
21-
public function read(string $directory);
19+
public function read(string $directory): int|string|null;
2220
}

src/Naneau/ProjectVersioner/Versioner.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Versioner
1818
*
1919
* @var Reader[]
2020
*/
21-
private $readers;
21+
private array $readers;
2222

2323
/**
2424
* Constructor
@@ -32,10 +32,8 @@ public function __construct(array $readers = [])
3232

3333
/**
3434
* Get the version for a directory
35-
*
36-
* @return string|int|null
3735
*/
38-
public function get(string $directory)
36+
public function get(string $directory): int|string|null
3937
{
4038
foreach ($this->getReaders() as $reader) {
4139
if ($reader->canRead($directory)) {

tests/Naneau/ProjectVersioner/Test/Reader/FinderTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function testMtime(): void
1515

1616
$versioner = new Versioner([new MTimeReader('*.txt')]);
1717

18-
// Set the time to now for one of the files
18+
// Set the time to now for one of the files
1919
$time = time();
2020
touch($directory . '/DirectoryOne/FileFour.txt', $time);
2121

@@ -40,7 +40,7 @@ public function testEmptyNames(): void
4040

4141
$versioner = new Versioner([new MTimeReader()]);
4242

43-
// Set the time to now for one of the files
43+
// Set the time to now for one of the files
4444
$time = time();
4545
touch($directory . '/DirectoryOne/FileFour.txt', $time);
4646

tests/Naneau/ProjectVersioner/Test/Reader/GitExecTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class GitExecTest extends \PHPUnit\Framework\TestCase
1010
{
1111
/**
12-
* Test reading of latest commit
12+
* Test reading of the latest commit
1313
*/
1414
public function testShortCommitRead(): void
1515
{

0 commit comments

Comments
 (0)