Skip to content

Commit

Permalink
Merge pull request #59 from clue-labs/nullable
Browse files Browse the repository at this point in the history
Improve PHP 8.4+ support by avoiding implicitly nullable types
  • Loading branch information
clue authored Dec 6, 2024
2 parents f3b0283 + 797ec35 commit a46abeb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
],
"require": {
"php": ">=5.3",
"react/promise": "^3 || ^2.1 || ^1.2.1",
"react/socket": "^1.12",
"react/promise": "^3.2 || ^2.1 || ^1.2.1",
"react/socket": "^1.16",
"ringcentral/psr7": "^1.2"
},
"require-dev": {
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36",
"react/async": "^4 || ^3 || ^2",
"react/async": "^4.3 || ^3 || ^2",
"react/event-loop": "^1.2",
"react/http": "^1.5",
"react/promise-timer": "^1.10"
"react/http": "^1.11",
"react/promise-timer": "^1.11"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 5 additions & 1 deletion src/ProxyConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ProxyConnector implements ConnectorInterface
public function __construct(
#[\SensitiveParameter]
$proxyUrl,
ConnectorInterface $connector = null,
$connector = null,
array $httpHeaders = array()
) {
// support `http+unix://` scheme for Unix domain socket (UDS) paths
Expand All @@ -84,6 +84,10 @@ public function __construct(
throw new InvalidArgumentException('Invalid proxy URL "' . $proxyUrl . '"');
}

if ($connector !== null && !$connector instanceof ConnectorInterface) { // manual type check to support legacy PHP < 7.1
throw new \InvalidArgumentException('Argument #2 ($connector) expected null|React\Socket\ConnectorInterface');
}

// apply default port and TCP/TLS transport for given scheme
if (!isset($parts['port'])) {
$parts['port'] = $parts['scheme'] === 'https' ? 443 : 80;
Expand Down
6 changes: 6 additions & 0 deletions tests/ProxyConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public function testInvalidHttpsUnixScheme()
new ProxyConnector('https+unix:///tmp/proxy.sock', $this->connector);
}

public function testContructorThrowsExceptionForInvalidConnector()
{
$this->setExpectedException('InvalidArgumentException', 'Argument #2 ($connector) expected null|React\Socket\ConnectorInterface');
new ProxyConnector('proxy.example.com', 'connector');
}

public function testCreatesConnectionToHttpPort()
{
$promise = new Promise(function () { });
Expand Down

0 comments on commit a46abeb

Please sign in to comment.