Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Oct 1, 2024
1 parent 991ca3f commit e9dd4e3
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 43 deletions.
28 changes: 8 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
60 changes: 59 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, int|string>
*/
public static function getValidatedVersionNumber(
int $versionint,
Expand All @@ -121,8 +121,8 @@ public static function getValidatedVersionNumber(
}

return [
(int) $versionint,
sprintf("%'02d", $versiondec),
'versionint' => (int) $versionint,
'versiondec' => (string) sprintf("%'02d", $versiondec),
];
}

Expand Down Expand Up @@ -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<string, string> $options The options configuration
* @param string $short The short name of the option
* @param string $long The long name of the option
* @return mixed
Expand All @@ -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];
Expand Down
25 changes: 14 additions & 11 deletions src/VersionInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -217,25 +220,25 @@ 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') {
$release = preg_replace('#^(\d+.\d+) *(dev|beta|rc\d)\+?#', '$1', $release);
$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') {
Expand All @@ -246,8 +249,8 @@ public function getNextVersion(
$release .= '+';
}
[
$integerversion,
$decimalversion,
'versionint' => $integerversion,
'versiondec' => $decimalversion,
] = Helper::getValidatedVersionNumber($integerversion, $decimalversion);
} elseif ($type === 'on-sync') {
$decimalversion++;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -318,7 +321,7 @@ public function getNextVersion(
}

return new self(
integerversion: $integerversion,
integerversion: (int) $integerversion,
decimalversion: $decimalversion,
comment: $comment,
release: $release,
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit e9dd4e3

Please sign in to comment.