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

Update to allow version check to work with php 8 #75

Closed
wants to merge 5 commits into from
Closed
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
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ matrix:
env: COMPOSER_VERSION=2.*@dev
- php: 7.4
env: COMPOSER_VERSION=dev-master
# - php: 8.0
# env: COMPOSER_VERSION=1.*
# - php: 8.0
# env: COMPOSER_VERSION=2.*@dev
# - php: 8.0
# env: COMPOSER_VERSION=dev-master
allow_failures:
- php: nightly
- env: COMPOSER_VERSION=dev-master
env: COMPOSER_VERSION=2.*@dev

sudo: false

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": "^5.3 || ^7.0",
"php": "^5.3 || ^7.0 || ^8.0",
"composer-plugin-api": "^1.0 || ^2.0"
},
"require-dev": {
Expand Down
22 changes: 17 additions & 5 deletions src/VersionsCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public function checkPackages(ArrayRepository $distRepository, WritableRepositor
// Old composer versions BC
$versionConstraint = class_exists('Composer\Semver\Constraint\Constraint')
? new Constraint('>', $package->getVersion())
: new VersionConstraint('>', $package->getVersion())
;
: new VersionConstraint('>', $package->getVersion());

$higherPackages = $distRepository->findPackages($package->getName(), $versionConstraint);

Expand All @@ -50,11 +49,24 @@ public function checkPackages(ArrayRepository $distRepository, WritableRepositor
if (\count($higherPackages) > 0) {
// Sort packages by highest version to lowest
usort($higherPackages, function (PackageInterface $p1, PackageInterface $p2) {
return Comparator::compare($p1->getVersion(), '<', $p2->getVersion());
if (Comparator::compare($p1->getVersion(), '=', $p2->getVersion())) {
return 0;
}
if (Comparator::compare($p1->getVersion(), '<', $p2->getVersion())) {
return 1;
}
return -1;
Comment on lines +52 to +58
Copy link

@pelmered pelmered Nov 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would replace with ternary:
return Comparator::compare($p1->getVersion(), '<', $p2->getVersion()) ? 1 : -1;
There shouldn't be any versions that are equal, right?

});

// Push actual and last package on outdated array
array_push($this->outdatedPackages, new OutdatedPackage($package, $higherPackages[0], $this->getPackageDepends($localRepository, $package)));
array_push(
$this->outdatedPackages,
new OutdatedPackage(
$package,
$higherPackages[0],
$this->getPackageDepends($localRepository, $package)
)
);
}
}
}
Expand All @@ -74,7 +86,7 @@ public function getOutput($showDepends = true)
$this->createNotUpToDateOutput($output, $showDepends);
}

return implode(PHP_EOL, $output).PHP_EOL;
return implode(PHP_EOL, $output) . PHP_EOL;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/OutdatedPackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public function testCreation()
$actual = new Package('foo/bar', '1.0.0', 'v1.0.0');
$last = new Package('foo/bar', '2.4.3', 'v2.4.3');
$links = array(
$this->getMock('Composer\Package\PackageInterface'),
$this->getMock('Composer\Package\PackageInterface'),
$this->getMock('Composer\Package\PackageInterface'),
$this->createMock('Composer\Package\PackageInterface'),
$this->createMock('Composer\Package\PackageInterface'),
$this->createMock('Composer\Package\PackageInterface'),
);

$outdatedPackage = new OutdatedPackage($actual, $last, $links);
Expand Down
2 changes: 1 addition & 1 deletion tests/VersionsCheckPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class VersionsCheckPluginTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->io = new BufferIO();
$this->composer = $this->getMock('Composer\Composer');
$this->composer = $this->createMock('Composer\Composer');
$this->config = new Config(false);

$this->composer->expects($this->any())->method('getConfig')
Expand Down