php-cs-fixer @PHP81Migration rule set

This commit is contained in:
Jack Worman 2022-08-11 08:25:16 -05:00
parent c74ad399e6
commit 6958ba1627
23 changed files with 452 additions and 401 deletions

View File

@ -26,7 +26,7 @@ return (new PhpCsFixer\Config())
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_trim' => true,
'@PHP74Migration' => true,
'@PHP74Migration:risky' => true,
'@PHP81Migration' => true,
'@PHP80Migration:risky' => true,
]
);

View File

@ -6,7 +6,7 @@
<arg name="extensions" value="php"/>
<arg name="basepath" value=".."/>
<arg name="report" value="emacs"/>
<arg name="report" value="diff"/>
<arg value="s"/>
<arg value="n"/>
<arg value="p"/>

File diff suppressed because it is too large Load Diff

View File

@ -57,7 +57,7 @@
}
],
"require": {
"php": ">=7.3",
"php": ">=8.1",
"paragonie/constant_time_encoding": "^2"
},
"require-dev": {

View File

@ -15,9 +15,7 @@ declare(strict_types=1);
namespace phpseclib3\Crypt\Common;
use phpseclib3\Crypt\DSA;
use phpseclib3\Crypt\Hash;
use phpseclib3\Crypt\RSA;
use phpseclib3\Exception\NoKeyLoadedException;
use phpseclib3\Exception\UnsupportedFormatException;
use phpseclib3\Math\BigInteger;
@ -152,7 +150,7 @@ abstract class AsymmetricKey
}
$components['format'] = $format;
$components['secret'] = $components['secret'] ?? '';
$components['secret'] ??= '';
$comment = $components['comment'] ?? null;
$new = static::onLoad($components);
$new->format = $format;
@ -226,7 +224,7 @@ abstract class AsymmetricKey
}
$components['format'] = $format;
$components['secret'] = $components['secret'] ?? '';
$components['secret'] ??= '';
$new = static::onLoad($components);
$new->format = $format;

View File

@ -67,7 +67,7 @@ abstract class OpenSSH
// key format is described here:
// https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.key?annotate=HEAD
if (strpos($key, 'BEGIN OPENSSH PRIVATE KEY') !== false) {
if (str_contains($key, 'BEGIN OPENSSH PRIVATE KEY')) {
$key = preg_replace('#(?:^-.*?-[\r\n]*$)|\s#ms', '', $key);
$key = Base64::decode($key);
$magic = Strings::shift($key, 15);

View File

@ -122,7 +122,7 @@ abstract class PuTTY
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
}
if (strpos($key, 'BEGIN SSH2 PUBLIC KEY') !== false) {
if (str_contains($key, 'BEGIN SSH2 PUBLIC KEY')) {
$lines = preg_split('#[\r\n]+#', $key);
switch (true) {
case $lines[0] != '---- BEGIN SSH2 PUBLIC KEY ----':

View File

@ -66,7 +66,7 @@ abstract class PKCS8 extends Progenitor
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
}
$isPublic = strpos($key, 'PUBLIC') !== false;
$isPublic = str_contains($key, 'PUBLIC');
$key = parent::load($key, $password);

View File

@ -70,7 +70,7 @@ abstract class PKCS8 extends Progenitor
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
}
$isPublic = strpos($key, 'PUBLIC') !== false;
$isPublic = str_contains($key, 'PUBLIC');
$key = parent::load($key, $password);

View File

@ -18,7 +18,6 @@ use phpseclib3\Crypt\EC\BaseCurves\TwistedEdwards;
use phpseclib3\Crypt\Hash;
use phpseclib3\Crypt\Random;
use phpseclib3\Math\BigInteger;
use phpseclib3\Math\PrimeField\Integer;
class Ed25519 extends TwistedEdwards
{
@ -182,7 +181,7 @@ class Ed25519 extends TwistedEdwards
return [
'dA' => $dA,
'secret' => $str
'secret' => $str,
];
}

View File

@ -123,7 +123,7 @@ class Ed448 extends TwistedEdwards
return [
'dA' => $dA,
'secret' => $str
'secret' => $str,
];
}

View File

@ -79,7 +79,7 @@ abstract class PKCS8 extends Progenitor
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
}
$isPublic = strpos($key, 'PUBLIC') !== false;
$isPublic = str_contains($key, 'PUBLIC');
$key = parent::load($key, $password);

View File

@ -49,9 +49,9 @@ abstract class PKCS1 extends Progenitor
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
}
if (strpos($key, 'PUBLIC') !== false) {
if (str_contains($key, 'PUBLIC')) {
$components = ['isPublicKey' => true];
} elseif (strpos($key, 'PRIVATE') !== false) {
} elseif (str_contains($key, 'PRIVATE')) {
$components = ['isPublicKey' => false];
} else {
$components = [];

View File

@ -71,9 +71,9 @@ abstract class PKCS8 extends Progenitor
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
}
if (strpos($key, 'PUBLIC') !== false) {
if (str_contains($key, 'PUBLIC')) {
$components = ['isPublicKey' => true];
} elseif (strpos($key, 'PRIVATE') !== false) {
} elseif (str_contains($key, 'PRIVATE')) {
$components = ['isPublicKey' => false];
} else {
$components = [];

View File

@ -103,7 +103,7 @@ abstract class PSS extends Progenitor
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
}
$components = ['isPublicKey' => strpos($key, 'PUBLIC') !== false];
$components = ['isPublicKey' => str_contains($key, 'PUBLIC')];
$key = parent::load($key, $password);

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace phpseclib3\File;
use DateTime;
use ParagonIE\ConstantTime\Base64;
use phpseclib3\Common\Functions\Strings;
use phpseclib3\File\ASN1\Element;
@ -1253,7 +1252,7 @@ abstract class ASN1
}
$prefix = substr($content, 0, 2) >= 50 ? '19' : '20';
$content = $prefix . $content;
} elseif (strpos($content, '.') !== false) {
} elseif (str_contains($content, '.')) {
$format .= '.u';
}
@ -1261,7 +1260,7 @@ abstract class ASN1
$content = substr($content, 0, -1) . '+0000';
}
if (strpos($content, '-') !== false || strpos($content, '+') !== false) {
if (str_contains($content, '-') || str_contains($content, '+')) {
$format .= 'O';
}

View File

@ -57,7 +57,7 @@ abstract class OpenSSL
throw new \UnexpectedValueException(openssl_error_string());
}
$class = get_class($x);
$class = $x::class;
return new $class($result, 256);
}
}

View File

@ -550,7 +550,7 @@ abstract class PHP extends Engine
$lhs = new static();
$rhs = new static();
}
if (static::class != get_class($temp)) {
if (static::class != $temp::class) {
$temp = new static();
$lhs = new static();
$rhs = new static();

View File

@ -1027,8 +1027,8 @@ class SFTP extends SSH2
}
break;
case 'mode':
$a[$sort] &= 07777;
$b[$sort] &= 07777;
$a[$sort] &= 0o7777;
$b[$sort] &= 0o7777;
// fall-through
default:
if ($a[$sort] === $b[$sort]) {
@ -1450,7 +1450,7 @@ class SFTP extends SSH2
$filename = $temp;
}
$attr = pack('N2', Attribute::PERMISSIONS, $mode & 07777);
$attr = pack('N2', Attribute::PERMISSIONS, $mode & 0o7777);
if (!$this->setstat($filename, $attr, $recursive)) {
return false;
}
@ -2825,26 +2825,26 @@ class SFTP extends SSH2
{
// values come from http://lxr.free-electrons.com/source/include/uapi/linux/stat.h#L12
// see, also, http://linux.die.net/man/2/stat
switch ($mode & 0170000) {// ie. 1111 0000 0000 0000
case 0000000: // no file type specified - figure out the file type using alternative means
switch ($mode & 0o170000) {// ie. 1111 0000 0000 0000
case 0: // no file type specified - figure out the file type using alternative means
return false;
case 0040000:
case 0o040000:
return FileType::DIRECTORY;
case 0100000:
case 0o100000:
return FileType::REGULAR;
case 0120000:
case 0o120000:
return FileType::SYMLINK;
// new types introduced in SFTPv5+
// http://tools.ietf.org/html/draft-ietf-secsh-filexfer-05#section-5.2
case 0010000: // named pipe (fifo)
case 0o010000: // named pipe (fifo)
return FileType::FIFO;
case 0020000: // character special
case 0o020000: // character special
return FileType::CHAR_DEVICE;
case 0060000: // block special
case 0o060000: // block special
return FileType::BLOCK_DEVICE;
case 0140000: // socket
case 0o140000: // socket
return FileType::SOCKET;
case 0160000: // whiteout
case 0o160000: // whiteout
// "SPECIAL should be used for files that are of
// a known type which cannot be expressed in the protocol"
return FileType::SPECIAL;

View File

@ -1500,8 +1500,8 @@ class SSH2
$exchange_hash_rfc4419 = '';
if (strpos($this->kex_algorithm, 'curve25519-sha256') === 0 || strpos($this->kex_algorithm, 'ecdh-sha2-nistp') === 0) {
$curve = strpos($this->kex_algorithm, 'curve25519-sha256') === 0 ?
if (str_starts_with($this->kex_algorithm, 'curve25519-sha256') || str_starts_with($this->kex_algorithm, 'ecdh-sha2-nistp')) {
$curve = str_starts_with($this->kex_algorithm, 'curve25519-sha256') ?
'Curve25519' :
substr($this->kex_algorithm, 10);
$ourPrivate = EC::createKey($curve);
@ -1509,7 +1509,7 @@ class SSH2
$clientKexInitMessage = MessageTypeExtra::KEX_ECDH_INIT;
$serverKexReplyMessage = MessageTypeExtra::KEX_ECDH_REPLY;
} else {
if (strpos($this->kex_algorithm, 'diffie-hellman-group-exchange') === 0) {
if (str_starts_with($this->kex_algorithm, 'diffie-hellman-group-exchange')) {
$dh_group_sizes_packed = pack(
'NNN',
$this->kex_dh_group_size_min,

View File

@ -268,7 +268,7 @@ class SFTPUserStoryTest extends PhpseclibFunctionalTestCase
public function testChModOnFile($sftp)
{
$this->assertNotFalse(
$sftp->chmod(0755, 'file1.txt'),
$sftp->chmod(0o755, 'file1.txt'),
'Failed asserting that chmod() was successful.'
);
@ -717,12 +717,12 @@ class SFTPUserStoryTest extends PhpseclibFunctionalTestCase
*/
public function testReadableWritable($sftp)
{
$sftp->chmod(0000, 'offset.txt');
$sftp->chmod(0, 'offset.txt');
$this->assertFalse($sftp->is_writable('offset.txt'));
$this->assertFalse($sftp->is_writeable('offset.txt'));
$this->assertFalse($sftp->is_readable('offset.txt'));
$sftp->chmod(0777, 'offset.txt');
$sftp->chmod(0o777, 'offset.txt');
$this->assertTrue($sftp->is_writable('offset.txt'));
$this->assertTrue($sftp->is_writeable('offset.txt'));
$this->assertTrue($sftp->is_readable('offset.txt'));

View File

@ -82,7 +82,7 @@ abstract class PhpseclibTestCase extends TestCase
protected static function getVar($obj, $var)
{
$reflection = new \ReflectionClass(get_class($obj));
$reflection = new \ReflectionClass($obj::class);
$prop = $reflection->getProperty($var);
$prop->setAccessible(true);
return $prop->getValue($obj);
@ -90,7 +90,7 @@ abstract class PhpseclibTestCase extends TestCase
public static function callFunc($obj, $func, $params = [])
{
$reflection = new \ReflectionClass(get_class($obj));
$reflection = new \ReflectionClass($obj::class);
$method = $reflection->getMethod($func);
$method->setAccessible(true);
return $method->invokeArgs($obj, $params);

View File

@ -100,7 +100,7 @@ class ChaCha20Test extends PhpseclibTestCase
$c = new ChaCha20();
$c->setPoly1305Key($key);
$r = new \ReflectionClass(get_class($c));
$r = new \ReflectionClass($c::class);
// this unit test is testing Poly1305 independent of ChaCha20, which phpseclib doesn't
// really support, hence this hackish approach
$m = $r->getMethod('poly1305');
@ -128,7 +128,7 @@ class ChaCha20Test extends PhpseclibTestCase
$c->setKey($key);
$c->setNonce($nonce);
$r = new \ReflectionClass(get_class($c));
$r = new \ReflectionClass($c::class);
$m = $r->getMethod('createPoly1305Key');
$m->setAccessible(true);
$result = $m->invoke($c);