php-cs-fixer - php 7.4 rules

This commit is contained in:
Jack Worman 2022-08-11 08:12:15 -05:00
parent f199a0cfe9
commit 80f2d7f521
17 changed files with 34 additions and 62 deletions

View File

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

View File

@ -536,11 +536,11 @@ class Blowfish extends BlockCipher
$p[14] ^ $key[14],
$p[15] ^ $key[15],
$p[16] ^ $key[0],
$p[17] ^ $key[1]
$p[17] ^ $key[1],
];
// @codingStandardsIgnoreStart
[ $p[0], $p[1]] = self::encryptBlockHelper( 0, 0, $sbox0, $sbox1, $sbox2, $sbox3, $p);
[ $p[0], $p[1]] = self::encryptBlockHelper( 0, 0, $sbox0, $sbox1, $sbox2, $sbox3, $p);
[ $p[2], $p[3]] = self::encryptBlockHelper($p[ 0], $p[ 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
[ $p[4], $p[5]] = self::encryptBlockHelper($p[ 2], $p[ 3], $sbox0, $sbox1, $sbox2, $sbox3, $p);
[ $p[6], $p[7]] = self::encryptBlockHelper($p[ 4], $p[ 5], $sbox0, $sbox1, $sbox2, $sbox3, $p);
@ -605,11 +605,11 @@ class Blowfish extends BlockCipher
$p[14] ^ $key[14],
$p[15] ^ $key[15],
$p[16] ^ $key[0],
$p[17] ^ $key[1]
$p[17] ^ $key[1],
];
// @codingStandardsIgnoreStart
[ $p[0], $p[1]] = self::encryptBlockHelper($data[ 0] , $data[ 1] , $sbox0, $sbox1, $sbox2, $sbox3, $p);
[ $p[0], $p[1]] = self::encryptBlockHelper($data[ 0], $data[ 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
[ $p[2], $p[3]] = self::encryptBlockHelper($data[ 2] ^ $p[ 0], $data[ 3] ^ $p[ 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
[ $p[4], $p[5]] = self::encryptBlockHelper($data[ 4] ^ $p[ 2], $data[ 5] ^ $p[ 3], $sbox0, $sbox1, $sbox2, $sbox3, $p);
[ $p[6], $p[7]] = self::encryptBlockHelper($data[ 6] ^ $p[ 4], $data[ 7] ^ $p[ 5], $sbox0, $sbox1, $sbox2, $sbox3, $p);

View File

@ -21,7 +21,6 @@ use ParagonIE\ConstantTime\Base64;
use phpseclib3\Common\Functions\Strings;
use phpseclib3\Crypt\AES;
use phpseclib3\Crypt\Random;
use phpseclib3\Exception\UnsupportedFormatException;
/**
* OpenSSH Formatted RSA Key Handler

View File

@ -131,9 +131,7 @@ abstract class PuTTY
throw new \UnexpectedValueException('Key doesn\'t end with ---- END SSH2 PUBLIC KEY ----');
}
$lines = array_splice($lines, 1, -1);
$lines = array_map(function ($line) {
return rtrim($line, "\r\n");
}, $lines);
$lines = array_map(fn ($line) => rtrim($line, "\r\n"), $lines);
$data = $current = '';
$values = [];
$in_value = false;

View File

@ -110,9 +110,7 @@ abstract class OpenSSH extends Progenitor
$name = $reflect->getShortName();
$oid = self::$curveOIDs[$name];
$aliases = array_filter(self::$curveOIDs, function ($v) use ($oid) {
return $v == $oid;
});
$aliases = array_filter(self::$curveOIDs, fn ($v) => $v == $oid);
$aliases = array_keys($aliases);
for ($i = 0; $i < count($aliases); $i++) {

View File

@ -149,15 +149,9 @@ abstract class Raw
'e' => clone $e,
'n' => clone $n,
'd' => clone $d,
'primes' => array_map(function ($var) {
return clone $var;
}, $primes),
'exponents' => array_map(function ($var) {
return clone $var;
}, $exponents),
'coefficients' => array_map(function ($var) {
return clone $var;
}, $coefficients),
'primes' => array_map(fn ($var) => clone $var, $primes),
'exponents' => array_map(fn ($var) => clone $var, $exponents),
'coefficients' => array_map(fn ($var) => clone $var, $coefficients),
]);
}

View File

@ -1103,8 +1103,8 @@ class X509
if (isset($parts['query'])) {
$path.= '?' . $parts['query'];
}
fputs($fsock, "GET $path HTTP/1.0\r\n");
fputs($fsock, "Host: $parts[host]\r\n\r\n");
fwrite($fsock, "GET $path HTTP/1.0\r\n");
fwrite($fsock, "Host: $parts[host]\r\n\r\n");
$line = fgets($fsock, 1024);
if (strlen($line) < 3) {
return false;
@ -1843,9 +1843,7 @@ class X509
$value = array_pop($value); // Always strip data type.
}
} elseif (is_object($value) && $value instanceof Element) {
$callback = function ($x) {
return '\x' . bin2hex($x[0]);
};
$callback = fn ($x) => '\x' . bin2hex($x[0]);
$value = strtoupper(preg_replace_callback('#[^\x20-\x7E]#', $callback, $value->element));
}
$output .= $desc . '=' . $value;

View File

@ -665,9 +665,7 @@ class BigInteger implements \JsonSerializable
public static function min(BigInteger ...$nums): BigInteger
{
$class = self::$mainEngine;
$nums = array_map(function ($num) {
return $num->value;
}, $nums);
$nums = array_map(fn ($num) => $num->value, $nums);
return new static($class::min(...$nums));
}
@ -677,9 +675,7 @@ class BigInteger implements \JsonSerializable
public static function max(BigInteger ...$nums): BigInteger
{
$class = self::$mainEngine;
$nums = array_map(function ($num) {
return $num->value;
}, $nums);
$nums = array_map(fn ($num) => $num->value, $nums);
return new static($class::max(...$nums));
}
@ -755,9 +751,7 @@ class BigInteger implements \JsonSerializable
public function createRecurringModuloFunction()
{
$func = $this->value->createRecurringModuloFunction();
return function (BigInteger $x) use ($func) {
return new static($func($x->value));
};
return fn (BigInteger $x) => new static($func($x->value));
}
/**
@ -769,8 +763,6 @@ class BigInteger implements \JsonSerializable
*/
public function bitwise_split(int $split): array
{
return array_map(function ($val) {
return new static($val);
}, $this->value->bitwise_split($split));
return array_map(fn ($val) => new static($val), $this->value->bitwise_split($split));
}
}

View File

@ -537,9 +537,7 @@ class GMP extends Engine
public function createRecurringModuloFunction(): \Closure
{
$temp = $this->value;
return function (GMP $x) use ($temp) {
return new GMP($x->value % $temp);
};
return fn (GMP $x) => new GMP($x->value % $temp);
}
/**

View File

@ -2183,7 +2183,7 @@ class SFTP extends SSH2
} elseif (is_callable($local_file)) {
$local_file($temp);
} else {
fputs($fp, $temp);
fwrite($fp, $temp);
}
if (is_callable($progressCallback)) {
call_user_func($progressCallback, $offset);

View File

@ -1172,7 +1172,7 @@ class SSH2
$this->identifier = $this->generate_identifier();
if ($this->send_id_string_first) {
fputs($this->fsock, $this->identifier . "\r\n");
fwrite($this->fsock, $this->identifier . "\r\n");
}
/* According to the SSH2 specs,
@ -1251,7 +1251,7 @@ class SSH2
}
if (!$this->send_id_string_first) {
fputs($this->fsock, $this->identifier . "\r\n");
fwrite($this->fsock, $this->identifier . "\r\n");
}
if (!$this->send_kex_first) {
@ -3264,18 +3264,18 @@ class SSH2
$cmf = ord($payload[0]);
$cm = $cmf & 0x0F;
if ($cm != 8) { // deflate
user_error("Only CM = 8 ('deflate') is supported ($cm)");
trigger_error("Only CM = 8 ('deflate') is supported ($cm)");
}
$cinfo = ($cmf & 0xF0) >> 4;
if ($cinfo > 7) {
user_error("CINFO above 7 is not allowed ($cinfo)");
trigger_error("CINFO above 7 is not allowed ($cinfo)");
}
$windowSize = 1 << ($cinfo + 8);
$flg = ord($payload[1]);
//$fcheck = $flg && 0x0F;
if ((($cmf << 8) | $flg) % 31) {
user_error('fcheck failed');
trigger_error('fcheck failed');
}
$fdict = boolval($flg & 0x20);
$flevel = ($flg & 0xC0) >> 6;
@ -3930,7 +3930,7 @@ class SSH2
$packet .= $this->encrypt && $this->encrypt->usesNonce() ? $this->encrypt->getTag() : $hmac;
$start = microtime(true);
$sent = @fputs($this->fsock, $packet);
$sent = @fwrite($this->fsock, $packet);
$stop = microtime(true);
if (defined('NET_SSH2_LOGGING')) {
@ -4056,7 +4056,7 @@ class SSH2
$realtime_log_size = strlen($entry);
$realtime_log_wrap = true;
}
fputs($realtime_log_file, $entry);
fwrite($realtime_log_file, $entry);
}
}
@ -4195,9 +4195,7 @@ class SSH2
$output .= str_pad(dechex($j), 7, '0', STR_PAD_LEFT) . '0 ';
}
$fragment = Strings::shift($current_log, $this->log_short_width);
$hex = substr(preg_replace_callback('#.#s', function ($matches) {
return $this->log_boundary . str_pad(dechex(ord($matches[0])), 2, '0', STR_PAD_LEFT);
}, $fragment), strlen($this->log_boundary));
$hex = substr(preg_replace_callback('#.#s', fn ($matches) => $this->log_boundary . str_pad(dechex(ord($matches[0])), 2, '0', STR_PAD_LEFT), $fragment), strlen($this->log_boundary));
// replace non ASCII printable characters with dots
// http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters
// also replace < with a . since < messes up the output on web browsers

View File

@ -36,7 +36,6 @@ namespace phpseclib3\System\SSH;
use phpseclib3\Common\Functions\Strings;
use phpseclib3\Crypt\PublicKeyLoader;
use phpseclib3\Crypt\RSA;
use phpseclib3\Exception\BadConfigurationException;
use phpseclib3\Net\SSH2;
use phpseclib3\System\SSH\Agent\Identity;
@ -152,7 +151,7 @@ class Agent
}
$packet = pack('NC', 1, self::SSH_AGENTC_REQUEST_IDENTITIES);
if (strlen($packet) != fputs($this->fsock, $packet)) {
if (strlen($packet) != fwrite($this->fsock, $packet)) {
throw new \RuntimeException('Connection closed while requesting identities');
}

View File

@ -264,7 +264,7 @@ class Identity implements PrivateKey
$this->flags
);
$packet = Strings::packSSH2('s', $packet);
if (strlen($packet) != fputs($this->fsock, $packet)) {
if (strlen($packet) != fwrite($this->fsock, $packet)) {
throw new \RuntimeException('Connection closed during signing');
}

View File

@ -40,7 +40,7 @@ class SFTPStreamTest extends SFTPTestCase
'sftp' => ['session' => $this->sftp],
]);
$fp = fopen($this->buildUrl('te#st.txt'), 'wb', false, $context);
fputs($fp, 'zzzz');
fwrite($fp, 'zzzz');
fclose($fp);
$this->assertContains('te#st.txt', $this->sftp->nlist());

View File

@ -34,7 +34,7 @@ class PsalmBaselineTest extends TestCase
/** @var array{level: int, type: string, tag: string, attributes: array{OCCURRENCES?: int}} $element */
foreach ($values as $element) {
if ($element['level'] === 3 && ($element['type'] === 'open' || $element['type'] === 'complete')) {
$errorCounts[$element['tag']] = $errorCounts[$element['tag']] ?? 0;
$errorCounts[$element['tag']] ??= 0;
$occurrences = $element['attributes']['OCCURRENCES'] ?? 1;
$errorCounts[$element['tag']] += $occurrences;
}

View File

@ -178,9 +178,7 @@ abstract class TestCase extends PhpseclibTestCase
*/
public function continuousBufferBatteryCombosWithoutSingleCombos(): array
{
return array_filter($this->continuousBufferBatteryCombos(), function (array $continuousBufferBatteryCombo) {
return count($continuousBufferBatteryCombo[2]) > 1;
});
return array_filter($this->continuousBufferBatteryCombos(), fn (array $continuousBufferBatteryCombo) => count($continuousBufferBatteryCombo[2]) > 1);
}
/**

View File

@ -568,7 +568,7 @@ MIIEDwIBADATBgcqhkjOPQIBBggqhkjOPQMBBwSCA/MwggPvAgEBBIID6P//////
$this->assertSameNL($raw, $key->toString('MontgomeryPrivate'));
}
public function testOpenSSHEncryptedCreation()
public function testOpenSSHEncryptedCreation(): void
{
$key = EC::createKey('Ed25519');
$key = $key->withPassword('test')->toString('OpenSSH');