Skip to content

Commit

Permalink
Fix some issues identified by phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-knight committed Sep 29, 2024
1 parent 50ca9d5 commit 7aacc7b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/HL7/Segments/GT1.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Aranyasen\HL7\Segments;

use Aranyasen\HL7\Segment;
use InvalidArgumentException;

/**
* GT1 segment class
Expand Down
6 changes: 3 additions & 3 deletions src/HL7/Segments/MSH.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public function __construct(array $fields = null, array $hl7Globals = null)
* @param int $index Index of field
* @param string $value
*/
public function setField(int $index, $value = ''): bool
public function setField(int $index, string|int|array|null $value = ''): bool
{
if (($index === 1) && strlen($value) !== 1) {
if (($index === 1) && (!is_string($value) || strlen($value) !== 1)) {
return false;
}

if (($index === 2) && strlen($value) !== 4) {
if (($index === 2) && (!is_string($value) || strlen($value) !== 4)) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions tests/HL7Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Aranyasen\HL7;
use Aranyasen\HL7\Segments\PID;
use DMS\PHPUnitExtensions\ArraySubset\Assert;
use Exception;

class HL7Test extends TestCase
{
Expand Down
11 changes: 4 additions & 7 deletions tests/Hl7ListenerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,19 @@ public function createTcpServer(int $port, int $totalClientsToConnect): void
}

if (($ret = socket_bind($socket, "localhost", $port)) === false) {
throw new RuntimeException('socket_bind() failed: reason: ' . socket_strerror($ret) . "\n");
throw new RuntimeException('socket_bind() failed: reason: ' . socket_strerror(socket_last_error($socket)) . "\n");
}
if (($ret = socket_listen($socket, 5)) === false) {
throw new RuntimeException('socket_listen() failed: reason: ' . socket_strerror($ret) . "\n");
throw new RuntimeException('socket_listen() failed: reason: ' . socket_strerror(socket_last_error($socket)) . "\n");
}

$clientCount = 0;
while (true) { // Loop over each client
if (($clientSocket = socket_accept($socket)) === false) {
echo 'socket_accept() failed: reason: ' . socket_strerror(socket_last_error()) . "\n";
socket_close($clientSocket);
echo 'socket_accept() failed: reason: ' . socket_strerror(socket_last_error($socket)) . "\n";
socket_close($socket);
exit();
}
if ($clientSocket === false) {
continue;
}

$clientCount++;
$clientName = 'Unknown';
Expand Down

0 comments on commit 7aacc7b

Please sign in to comment.