diff --git a/build/php-cs-fixer.php b/build/php-cs-fixer.php index f51e0f72..359d1f9f 100644 --- a/build/php-cs-fixer.php +++ b/build/php-cs-fixer.php @@ -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, ] ); diff --git a/phpseclib/Crypt/Blowfish.php b/phpseclib/Crypt/Blowfish.php index 980ecb46..05fa4a55 100644 --- a/phpseclib/Crypt/Blowfish.php +++ b/phpseclib/Crypt/Blowfish.php @@ -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); diff --git a/phpseclib/Crypt/Common/Formats/Keys/OpenSSH.php b/phpseclib/Crypt/Common/Formats/Keys/OpenSSH.php index a0ced4b7..f42d1ade 100644 --- a/phpseclib/Crypt/Common/Formats/Keys/OpenSSH.php +++ b/phpseclib/Crypt/Common/Formats/Keys/OpenSSH.php @@ -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 diff --git a/phpseclib/Crypt/Common/Formats/Keys/PuTTY.php b/phpseclib/Crypt/Common/Formats/Keys/PuTTY.php index 6b9e4344..52386b46 100644 --- a/phpseclib/Crypt/Common/Formats/Keys/PuTTY.php +++ b/phpseclib/Crypt/Common/Formats/Keys/PuTTY.php @@ -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; diff --git a/phpseclib/Crypt/EC/Formats/Keys/OpenSSH.php b/phpseclib/Crypt/EC/Formats/Keys/OpenSSH.php index 84f1d108..c5a59c54 100644 --- a/phpseclib/Crypt/EC/Formats/Keys/OpenSSH.php +++ b/phpseclib/Crypt/EC/Formats/Keys/OpenSSH.php @@ -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++) { diff --git a/phpseclib/Crypt/RSA/Formats/Keys/Raw.php b/phpseclib/Crypt/RSA/Formats/Keys/Raw.php index ff667dee..46268b88 100644 --- a/phpseclib/Crypt/RSA/Formats/Keys/Raw.php +++ b/phpseclib/Crypt/RSA/Formats/Keys/Raw.php @@ -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), ]); } diff --git a/phpseclib/File/X509.php b/phpseclib/File/X509.php index 120a91f0..8c95121e 100644 --- a/phpseclib/File/X509.php +++ b/phpseclib/File/X509.php @@ -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; diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index 06966255..06d6ec46 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -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)); } } diff --git a/phpseclib/Math/BigInteger/Engines/GMP.php b/phpseclib/Math/BigInteger/Engines/GMP.php index 5471f00b..544d20fd 100644 --- a/phpseclib/Math/BigInteger/Engines/GMP.php +++ b/phpseclib/Math/BigInteger/Engines/GMP.php @@ -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); } /** diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 52c8c2e8..b96aa7e9 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -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); diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 7dd2010e..09456c01 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -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 diff --git a/phpseclib/System/SSH/Agent.php b/phpseclib/System/SSH/Agent.php index 20a93d99..954fdd56 100644 --- a/phpseclib/System/SSH/Agent.php +++ b/phpseclib/System/SSH/Agent.php @@ -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'); } diff --git a/phpseclib/System/SSH/Agent/Identity.php b/phpseclib/System/SSH/Agent/Identity.php index c3920196..0bb770cd 100644 --- a/phpseclib/System/SSH/Agent/Identity.php +++ b/phpseclib/System/SSH/Agent/Identity.php @@ -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'); } diff --git a/tests/Functional/Net/SFTPStreamTest.php b/tests/Functional/Net/SFTPStreamTest.php index c219f53d..d38ce4ea 100644 --- a/tests/Functional/Net/SFTPStreamTest.php +++ b/tests/Functional/Net/SFTPStreamTest.php @@ -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()); diff --git a/tests/PsalmBaselineTest.php b/tests/PsalmBaselineTest.php index ec33f61b..c12045c4 100644 --- a/tests/PsalmBaselineTest.php +++ b/tests/PsalmBaselineTest.php @@ -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; } diff --git a/tests/Unit/Crypt/AES/TestCase.php b/tests/Unit/Crypt/AES/TestCase.php index 98013461..6a984aaa 100644 --- a/tests/Unit/Crypt/AES/TestCase.php +++ b/tests/Unit/Crypt/AES/TestCase.php @@ -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); } /** diff --git a/tests/Unit/Crypt/EC/KeyTest.php b/tests/Unit/Crypt/EC/KeyTest.php index c8fa9d81..f6118402 100644 --- a/tests/Unit/Crypt/EC/KeyTest.php +++ b/tests/Unit/Crypt/EC/KeyTest.php @@ -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');