From 44d5ca2ab572b047caf09bf7e2397a8fb6bf7b10 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Thu, 25 Jul 2024 00:27:03 -0500 Subject: [PATCH] CS adjustment --- phpseclib/Net/SSH2.php | 11 ++++------- tests/Functional/Net/SSH2Test.php | 2 +- tests/PhpseclibTestCase.php | 4 ++-- tests/Unit/Net/SSH2UnitTest.php | 23 ++++++++++------------- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index a1cfd3f3..e98b0e7d 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -724,8 +724,6 @@ class SSH2 /** * Time of last read/write network activity - * - * @var float */ private float|null $last_packet = null; @@ -1483,7 +1481,7 @@ class SSH2 $this->updateLogHistory('UNKNOWN (34)', 'SSH_MSG_KEXDH_GEX_REQUEST'); $response = $this->get_binary_packet_or_close(MessageTypeExtra::KEXDH_GEX_GROUP); - list($type, $primeBytes, $gBytes) = Strings::unpackSSH2('Css', $response); + [$type, $primeBytes, $gBytes] = Strings::unpackSSH2('Css', $response); $this->updateLogHistory('UNKNOWN (31)', 'SSH_MSG_KEXDH_GEX_GROUP'); $prime = new BigInteger($primeBytes, -256); @@ -3653,8 +3651,6 @@ class SSH2 * on other channels is buffered. The respective negative value of a channel is * also supported for the case that the caller is awaiting adjustment of the data * window, and where data received on that respective channel is also buffered. - * @param bool $skip_extended - * @return mixed * @throws RuntimeException on connection error */ protected function get_channel_packet(int $client_channel, bool $skip_extended = false) @@ -4143,8 +4139,9 @@ class SSH2 */ protected function send_channel_packet(int $client_channel, string $data): void { - if (isset($this->channel_buffers_write[$client_channel]) - && strpos($data, $this->channel_buffers_write[$client_channel]) === 0 + if ( + isset($this->channel_buffers_write[$client_channel]) + && str_starts_with($data, $this->channel_buffers_write[$client_channel]) ) { // if buffer holds identical initial data content, resume send from the unmatched data portion $data = substr($data, strlen($this->channel_buffers_write[$client_channel])); diff --git a/tests/Functional/Net/SSH2Test.php b/tests/Functional/Net/SSH2Test.php index 4ecca1e7..2ccb9c3c 100644 --- a/tests/Functional/Net/SSH2Test.php +++ b/tests/Functional/Net/SSH2Test.php @@ -571,7 +571,7 @@ class SSH2Test extends PhpseclibFunctionalTestCase $this->assertSame(0, $ssh->getOpenChannelCount()); } - public function testKeepAlive() + public function testKeepAlive(): void { $ssh = $this->getSSH2(); $username = $this->getEnv('SSH_USERNAME'); diff --git a/tests/PhpseclibTestCase.php b/tests/PhpseclibTestCase.php index 2672c84a..b6d9ae7f 100644 --- a/tests/PhpseclibTestCase.php +++ b/tests/PhpseclibTestCase.php @@ -99,9 +99,9 @@ abstract class PhpseclibTestCase extends TestCase return $prop->getValue($obj); } - protected static function setVar($obj, $var, $value) + protected static function setVar($obj, $var, $value): void { - $reflection = new \ReflectionClass(get_class($obj)); + $reflection = new \ReflectionClass($obj::class); // private variables are not inherited, climb hierarchy until located while (true) { try { diff --git a/tests/Unit/Net/SSH2UnitTest.php b/tests/Unit/Net/SSH2UnitTest.php index 3489c48a..4bad1bb9 100644 --- a/tests/Unit/Net/SSH2UnitTest.php +++ b/tests/Unit/Net/SSH2UnitTest.php @@ -223,7 +223,7 @@ class SSH2UnitTest extends PhpseclibTestCase /** * @requires PHPUnit < 10 */ - public function testGetStreamTimeout() + public function testGetStreamTimeout(): void { // no curTimeout, no keepAlive $ssh = $this->createSSHMock(); @@ -238,7 +238,7 @@ class SSH2UnitTest extends PhpseclibTestCase $ssh = $this->createSSHMock(); $ssh->setKeepAlive(2); self::setVar($ssh, 'last_packet', microtime(true)); - list($sec, $usec) = self::callFunc($ssh, 'get_stream_timeout'); + [$sec, $usec] = self::callFunc($ssh, 'get_stream_timeout'); $this->assertGreaterThanOrEqual(1, $sec); $this->assertLessThanOrEqual(2, $sec); @@ -254,7 +254,7 @@ class SSH2UnitTest extends PhpseclibTestCase $ssh->setTimeout(5); $ssh->setKeepAlive(2); self::setVar($ssh, 'last_packet', microtime(true)); - list($sec, $usec) = self::callFunc($ssh, 'get_stream_timeout'); + [$sec, $usec] = self::callFunc($ssh, 'get_stream_timeout'); $this->assertGreaterThanOrEqual(1, $sec); $this->assertLessThanOrEqual(2, $sec); @@ -273,7 +273,7 @@ class SSH2UnitTest extends PhpseclibTestCase /** * @requires PHPUnit < 10 */ - public function testSendChannelPacketNoBufferedData() + public function testSendChannelPacketNoBufferedData(): void { $ssh = $this->getMockBuilder('phpseclib3\Net\SSH2') ->disableOriginalConstructor() @@ -282,7 +282,7 @@ class SSH2UnitTest extends PhpseclibTestCase $ssh->expects($this->once()) ->method('get_channel_packet') ->with(-1) - ->willReturnCallback(function () use ($ssh) { + ->willReturnCallback(function () use ($ssh): void { self::setVar($ssh, 'window_size_client_to_server', [1 => 0x7FFFFFFF]); }); $ssh->expects($this->once()) @@ -300,7 +300,7 @@ class SSH2UnitTest extends PhpseclibTestCase /** * @requires PHPUnit < 10 */ - public function testSendChannelPacketBufferedData() + public function testSendChannelPacketBufferedData(): void { $ssh = $this->getMockBuilder('phpseclib3\Net\SSH2') ->disableOriginalConstructor() @@ -309,7 +309,7 @@ class SSH2UnitTest extends PhpseclibTestCase $ssh->expects($this->once()) ->method('get_channel_packet') ->with(-1) - ->willReturnCallback(function () use ($ssh) { + ->willReturnCallback(function () use ($ssh): void { self::setVar($ssh, 'window_size_client_to_server', [1 => 0x7FFFFFFF]); }); $ssh->expects($this->once()) @@ -328,7 +328,7 @@ class SSH2UnitTest extends PhpseclibTestCase /** * @requires PHPUnit < 10 */ - public function testSendChannelPacketTimeout() + public function testSendChannelPacketTimeout(): void { $this->expectException(TimeoutException::class); $this->expectExceptionMessage('Timed out waiting for server'); @@ -340,7 +340,7 @@ class SSH2UnitTest extends PhpseclibTestCase $ssh->expects($this->once()) ->method('get_channel_packet') ->with(-1) - ->willReturnCallback(function () use ($ssh) { + ->willReturnCallback(function () use ($ssh): void { self::setVar($ssh, 'is_timeout', true); }); $ssh->expects($this->once()) @@ -358,7 +358,7 @@ class SSH2UnitTest extends PhpseclibTestCase /** * @requires PHPUnit < 10 */ - public function testSendChannelPacketNoWindowAdjustment() + public function testSendChannelPacketNoWindowAdjustment(): void { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Data window was not adjusted'); @@ -380,9 +380,6 @@ class SSH2UnitTest extends PhpseclibTestCase self::callFunc($ssh, 'send_channel_packet', [1, 'hello world']); } - /** - * @return \phpseclib3\Net\SSH2 - */ protected function createSSHMock(): SSH2 { return $this->getMockBuilder('phpseclib3\Net\SSH2')