Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve PHP 8.4+ support by avoiding implicitly nullable types #59

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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