1
0
Fork 0

Fix a few phpstan errors and add a php8+ baseline for the rest

pull/10343/head
Jordi Boggiano 2022-01-01 14:39:32 +01:00
parent a4a2b6da87
commit 0b3adc84da
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
12 changed files with 8916 additions and 9 deletions

8875
phpstan/baseline-8.1.neon Normal file

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,7 @@ includes:
- ../vendor/phpstan/phpstan-deprecation-rules/rules.neon
- ../vendor/phpstan/phpstan-strict-rules/rules.neon
- ./baseline.neon
- ./ignore-by-php-version.neon.php
parameters:
level: 8

View File

@ -0,0 +1,14 @@
<?php declare(strict_types = 1);
use PHPStan\DependencyInjection\NeonAdapter;
$adapter = new NeonAdapter();
// more inspiration at https://github.com/phpstan/phpstan-src/blob/master/build/ignore-by-php-version.neon.php
$config = [];
if (PHP_VERSION_ID >= 80000) {
$config = array_merge_recursive($config, $adapter->load(__DIR__ . '/baseline-8.1.neon'));
}
$config['parameters']['phpVersion'] = PHP_VERSION_ID;
return $config;

View File

@ -163,7 +163,8 @@ class ClassMapGenerator
$rejectedClasses = array();
$realSubPath = substr($filePath, strlen($basePath) + 1);
$realSubPath = substr($realSubPath, 0, strrpos($realSubPath, '.'));
$dotPosition = strrpos($realSubPath, '.');
$realSubPath = substr($realSubPath, 0, $dotPosition === false ? PHP_INT_MAX : $dotPosition);
foreach ($classes as $class) {
// silently skip if ns doesn't have common root
@ -226,7 +227,7 @@ class ClassMapGenerator
$message = 'File at "%s" does not exist, check your classmap definitions';
} elseif (!Filesystem::isReadable($path)) {
$message = 'File at "%s" is not readable, check its permissions';
} elseif ('' === trim(file_get_contents($path))) {
} elseif ('' === trim((string) file_get_contents($path))) {
// The input file was really empty and thus contains no classes
return array();
} else {

View File

@ -218,7 +218,7 @@ class Cache
$file = Preg::replace('{[^'.$this->allowlist.']}i', '-', $file);
if (file_exists($this->root . $file)) {
try {
touch($this->root . $file, filemtime($this->root . $file), time());
touch($this->root . $file, (int) filemtime($this->root . $file), time());
} catch (\ErrorException $e) {
// fallback in case the above failed due to incorrect ownership
// see https://github.com/composer/composer/issues/4070

View File

@ -298,6 +298,9 @@ TAGSPUBKEY
}
$pubkeyid = openssl_pkey_get_public($sigFile);
if (false === $pubkeyid) {
throw new \RuntimeException('Failed loading the public key from '.$sigFile);
}
$algo = defined('OPENSSL_ALGO_SHA384') ? OPENSSL_ALGO_SHA384 : 'SHA384';
if (!in_array('sha384', array_map('strtolower', openssl_get_md_methods()))) {
throw new \RuntimeException('SHA384 is not supported by your openssl extension, could not verify the phar file integrity');
@ -308,6 +311,7 @@ TAGSPUBKEY
// PHP 8 automatically frees the key instance and deprecates the function
if (PHP_VERSION_ID < 80000) {
// @phpstan-ignore-next-line
openssl_free_key($pubkeyid);
}

View File

@ -80,7 +80,7 @@ class Locker
*/
public static function getContentHash($composerFileContents)
{
$content = json_decode($composerFileContents, true);
$content = JsonFile::parseJson($composerFileContents, 'composer.json');
$relevantKeys = array(
'name',
@ -107,7 +107,7 @@ class Locker
ksort($relevantContent);
return md5(json_encode($relevantContent));
return md5(JsonFile::encode($relevantContent, 0));
}
/**

View File

@ -137,7 +137,11 @@ final class TlsHelper
*/
public static function getCertificateFingerprint($certificate)
{
$pubkeydetails = openssl_pkey_get_details(openssl_get_publickey($certificate));
$pubkey = openssl_get_publickey($certificate);
if ($pubkey === false) {
throw new \RuntimeException('Failed to retrieve the public key from certificate');
}
$pubkeydetails = openssl_pkey_get_details($pubkey);
$pubkeypem = $pubkeydetails['key'];
//Convert PEM to DER before SHA1'ing
$start = '-----BEGIN PUBLIC KEY-----';

View File

@ -453,6 +453,9 @@ class InstallerTest extends TestCase
$application->setAutoExit(false);
$appOutput = fopen('php://memory', 'w+');
if (false === $appOutput) {
self::fail('Failed to open memory stream');
}
$input = new StringInput($run.' -vvv');
$input->setInteractive(false);
$result = $application->run($input, new StreamOutput($appOutput));
@ -555,7 +558,7 @@ class InstallerTest extends TestCase
if (!empty($testData['LOCK'])) {
$lock = JsonFile::parseJson($testData['LOCK']);
if (!isset($lock['hash'])) {
$lock['hash'] = md5(json_encode($composer));
$lock['hash'] = md5(JsonFile::encode($composer, 0));
}
}
if (!empty($testData['INSTALLED'])) {

View File

@ -156,7 +156,6 @@ class ComposerRepositoryTest extends TestCase
),
)));
$versionParser = new VersionParser();
$reflMethod = new \ReflectionMethod($repo, 'whatProvides');
$reflMethod->setAccessible(true);
$packages = $reflMethod->invoke($repo, 'a');

View File

@ -129,7 +129,7 @@ class CompositeRepositoryTest extends TestCase
/**
* @dataProvider provideMethodCalls
*
* @param string $method
* @param string $method
* @param mixed[] $args
*/
public function testNoRepositories($method, $args)

View File

@ -277,6 +277,9 @@ class PerforceTest extends TestCase
public function testWriteP4ClientSpecWithoutStream()
{
$stream = fopen('php://memory', 'w+');
if (false === $stream) {
self::fail('Could not open memory stream');
}
$this->perforce->writeClientSpecToFile($stream);
rewind($stream);
@ -298,6 +301,9 @@ class PerforceTest extends TestCase
{
$this->setPerforceToStream();
$stream = fopen('php://memory', 'w+');
if (false === $stream) {
self::fail('Could not open memory stream');
}
$this->perforce->writeClientSpecToFile($stream);
rewind($stream);