diff --git a/.github/workflows/php-checks.yml b/.github/workflows/php-checks.yml index 08f9257..3fc04d2 100644 --- a/.github/workflows/php-checks.yml +++ b/.github/workflows/php-checks.yml @@ -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 diff --git a/.gitignore b/.gitignore index 0794651..2cf6eb4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ -/vendor/ -composer.lock -.phpunit.result.cache +/composer.lock +/vendor + +/.php-cs-fixer.cache +/.phpunit.cache diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b3d20b..403c757 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/composer.json b/composer.json index 9b3dadd..a19ca26 100644 --- a/composer.json +++ b/composer.json @@ -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" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 238f65f..24076d8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,15 +1,16 @@ + - - - - ./tests/ - - + 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" +> + + + ./tests/ + + diff --git a/src/Naneau/ProjectVersioner/Reader/Composer.php b/src/Naneau/ProjectVersioner/Reader/Composer.php index 41de516..d5b511d 100644 --- a/src/Naneau/ProjectVersioner/Reader/Composer.php +++ b/src/Naneau/ProjectVersioner/Reader/Composer.php @@ -6,7 +6,7 @@ /** * Composer * - * Finds version from composer lock file + * Finds the version from composer lock file */ class Composer implements ReaderInterface { @@ -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) { diff --git a/src/Naneau/ProjectVersioner/Reader/ComposerJson.php b/src/Naneau/ProjectVersioner/Reader/ComposerJson.php index e7b813d..f6a0758 100644 --- a/src/Naneau/ProjectVersioner/Reader/ComposerJson.php +++ b/src/Naneau/ProjectVersioner/Reader/ComposerJson.php @@ -1,6 +1,7 @@ version)) { return null; } diff --git a/src/Naneau/ProjectVersioner/Reader/ComposerPackage.php b/src/Naneau/ProjectVersioner/Reader/ComposerPackage.php index c4bccc9..d1331a9 100644 --- a/src/Naneau/ProjectVersioner/Reader/ComposerPackage.php +++ b/src/Naneau/ProjectVersioner/Reader/ComposerPackage.php @@ -1,6 +1,7 @@ getPackageFromLockFile($directory); @@ -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; } diff --git a/src/Naneau/ProjectVersioner/Reader/File.php b/src/Naneau/ProjectVersioner/Reader/File.php index 3a78a23..fa1a3bd 100644 --- a/src/Naneau/ProjectVersioner/Reader/File.php +++ b/src/Naneau/ProjectVersioner/Reader/File.php @@ -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) { diff --git a/src/Naneau/ProjectVersioner/Reader/Finder/Contents.php b/src/Naneau/ProjectVersioner/Reader/Finder/Contents.php index 81ad013..11a955f 100644 --- a/src/Naneau/ProjectVersioner/Reader/Finder/Contents.php +++ b/src/Naneau/ProjectVersioner/Reader/Finder/Contents.php @@ -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) { diff --git a/src/Naneau/ProjectVersioner/Reader/Finder/Finder.php b/src/Naneau/ProjectVersioner/Reader/Finder/Finder.php index 42f9480..c558a06 100644 --- a/src/Naneau/ProjectVersioner/Reader/Finder/Finder.php +++ b/src/Naneau/ProjectVersioner/Reader/Finder/Finder.php @@ -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) { diff --git a/src/Naneau/ProjectVersioner/Reader/Finder/MTime.php b/src/Naneau/ProjectVersioner/Reader/Finder/MTime.php index 4c3a4df..79a86b1 100644 --- a/src/Naneau/ProjectVersioner/Reader/Finder/MTime.php +++ b/src/Naneau/ProjectVersioner/Reader/Finder/MTime.php @@ -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) { diff --git a/src/Naneau/ProjectVersioner/Reader/Git/Commit/Exec.php b/src/Naneau/ProjectVersioner/Reader/Git/Commit/Exec.php index 4845eee..a758218 100644 --- a/src/Naneau/ProjectVersioner/Reader/Git/Commit/Exec.php +++ b/src/Naneau/ProjectVersioner/Reader/Git/Commit/Exec.php @@ -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) { diff --git a/src/Naneau/ProjectVersioner/Reader/Git/Describe/Exec.php b/src/Naneau/ProjectVersioner/Reader/Git/Describe/Exec.php index 2d1d7cd..bd8fe71 100644 --- a/src/Naneau/ProjectVersioner/Reader/Git/Describe/Exec.php +++ b/src/Naneau/ProjectVersioner/Reader/Git/Describe/Exec.php @@ -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 @@ -18,9 +18,6 @@ class Exec extends GitExec { /** * Get command for directory - * - * @param string $directory - * @return string */ protected function getCommandForDirectory(string $directory): string { diff --git a/src/Naneau/ProjectVersioner/Reader/Git/Exec.php b/src/Naneau/ProjectVersioner/Reader/Git/Exec.php index 5a156e1..c0c70d3 100644 --- a/src/Naneau/ProjectVersioner/Reader/Git/Exec.php +++ b/src/Naneau/ProjectVersioner/Reader/Git/Exec.php @@ -8,7 +8,7 @@ /** * Exec * - * Base class for exec based git reading + * Base class for exec-based git reading */ abstract class Exec implements ReaderInterface { @@ -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) @@ -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 { diff --git a/src/Naneau/ProjectVersioner/Reader/Git/Tag/Exec.php b/src/Naneau/ProjectVersioner/Reader/Git/Tag/Exec.php index 29033f0..6ba320d 100644 --- a/src/Naneau/ProjectVersioner/Reader/Git/Tag/Exec.php +++ b/src/Naneau/ProjectVersioner/Reader/Git/Tag/Exec.php @@ -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 */ diff --git a/src/Naneau/ProjectVersioner/ReaderInterface.php b/src/Naneau/ProjectVersioner/ReaderInterface.php index 5193b86..8c4bb97 100644 --- a/src/Naneau/ProjectVersioner/ReaderInterface.php +++ b/src/Naneau/ProjectVersioner/ReaderInterface.php @@ -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; } diff --git a/src/Naneau/ProjectVersioner/Versioner.php b/src/Naneau/ProjectVersioner/Versioner.php index cbbe066..46cc246 100644 --- a/src/Naneau/ProjectVersioner/Versioner.php +++ b/src/Naneau/ProjectVersioner/Versioner.php @@ -18,7 +18,7 @@ class Versioner * * @var Reader[] */ - private $readers; + private array $readers; /** * Constructor @@ -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)) { diff --git a/tests/Naneau/ProjectVersioner/Test/Reader/FinderTest.php b/tests/Naneau/ProjectVersioner/Test/Reader/FinderTest.php index 71bbae3..6e669b8 100644 --- a/tests/Naneau/ProjectVersioner/Test/Reader/FinderTest.php +++ b/tests/Naneau/ProjectVersioner/Test/Reader/FinderTest.php @@ -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); @@ -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); diff --git a/tests/Naneau/ProjectVersioner/Test/Reader/GitExecTest.php b/tests/Naneau/ProjectVersioner/Test/Reader/GitExecTest.php index 0142527..d465034 100644 --- a/tests/Naneau/ProjectVersioner/Test/Reader/GitExecTest.php +++ b/tests/Naneau/ProjectVersioner/Test/Reader/GitExecTest.php @@ -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 {