Skip to content

Commit

Permalink
Merge pull request #7 from AngryBytes/feat/php-8.3
Browse files Browse the repository at this point in the history
Feat/php 8.3
  • Loading branch information
stephank authored Dec 1, 2023
2 parents b1de636 + 46b10aa commit 68cd668
Show file tree
Hide file tree
Showing 20 changed files with 73 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.4', '8.0', '8.1', '8.2']
php-versions: ['8.1', '8.2', '8.3']
name: PHP ${{ matrix.php-versions }} tests
steps:
- name: Checkout
Expand Down
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/vendor/
composer.lock
.phpunit.result.cache
/composer.lock
/vendor

/.php-cs-fixer.cache
/.phpunit.cache
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 3.0.0

### PHP support

- Dropped support for PHP `8.0` and lower.
- Added support for PHP `8.3`.

### 3rd party updates

- Updated `symfony/finder` to version `6`.

## 2.0.1

### PHP support
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
},
"minimum-stability": "stable",
"require": {
"php": "7.4.* || 8.0.* || 8.1.* || 8.2.*",
"php": "8.1.* || 8.2.* || 8.3.*",
"ext-json": "*",
"symfony/finder": "^5.0.0"
"symfony/finder": "^6.0.0"
},
"require-dev": {
"phpstan/phpstan": "1.9.12",
"phpunit/phpunit": "9.5.28",
"squizlabs/php_codesniffer": "3.7.1"
"phpstan/phpstan": "1.10.46",
"phpunit/phpunit": "10.4.2",
"squizlabs/php_codesniffer": "3.7.2"
}
}
27 changes: 14 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
>

<testsuites>
<testsuite name="ProjectVersioner Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="ProjectVersioner Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
4 changes: 2 additions & 2 deletions src/Naneau/ProjectVersioner/Reader/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Composer
*
* Finds version from composer lock file
* Finds the version from composer lock file
*/
class Composer implements ReaderInterface
{
Expand All @@ -21,7 +21,7 @@ public function canRead(string $directory): bool
/**
* {@inheritdoc}
*/
public function read(string $directory)
public function read(string $directory): int|string|null
{
$contents = file_get_contents($directory . '/composer.lock');
if (!$contents) {
Expand Down
10 changes: 8 additions & 2 deletions src/Naneau/ProjectVersioner/Reader/ComposerJson.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Naneau\ProjectVersioner\Reader;

use JsonException;
use Naneau\ProjectVersioner\ReaderInterface;

use stdClass;
Expand All @@ -21,14 +22,19 @@ public function canRead(string $directory): bool
/**
* {@inheritdoc}
*/
public function read(string $directory)
public function read(string $directory): int|string|null
{
$json = @file_get_contents($directory . '/composer.json');
if (!$json) {
return null;
}

$json = json_decode($json, false);
try {
$json = json_decode($json, false, 512, JSON_THROW_ON_ERROR);
} catch (JsonException) {
return null;
}

if (!($json instanceof stdClass) || empty($json->version)) {
return null;
}
Expand Down
14 changes: 9 additions & 5 deletions src/Naneau/ProjectVersioner/Reader/ComposerPackage.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Naneau\ProjectVersioner\Reader;

use JsonException;
use Naneau\ProjectVersioner\ReaderInterface;

use stdClass;
Expand All @@ -15,10 +16,8 @@ class ComposerPackage implements ReaderInterface
{
/**
* The page name to look for
*
* @var string
*/
private $package;
private string $package;

public function __construct(string $package)
{
Expand Down Expand Up @@ -46,7 +45,7 @@ public function canRead(string $directory): bool
/**
* {@inheritdoc}
*/
public function read(string $directory)
public function read(string $directory): int|string|null
{
$package = $this->getPackageFromLockFile($directory);

Expand Down Expand Up @@ -88,7 +87,12 @@ private function getPackageFromLockFile(string $directory): ?stdClass
return null;
}

$parsed = json_decode($contents, false);
try {
$parsed = json_decode($contents, false, 512, JSON_THROW_ON_ERROR);
} catch (JsonException) {
return null;
}

if (!isset($parsed->packages)) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Naneau/ProjectVersioner/Reader/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function canRead(string $directory): bool
/**
* {@inheritdoc}
*/
public function read(string $directory)
public function read(string $directory): int|string|null
{
$contents = file_get_contents($directory . DIRECTORY_SEPARATOR . $this->getFile());
if (!$contents) {
Expand Down
2 changes: 1 addition & 1 deletion src/Naneau/ProjectVersioner/Reader/Finder/Contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Contents extends Finder
/**
* {@inheritdoc}
*/
public function read(string $directory)
public function read(string $directory): string
{
$hash = '';
foreach ($this->getFinder() as $file) {
Expand Down
6 changes: 2 additions & 4 deletions src/Naneau/ProjectVersioner/Reader/Finder/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
/**
* Finder
*
* Base class for finder based readers
* Base class for finder-based readers
*/
abstract class Finder implements ReaderInterface
{
/**
* the finder
*
* @var SfFinder
*/
private $finder;
private SfFinder $finder;

public function __construct(?string $name = null, ?SfFinder $finder = null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Naneau/ProjectVersioner/Reader/Finder/MTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MTime extends Finder
/**
* {@inheritdoc}
*/
public function read(string $directory)
public function read(string $directory): int|string|null
{
$highest = 0;
foreach ($this->getFinder() as $file) {
Expand Down
4 changes: 1 addition & 3 deletions src/Naneau/ProjectVersioner/Reader/Git/Commit/Exec.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ class Exec extends GitExec
{
/**
* Use short hash?
*
* @var bool
*/
private $short = true;
private bool $short = true;

public function __construct(bool $short = true)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Naneau/ProjectVersioner/Reader/Git/Describe/Exec.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Reads the latest "described" version from git, which includes the latest
* (reachable) tag, and a postfix for any commits added after that
*
* For example: 3.0.2-12-gd504031 for tag 3.0.2, with 12 additional commits,
* For example, 3.0.2-12-gd504031 for tag 3.0.2, with 12 additional commits,
* the latest being gd504031
*
* @see http://git-scm.com/docs/git-describe
Expand All @@ -18,9 +18,6 @@ class Exec extends GitExec
{
/**
* Get command for directory
*
* @param string $directory
* @return string
*/
protected function getCommandForDirectory(string $directory): string
{
Expand Down
6 changes: 3 additions & 3 deletions src/Naneau/ProjectVersioner/Reader/Git/Exec.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Exec
*
* Base class for exec based git reading
* Base class for exec-based git reading
*/
abstract class Exec implements ReaderInterface
{
Expand All @@ -26,7 +26,7 @@ public function canRead(string $directory): bool
/**
* {@inheritDoc}
*/
public function read(string $directory)
public function read(string $directory): int|string|null
{
return $this->exec(
$this->getCommandForDirectory($directory)
Expand Down Expand Up @@ -63,7 +63,7 @@ private function canExec(string $command, string $directory): bool
}

/**
* Execute a git command and return first line of output
* Execute a git command and return the first line of output
*/
private function exec(string $command): string
{
Expand Down
4 changes: 2 additions & 2 deletions src/Naneau/ProjectVersioner/Reader/Git/Tag/Exec.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
/**
* Exec
*
* Reads the latest tag reachable from the current commit
* Reads the latest tag, reachable from the current commit
*
* For example: 3.0.2
* For example, 3.0.2
*
* @see http://git-scm.com/docs/git-describe
*/
Expand Down
4 changes: 1 addition & 3 deletions src/Naneau/ProjectVersioner/ReaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public function canRead(string $directory): bool;

/**
* Read the version from a directory
*
* @return string|int|null
*/
public function read(string $directory);
public function read(string $directory): int|string|null;
}
6 changes: 2 additions & 4 deletions src/Naneau/ProjectVersioner/Versioner.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Versioner
*
* @var Reader[]
*/
private $readers;
private array $readers;

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

/**
* Get the version for a directory
*
* @return string|int|null
*/
public function get(string $directory)
public function get(string $directory): int|string|null
{
foreach ($this->getReaders() as $reader) {
if ($reader->canRead($directory)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Naneau/ProjectVersioner/Test/Reader/FinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testMtime(): void

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

// Set the time to now for one of the files
// Set the time to now for one of the files
$time = time();
touch($directory . '/DirectoryOne/FileFour.txt', $time);

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

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

// Set the time to now for one of the files
// Set the time to now for one of the files
$time = time();
touch($directory . '/DirectoryOne/FileFour.txt', $time);

Expand Down
2 changes: 1 addition & 1 deletion tests/Naneau/ProjectVersioner/Test/Reader/GitExecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class GitExecTest extends \PHPUnit\Framework\TestCase
{
/**
* Test reading of latest commit
* Test reading of the latest commit
*/
public function testShortCommitRead(): void
{
Expand Down

0 comments on commit 68cd668

Please sign in to comment.