Skip to content

Commit

Permalink
Merge branch 'master' into deprecate-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric authored Nov 6, 2024
2 parents 173cdb1 + 452fc34 commit 402c044
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 51 deletions.
32 changes: 20 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ concurrency:

jobs:
tests:
name: Tests
name: Tests (${{ matrix.os }}, ${{ matrix.php.version }}, ${{ matrix.dependencies }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -27,13 +27,14 @@ jobs:
- ubuntu-latest
- windows-latest
php:
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
- { version: '7.2', phpunit: '^8.5.40' }
- { version: '7.3', phpunit: '^9.6.21' }
- { version: '7.4', phpunit: '^9.6.21' }
- { version: '8.0', phpunit: '^9.6.21' }
- { version: '8.1', phpunit: '^9.6.21' }
- { version: '8.2', phpunit: '^9.6.21' }
- { version: '8.3', phpunit: '^9.6.21' }
- { version: '8.4', phpunit: '^9.6.21' }
dependencies:
- lowest
- highest
Expand All @@ -47,7 +48,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
php-version: ${{ matrix.php.version }}
coverage: xdebug

- name: Setup Problem Matchers for PHPUnit
Expand All @@ -62,8 +63,15 @@ jobs:
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.directory }}
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.dependencies }}-composer-
key: ${{ runner.os }}-${{ matrix.php.version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php.version }}-${{ matrix.dependencies }}-composer-

# These dependencies are not used running the tests but can cause deprecation warnings so we remove them before running the tests
- name: Remove unused dependencies
run: composer remove vimeo/psalm phpstan/phpstan friendsofphp/php-cs-fixer --dev --no-interaction --no-update

- name: Set phpunit/phpunit version constraint
run: composer require phpunit/phpunit:'${{ matrix.php.phpunit }}' --dev --no-interaction --no-update

- name: Install highest dependencies
run: composer update --no-progress --no-interaction --prefer-dist
Expand All @@ -84,4 +92,4 @@ jobs:

- name: Check benchmarks
run: vendor/bin/phpbench run --revs=1 --iterations=1
if: ${{ matrix.dependencies == 'highest' && matrix.php == '8.2' }}
if: ${{ matrix.dependencies == 'highest' && matrix.php.version == '8.3' }}
6 changes: 3 additions & 3 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: '8.3'

- name: Install dependencies
run: composer update --no-progress --no-interaction --prefer-dist
Expand All @@ -39,7 +39,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: '8.3'

- name: Install dependencies
run: composer update --no-progress --no-interaction --prefer-dist
Expand All @@ -59,7 +59,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: '8.3'

- name: Install dependencies
run: composer update --no-progress --no-interaction --prefer-dist
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.4",
"guzzlehttp/promises": "^1.0|^2.0",
"guzzlehttp/promises": "^2.0.3",
"guzzlehttp/psr7": "^1.8.4|^2.1.1",
"monolog/monolog": "^1.6|^2.0|^3.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "^1.3",
"phpunit/phpunit": "^8.5.14|^9.4",
"phpunit/phpunit": "^8.5|^9.6",
"symfony/phpunit-bridge": "^5.2|^6.0|^7.0",
"vimeo/psalm": "^4.17"
},
Expand Down
3 changes: 2 additions & 1 deletion src/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ final class ErrorHandler
\E_USER_DEPRECATED => 'User Deprecated',
\E_NOTICE => 'Notice',
\E_USER_NOTICE => 'User Notice',
\E_STRICT => 'Runtime Notice',
// This is \E_STRICT which has been deprecated in PHP 8.4 so we should not reference it directly to prevent deprecation notices
2048 => 'Runtime Notice',
\E_WARNING => 'Warning',
\E_USER_WARNING => 'User Warning',
\E_COMPILE_WARNING => 'Compile Warning',
Expand Down
2 changes: 1 addition & 1 deletion src/FrameBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private function getFunctionArguments(array $backtraceFrame): array
} else {
$reflectionFunction = new \ReflectionMethod($backtraceFrame['class'], '__call');
}
} elseif (!\in_array($backtraceFrame['function'], ['{closure}', '__lambda_func'], true) && \function_exists($backtraceFrame['function'])) {
} elseif ($backtraceFrame['function'] !== '__lambda_func' && !str_starts_with($backtraceFrame['function'], '{closure') && \function_exists($backtraceFrame['function'])) {
$reflectionFunction = new \ReflectionFunction($backtraceFrame['function']);
}
} catch (\ReflectionException $e) {
Expand Down
16 changes: 2 additions & 14 deletions src/HttpClient/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,15 @@ public function sendRequest(Request $request, Options $options): Response
curl_setopt($curlHandle, \CURLOPT_URL, $dsn->getEnvelopeApiEndpointUrl());
curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, $requestHeaders);
curl_setopt($curlHandle, \CURLOPT_USERAGENT, $this->sdkIdentifier . '/' . $this->sdkVersion);
curl_setopt($curlHandle, \CURLOPT_TIMEOUT_MS, $options->getHttpTimeout() * 1000);
curl_setopt($curlHandle, \CURLOPT_CONNECTTIMEOUT_MS, $options->getHttpConnectTimeout() * 1000);
curl_setopt($curlHandle, \CURLOPT_ENCODING, '');
curl_setopt($curlHandle, \CURLOPT_POST, true);
curl_setopt($curlHandle, \CURLOPT_POSTFIELDS, $requestData);
curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlHandle, \CURLOPT_HEADERFUNCTION, $responseHeaderCallback);
curl_setopt($curlHandle, \CURLOPT_HTTP_VERSION, \CURL_HTTP_VERSION_1_1);

$httpTimeout = $options->getHttpTimeout();
if ($httpTimeout < 1.0) {
curl_setopt($curlHandle, \CURLOPT_TIMEOUT_MS, $httpTimeout * 1000);
} else {
curl_setopt($curlHandle, \CURLOPT_TIMEOUT, $httpTimeout);
}

$connectTimeout = $options->getHttpConnectTimeout();
if ($connectTimeout < 1.0) {
curl_setopt($curlHandle, \CURLOPT_CONNECTTIMEOUT_MS, $connectTimeout * 1000);
} else {
curl_setopt($curlHandle, \CURLOPT_CONNECTTIMEOUT, $connectTimeout);
}

$httpSslVerifyPeer = $options->getHttpSslVerifyPeer();
if (!$httpSslVerifyPeer) {
curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, false);
Expand Down
2 changes: 1 addition & 1 deletion src/Severity.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static function fromError(int $severity): self
return self::error();
case \E_NOTICE:
case \E_USER_NOTICE:
case \E_STRICT:
case 2048: // This is \E_STRICT which has been deprecated in PHP 8.4 so we should not reference it directly to prevent deprecation notices
return self::info();
default:
return self::error();
Expand Down
58 changes: 43 additions & 15 deletions tests/Serializer/AbstractSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,48 +442,64 @@ public function serializableCallableProvider(): array
$this->assertFileExists($filename);
$callableWithoutNamespaces = require $filename;

$prettyClosureNames = \PHP_VERSION_ID >= 80400;

return [
[
'callable' => function (array $param1) {
throw new \Exception('Don\'t even think about invoke me');
},
'expected' => 'Lambda ' . __NAMESPACE__ . '\\{closure} [array param1]',
'expected' => $prettyClosureNames
? 'Lambda {closure:' . __CLASS__ . '::' . __FUNCTION__ . '():%d} [array param1]'
: 'Lambda ' . __NAMESPACE__ . '\\{closure} [array param1]',
],
[
'callable' => function ($param1a) {
throw new \Exception('Don\'t even think about invoke me');
},
'expected' => 'Lambda ' . __NAMESPACE__ . '\\{closure} [mixed|null param1a]',
'expected' => $prettyClosureNames
? 'Lambda {closure:' . __CLASS__ . '::' . __FUNCTION__ . '():%d} [mixed|null param1a]'
: 'Lambda ' . __NAMESPACE__ . '\\{closure} [mixed|null param1a]',
],
[
'callable' => function (callable $param1c) {
throw new \Exception('Don\'t even think about invoke me');
},
'expected' => 'Lambda ' . __NAMESPACE__ . '\\{closure} [callable param1c]',
'expected' => $prettyClosureNames
? 'Lambda {closure:' . __CLASS__ . '::' . __FUNCTION__ . '():%d} [callable param1c]'
: 'Lambda ' . __NAMESPACE__ . '\\{closure} [callable param1c]',
],
[
'callable' => function (\stdClass $param1d) {
throw new \Exception('Don\'t even think about invoke me');
},
'expected' => 'Lambda ' . __NAMESPACE__ . '\\{closure} [stdClass param1d]',
'expected' => $prettyClosureNames
? 'Lambda {closure:' . __CLASS__ . '::' . __FUNCTION__ . '():%d} [stdClass param1d]'
: 'Lambda ' . __NAMESPACE__ . '\\{closure} [stdClass param1d]',
],
[
'callable' => function (?\stdClass $param1e = null) {
throw new \Exception('Don\'t even think about invoke me');
},
'expected' => 'Lambda ' . __NAMESPACE__ . '\\{closure} [stdClass|null [param1e]]',
'expected' => $prettyClosureNames
? 'Lambda {closure:' . __CLASS__ . '::' . __FUNCTION__ . '():%d} [stdClass|null [param1e]]'
: 'Lambda ' . __NAMESPACE__ . '\\{closure} [stdClass|null [param1e]]',
],
[
'callable' => function (array &$param1f) {
throw new \Exception('Don\'t even think about invoke me');
},
'expected' => 'Lambda ' . __NAMESPACE__ . '\\{closure} [array &param1f]',
'expected' => $prettyClosureNames
? 'Lambda {closure:' . __CLASS__ . '::' . __FUNCTION__ . '():%d} [array &param1f]'
: 'Lambda ' . __NAMESPACE__ . '\\{closure} [array &param1f]',
],
[
'callable' => function (?array &$param1g = null) {
throw new \Exception('Don\'t even think about invoke me');
},
'expected' => 'Lambda ' . __NAMESPACE__ . '\\{closure} [array|null [&param1g]]',
'expected' => $prettyClosureNames
? 'Lambda {closure:' . __CLASS__ . '::' . __FUNCTION__ . '():%d} [array|null [&param1g]]'
: 'Lambda ' . __NAMESPACE__ . '\\{closure} [array|null [&param1g]]',
],
[
'callable' => [$this, 'serializableCallableProvider'],
Expand All @@ -509,35 +525,47 @@ public function serializableCallableProvider(): array
'callable' => function (int $param1_70a) {
throw new \Exception('Don\'t even think about invoke me');
},
'expected' => 'Lambda ' . __NAMESPACE__ . '\\{closure} [int param1_70a]',
'expected' => $prettyClosureNames
? 'Lambda {closure:' . __CLASS__ . '::' . __FUNCTION__ . '():%d} [int param1_70a]'
: 'Lambda ' . __NAMESPACE__ . '\\{closure} [int param1_70a]',
],
[
'callable' => function (&$param): int {
return (int) $param;
},
'expected' => 'Lambda int ' . __NAMESPACE__ . '\\{closure} [mixed|null &param]',
'expected' => $prettyClosureNames
? 'Lambda int {closure:' . __CLASS__ . '::' . __FUNCTION__ . '():%d} [mixed|null &param]'
: 'Lambda int ' . __NAMESPACE__ . '\\{closure} [mixed|null &param]',
],
[
'callable' => function (int $param): ?int {
throw new \Exception('Don\'t even think about invoke me');
},
'expected' => 'Lambda int ' . __NAMESPACE__ . '\\{closure} [int param]',
'expected' => $prettyClosureNames
? 'Lambda int {closure:' . __CLASS__ . '::' . __FUNCTION__ . '():%d} [int param]'
: 'Lambda int ' . __NAMESPACE__ . '\\{closure} [int param]',
],
[
'callable' => function (?int $param1_70b) {
throw new \Exception('Don\'t even think about invoke me');
},
'expected' => 'Lambda ' . __NAMESPACE__ . '\\{closure} [int|null param1_70b]',
'expected' => $prettyClosureNames
? 'Lambda {closure:' . __CLASS__ . '::' . __FUNCTION__ . '():%d} [int|null param1_70b]'
: 'Lambda ' . __NAMESPACE__ . '\\{closure} [int|null param1_70b]',
],
[
'callable' => function (?int $param1_70c): void {
throw new \Exception('Don\'t even think about invoke me');
},
'expected' => 'Lambda void ' . __NAMESPACE__ . '\\{closure} [int|null param1_70c]',
'expected' => $prettyClosureNames
? 'Lambda void {closure:' . __CLASS__ . '::' . __FUNCTION__ . '():%d} [int|null param1_70c]'
: 'Lambda void ' . __NAMESPACE__ . '\\{closure} [int|null param1_70c]',
],
[
'callable' => $callableWithoutNamespaces,
'expected' => 'Lambda void {closure} [int|null param1_70ns]',
'expected' => $prettyClosureNames
? 'Lambda void {closure:%s:%d} [int|null param1_70ns]'
: 'Lambda void {closure} [int|null param1_70ns]',
],
[
// This is (a example of) a PHP provided function that is technically callable but we want to ignore that because it causes more false positives than it helps
Expand All @@ -559,11 +587,11 @@ public function testSerializeCallable($callable, string $expected): void
$serializer = $this->createSerializer();
$actual = $this->invokeSerialization($serializer, $callable);

$this->assertSame($expected, $actual);
$this->assertStringMatchesFormat($expected, $actual);

$actual = $this->invokeSerialization($serializer, [$callable]);

$this->assertSame([$expected], $actual);
$this->assertStringMatchesFormat($expected, $actual[0]);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion tests/SeverityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public static function levelsDataProvider(): array
// Info
[\E_NOTICE, 'info'],
[\E_USER_NOTICE, 'info'],
[\E_STRICT, 'info'],
// This is \E_STRICT which has been deprecated in PHP 8.4 so we should not reference it directly to prevent deprecation notices
[2048, 'info'],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ trigger_error('Error thrown', E_USER_WARNING);

echo 'Triggering E_USER_ERROR error (unsilenceable on PHP8)' . PHP_EOL;

trigger_error('Error thrown', E_USER_ERROR);
if (PHP_VERSION_ID >= 80400) {
// Silence a deprecation notice on PHP 8.4
// https://wiki.php.net/rfc/deprecations_php_8_4#deprecate_passing_e_user_error_to_trigger_error
@trigger_error('Error thrown', E_USER_ERROR);
} else {
trigger_error('Error thrown', E_USER_ERROR);
}
?>
--EXPECT--
Triggering E_USER_NOTICE error
Expand Down

0 comments on commit 402c044

Please sign in to comment.