From e9dd4e350edaaea49e82a42a2eba83084bdbc97c Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 1 Oct 2024 14:35:04 +0800 Subject: [PATCH] wip --- .github/workflows/ci.yml | 28 ++++++------------ composer.json | 3 +- composer.lock | 60 ++++++++++++++++++++++++++++++++++++++- src/Helper.php | 14 ++++----- src/VersionInfo.php | 25 +++++++++------- tests/unit/HelperTest.php | 5 +++- 6 files changed, 92 insertions(+), 43 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c1dc84..ba43588 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,15 +21,7 @@ jobs: with: php-version: ${{ matrix.php }} - - name: Cache Composer dependencies - uses: actions/cache@v4 - with: - path: ~/.composer/cache - key: php-composer-locked-${{ hashFiles('composer.lock') }} - restore-keys: php-composer-locked- - - - name: Install PHP dependencies - run: composer install --no-interaction --no-progress + - uses: php-actions/composer@v6 # or alternative dependency management - name: Run PHPUnit run: vendor/bin/phpunit @@ -47,16 +39,12 @@ jobs: tools: cs2pr, phpcs coverage: none - - name: Cache Composer dependencies - uses: actions/cache@v4 - with: - path: ~/.composer/cache - key: php-composer-locked-${{ hashFiles('composer.lock') }} - restore-keys: php-composer-locked- - - - name: Install PHP dependencies - run: composer install --no-interaction --no-progress + - uses: php-actions/composer@v6 # or alternative dependency management - name: PHP CodeSniffer - run: phpcs -q --no-colors --report=checkstyle - # run: phpcs -q --no-colors --report=checkstyle | cs2pr + run: phpcs -q --no-colors --report=checkstyle | cs2pr + + - uses: php-actions/phpstan@v3 + with: + path: src/ + level: 7 diff --git a/composer.json b/composer.json index c888a01..286ecb4 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,8 @@ "phpunit/phpunit": "^11.3", "mikey179/vfsstream": "^1.6", "phpcsstandards/phpcsextra": "^1.2.0", - "squizlabs/php_codesniffer": "^3.10" + "squizlabs/php_codesniffer": "^3.10", + "phpstan/phpstan": "^1.12" }, "license": "GPLv3", "autoload": { diff --git a/composer.lock b/composer.lock index 2352d4d..ae74c35 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "21fdc66febab414bd52e137911fff6e7", + "content-hash": "6818cb62a9c4299d4becdd8ca9d80c33", "packages": [], "packages-dev": [ { @@ -539,6 +539,64 @@ ], "time": "2024-05-20T13:34:27+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.12.5", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17", + "reference": "7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2024-09-26T12:45:22+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "11.0.6", diff --git a/src/Helper.php b/src/Helper.php index ee6dfe1..30bce87 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -98,7 +98,7 @@ public static function getNextBranchNumber( * * @param int $versionint The integer part of the version * @param string|int $versiondec The decimal part of the version - * @return array + * @return array */ public static function getValidatedVersionNumber( int $versionint, @@ -121,8 +121,8 @@ public static function getValidatedVersionNumber( } return [ - (int) $versionint, - sprintf("%'02d", $versiondec), + 'versionint' => (int) $versionint, + 'versiondec' => (string) sprintf("%'02d", $versiondec), ]; } @@ -275,7 +275,7 @@ public static function requireVersionFileValid( /** * Get the value of an option from the options array. * - * @param array $options The options configuration + * @param array $options The options configuration * @param string $short The short name of the option * @param string $long The long name of the option * @return mixed @@ -288,11 +288,7 @@ public static function getOption( if (!isset($options[$short]) && !isset($options[$long])) { throw new Exception("Required option -$short|--$long must be provided.", __LINE__); } - if ( - (isset($options[$short]) && is_array($options[$short])) - || (isset($options[$long]) && is_array($options[$long])) - || (isset($options[$short]) && isset($options[$long])) - ) { + if (array_key_exists($short, $options) && array_key_exists($long, $options)) { throw new Exception("Option -$short|--$long specified more than once.", __LINE__); } return (isset($options[$short])) ? $options[$short] : $options[$long]; diff --git a/src/VersionInfo.php b/src/VersionInfo.php index df099ca..908be71 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -126,6 +126,9 @@ public static function fromVersionFile(string $path): self { Helper::requirePathValid($path); $versionfile = file_get_contents($path); + if (!$versionfile) { + throw new Exception('Could not read the version file.', __LINE__); + } return self::fromVersionContent($versionfile); } @@ -217,16 +220,16 @@ public function getNextVersion( ); } [ - $integerversion, - $decimalversion, + 'versionint' => $integerversion, + 'versiondec' => $decimalversion, ] = Helper::getValidatedVersionNumber($integerversion, $decimalversion); } elseif ($type === 'beta') { $release = preg_replace('#^(\d+.\d+) *(dev|beta)\+?#', '$1', $release); $branch = $branchcurrent; // Branch doesn't change in beta releases ever. $release .= 'beta'; [ - $integerversion, - $decimalversion, + 'versionint' => $integerversion, + 'versiondec' => $decimalversion, ] = Helper::getValidatedVersionNumber($integerversion, $decimalversion); $maturity = 'MATURITY_BETA'; } elseif ($type === 'rc') { @@ -234,8 +237,8 @@ public function getNextVersion( $branch = $branchcurrent; // Branch doesn't change in rc releases ever. $release .= 'rc' . $rc; [ - $integerversion, - $decimalversion, + 'versionint' => $integerversion, + 'versiondec' => $decimalversion, ] = Helper::getValidatedVersionNumber($integerversion, $decimalversion); $maturity = 'MATURITY_RC'; } elseif ($type === 'on-demand') { @@ -246,8 +249,8 @@ public function getNextVersion( $release .= '+'; } [ - $integerversion, - $decimalversion, + 'versionint' => $integerversion, + 'versiondec' => $decimalversion, ] = Helper::getValidatedVersionNumber($integerversion, $decimalversion); } elseif ($type === 'on-sync') { $decimalversion++; @@ -282,8 +285,8 @@ public function getNextVersion( $release = preg_replace('#^(\d+.\d+) *(dev|beta|rc\d+)\+?#', '$1', $release); $branch = $branchcurrent; // Branch doesn't change in major releases ever. [ - $integerversion, - $decimalversion, + 'versionint' => $integerversion, + 'versiondec' => $decimalversion, ] = Helper::getValidatedVersionNumber($integerversion, $decimalversion); $maturity = 'MATURITY_STABLE'; // Now handle builddate for releases. @@ -318,7 +321,7 @@ public function getNextVersion( } return new self( - integerversion: $integerversion, + integerversion: (int) $integerversion, decimalversion: $decimalversion, comment: $comment, release: $release, diff --git a/tests/unit/HelperTest.php b/tests/unit/HelperTest.php index 2b7a0e5..258c19d 100644 --- a/tests/unit/HelperTest.php +++ b/tests/unit/HelperTest.php @@ -71,7 +71,10 @@ public function testGetValidatedVersionNumber( int $expectedint, string $expecteddec ): void { - [$newint, $newdec] = Helper::getValidatedVersionNumber($int, $dec); + [ + 'versionint' => $newint, + 'versiondec' => $newdec, + ] = Helper::getValidatedVersionNumber($int, $dec); $this->assertSame($expectedint, $newint); $this->assertSame($expecteddec, $newdec); }