Fix 3 sonarqube bugs
continuous-integration/drone/push Build is passing Details

main
Hugo Thunnissen 2 years ago
parent f2df6c7a1b
commit f9d2feb9cb

@ -115,7 +115,7 @@ class AutoloadGenerator
public function setApcu(bool $apcu, ?string $apcuPrefix = null) public function setApcu(bool $apcu, ?string $apcuPrefix = null)
{ {
$this->apcu = $apcu; $this->apcu = $apcu;
$this->apcuPrefix = $apcuPrefix !== null ? $apcuPrefix : $apcuPrefix; $this->apcuPrefix = $apcuPrefix;
} }
/** /**

@ -243,15 +243,13 @@ class PhpFileCleaner
} }
// skip the rest of the line // skip the rest of the line
while ($this->index < $this->len) { if ($this->index < $this->len) {
$this->skipToNewline(); $this->skipToNewline();
// skip newlines // skip newlines
while ($this->index < $this->len && ($this->contents[$this->index] === "\r" || $this->contents[$this->index] === "\n")) { while ($this->index < $this->len && ($this->contents[$this->index] === "\r" || $this->contents[$this->index] === "\n")) {
$this->index += 1; $this->index += 1;
} }
break;
} }
} }
} }

@ -215,7 +215,7 @@ class Problem
if (PlatformRepository::isPlatformPackage($packageName)) { if (PlatformRepository::isPlatformPackage($packageName)) {
// handle php/php-*/hhvm // handle php/php-*/hhvm
if (0 === stripos($packageName, 'php') || $packageName === 'hhvm') { if (0 === stripos($packageName, 'php') || $packageName === 'hhvm') {
$version = self::getPlatformPackageVersion($pool, $packageName, phpversion()); $version = self::getPlatformPackageVersion($pool, $packageName);
$msg = "- Root composer.json requires ".$packageName.self::constraintToText($constraint).' but '; $msg = "- Root composer.json requires ".$packageName.self::constraintToText($constraint).' but ';
@ -243,7 +243,7 @@ class Problem
$ext = substr($packageName, 4); $ext = substr($packageName, 4);
$msg = "- Root composer.json requires PHP extension ".$packageName.self::constraintToText($constraint).' but '; $msg = "- Root composer.json requires PHP extension ".$packageName.self::constraintToText($constraint).' but ';
$version = self::getPlatformPackageVersion($pool, $packageName, phpversion($ext) ?: '0'); $version = self::getPlatformPackageVersion($pool, $packageName);
if (null === $version) { if (null === $version) {
if (extension_loaded($ext)) { if (extension_loaded($ext)) {
return array( return array(
@ -427,39 +427,39 @@ class Problem
* @param string $version the effective runtime version of the platform package * @param string $version the effective runtime version of the platform package
* @return ?string a version string or null if it appears the package was artificially disabled * @return ?string a version string or null if it appears the package was artificially disabled
*/ */
private static function getPlatformPackageVersion(Pool $pool, string $packageName, string $version): ?string private static function getPlatformPackageVersion(Pool $pool, string $packageName): ?string
{ {
$available = $pool->whatProvides($packageName); $available = $pool->whatProvides($packageName);
if (count($available)) { if (!count($available)) {
$selected = null; return null;
foreach ($available as $pkg) { }
if ($pkg->getRepository() instanceof PlatformRepository) {
$selected = $pkg; $selected = null;
break; foreach ($available as $pkg) {
} if ($pkg->getRepository() instanceof PlatformRepository) {
} $selected = $pkg;
if ($selected === null) { break;
$selected = reset($available);
} }
}
if ($selected === null) {
$selected = reset($available);
}
// must be a package providing/replacing and not a real platform package // must be a package providing/replacing and not a real platform package
if ($selected->getName() !== $packageName) { if ($selected->getName() !== $packageName) {
/** @var Link $link */ /** @var Link $link */
foreach (array_merge(array_values($selected->getProvides()), array_values($selected->getReplaces())) as $link) { foreach (array_merge(array_values($selected->getProvides()), array_values($selected->getReplaces())) as $link) {
if ($link->getTarget() === $packageName) { if ($link->getTarget() === $packageName) {
return $link->getPrettyConstraint().' '.substr($link->getDescription(), 0, -1).'d by '.$selected->getPrettyString(); return $link->getPrettyConstraint().' '.substr($link->getDescription(), 0, -1).'d by '.$selected->getPrettyString();
}
} }
} }
}
$version = $selected->getPrettyVersion(); $version = $selected->getPrettyVersion();
$extra = $selected->getExtra(); $extra = $selected->getExtra();
if ($selected instanceof CompletePackageInterface && isset($extra['config.platform']) && $extra['config.platform'] === true) { if ($selected instanceof CompletePackageInterface && isset($extra['config.platform']) && $extra['config.platform'] === true) {
$version .= '; ' . str_replace('Package ', '', $selected->getDescription()); $version .= '; ' . str_replace('Package ', '', $selected->getDescription());
}
} else {
return null;
} }
return $version; return $version;

Loading…
Cancel
Save