Skip to content

Commit

Permalink
Merge pull request #124 from scoutapp/fix-warning-on-connect
Browse files Browse the repository at this point in the history
Fix warning on failed socket_connect
  • Loading branch information
Chris Schneider authored Dec 3, 2019
2 parents bc06103 + b169ad8 commit a3346e9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
beStrictAboutChangesToGlobalState="true"
beStrictAboutTodoAnnotatedTests="true"
forceCoversAnnotation="true"
convertWarningsToExceptions="false"
convertErrorsToExceptions="false"
convertNoticesToExceptions="false"
convertDeprecationsToExceptions="false"
>
<testsuites>
<testsuite name="unit">
Expand All @@ -20,6 +24,7 @@
</testsuites>
<php>
<ini name="error_reporting" value="E_ALL" />
<ini name="display_errors" value="On" />
</php>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
Expand Down
18 changes: 18 additions & 0 deletions src/Connector/SocketConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@

namespace Scoutapm\Connector;

use ErrorException;
use Scoutapm\Connector\Exception\FailedToConnect;
use Scoutapm\Connector\Exception\NotConnected;
use Throwable;
use const AF_UNIX;
use const E_NOTICE;
use const E_STRICT;
use const E_WARNING;
use const SOCK_STREAM;
use function json_encode;
use function pack;
use function register_shutdown_function;
use function restore_error_handler;
use function set_error_handler;
use function socket_clear_error;
use function socket_close;
use function socket_connect;
Expand Down Expand Up @@ -56,11 +62,23 @@ public function connect() : void

try {
socket_clear_error($this->socket);

// phpcs:disable SlevomatCodingStandard.TypeHints.TypeHintDeclaration.IncorrectReturnTypeHint
set_error_handler(
static function (int $severity, string $message, string $file = '', int $line = 0, array $context = []) : bool {
throw new ErrorException($message, 0, $severity, $file, $line);
},
E_STRICT | E_NOTICE | E_WARNING
);
// phpcs:enable

$this->connected = socket_connect($this->socket, $this->socketPath);
register_shutdown_function([&$this, 'shutdown']);
} catch (Throwable $e) {
$this->connected = false;
throw FailedToConnect::fromSocketPathAndPrevious($this->socketPath, $e);
} finally {
restore_error_handler();
}
}

Expand Down

0 comments on commit a3346e9

Please sign in to comment.