Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate InstalledVersions::getRawData #39

Merged
merged 7 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 14 additions & 29 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,28 @@ jobs:
- '7.3'
- '7.4'
- '8.0'
composer_version: ['v2']
include:
- description: '(prefer lowest)'
php: '7.1'
composer_version: '2.0.0'
dependencies: 'lowest'

name: PHP ${{ matrix.php }} tests
name: PHP ${{ matrix.php }} tests ${{ matrix.description }}
steps:
# checkout git
- uses: actions/checkout@v2
# cache
- uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: ${{ matrix.php }}
# setup PHP
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:${{ matrix.composer_version }}
coverage: xdebug
- run: composer install --no-progress --ansi
if: matrix.php != '8.0'
- run: composer install --no-progress --ansi --ignore-platform-reqs
if: matrix.php == '8.0'
- uses: "ramsey/composer-install@v1"
with:
dependency-versions: ${{ matrix.dependencies }}
- run: vendor/bin/phpunit --coverage-clover=coverage.xml
if: matrix.php != '8.0'
- run: vendor/bin/phpunit
if: matrix.php == '8.0'
- uses: codecov/codecov-action@v1
if: matrix.php != '8.0'
with:
file: './coverage.xml'
fail_ci_if_error: true
Expand All @@ -50,41 +47,29 @@ jobs:
name: Code style
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: '7.4'
- uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
- run: composer install --no-progress --ansi
- uses: "ramsey/composer-install@v1"
- run: vendor/bin/php-cs-fixer fix --ansi --verbose --dry-run
PHPStan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: '7.4'
- uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
- run: composer install --no-progress --ansi
- uses: "ramsey/composer-install@v1"
- run: vendor/bin/phpstan analyse
Psalm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: '7.4'
- uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
- run: composer install --no-progress --ansi
- uses: "ramsey/composer-install@v1"
- run: vendor/bin/psalm
42 changes: 36 additions & 6 deletions src/PrettyVersions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ class PrettyVersions
*/
public static function getVersion(string $packageName): Version
{
if (isset(InstalledVersions::getRawData()['versions'][$packageName]['provided'])) {
throw ProvidedPackageException::create($packageName);
}
self::checkProvidedPackages($packageName);

if (isset(InstalledVersions::getRawData()['versions'][$packageName]['replaced'])) {
throw ReplacedPackageException::create($packageName);
}
self::checkReplacedPackages($packageName);

return new Version(
$packageName,
Expand All @@ -44,4 +40,38 @@ public static function getRootPackageVersion(): Version
InstalledVersions::getRootPackage()['reference']
);
}

protected static function checkProvidedPackages(string $packageName): void
{
if (! method_exists(InstalledVersions::class, 'getAllRawData')) {
if (isset(InstalledVersions::getRawData()['versions'][$packageName]['provided'])) {
throw ProvidedPackageException::create($packageName);
}

return;
}

foreach (InstalledVersions::getAllRawData() as $installed) {
if (isset($installed['versions'][$packageName]['provided'])) {
throw ProvidedPackageException::create($packageName);
}
}
}

protected static function checkReplacedPackages(string $packageName): void
{
if (! method_exists(InstalledVersions::class, 'getAllRawData')) {
if (isset(InstalledVersions::getRawData()['versions'][$packageName]['replaced'])) {
throw ReplacedPackageException::create($packageName);
}

return;
}

foreach (InstalledVersions::getAllRawData() as $installed) {
if (isset($installed['versions'][$packageName]['replaced'])) {
throw ReplacedPackageException::create($packageName);
}
}
}
}