Skip to content

Commit

Permalink
perf: add PHP 8.4 to test matrix (#218)
Browse files Browse the repository at this point in the history
* Update honeybadger-php to play nice with PHP 8.4

* Update missing files

* ci: add 8.4 to test matrix and fix tests

* ci: do not prefer lowest

* chore: remove changelog entry

It will be added by the release action.

---------

Co-authored-by: PuLLi <[email protected]>
  • Loading branch information
subzero10 and the-pulli authored Dec 9, 2024
1 parent 3f84e54 commit de5747f
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ jobs:
strategy:
matrix:
composer-flags: ["--prefer-stable", "--prefer-lowest"]
php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2']
php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.4']
exclude:
- {php-versions: '8.1', composer-flags: "--prefer-lowest"}
- {php-versions: '8.2', composer-flags: "--prefer-lowest"}
- {php-versions: '8.4', composer-flags: "--prefer-lowest"}
name: PHP ${{ matrix.php-versions }} Tests (${{ matrix.composer-flags }})
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion src/CheckInsClientWithErrorHandling.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CheckInsClientWithErrorHandling
*/
private $baseClient;

public function __construct(Config $config, Client $httpClient = null)
public function __construct(Config $config, ?Client $httpClient = null)
{
$this->config = $config;
$this->baseClient = new CheckInsClient($config, $httpClient);
Expand Down
2 changes: 1 addition & 1 deletion src/CheckInsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CheckInsManager implements SyncCheckIns {
* @param array $config
* @param CheckInsClient|null $client
*/
public function __construct(array $config, CheckInsClient $client = null) {
public function __construct(array $config, ?CheckInsClient $client = null) {
$this->config = new Config($config);
$this->client = $client ?? new CheckInsClient($this->config);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Contracts/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ abstract class ApiClient {

/**
* @param Config $config
* @param Client|null $httpClient
* @param ?Client $httpClient
*/
public function __construct(Config $config, Client $httpClient = null) {
public function __construct(Config $config, ?Client $httpClient = null) {
$this->config = $config;
$this->client = $httpClient ?? $this->makeClient();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Contracts/Reporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ interface Reporter
{
/**
* @param \Throwable $throwable
* @param \Symfony\Component\HttpFoundation\Request $request
* @param ?\Symfony\Component\HttpFoundation\Request $request
* @param array $additionalParams
* @return array
*
* @throws \Honeybadger\Exceptions\ServiceException
*/
public function notify(Throwable $throwable, FoundationRequest $request = null, array $additionalParams = []): array;
public function notify(Throwable $throwable, ?FoundationRequest $request = null, array $additionalParams = []): array;

/**
* @param array $payload
Expand Down Expand Up @@ -89,7 +89,7 @@ public function clear(): self;
*
* @return void
*/
public function event($eventTypeOrPayload, array $payload = null): void;
public function event($eventTypeOrPayload, ?array $payload = null): void;

/**
* Flush all events from the queue.
Expand Down
2 changes: 1 addition & 1 deletion src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Environment
*/
protected $server = [];

public function __construct(array $server = null, array $env = null)
public function __construct(?array $server = null, ?array $env = null)
{
$this->server = array_merge(
$server ?? $_SERVER,
Expand Down
8 changes: 4 additions & 4 deletions src/ExceptionNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public function __construct(Config $config, Repository $context, Breadcrumbs $br

/**
* @param \Throwable $e
* @param \Symfony\Component\HttpFoundation\Request $request
* @param ?\Symfony\Component\HttpFoundation\Request $request
* @param array $additionalParams
* @return array
*/
public function make(Throwable $e, FoundationRequest $request = null, array $additionalParams = []): array
public function make(Throwable $e, ?FoundationRequest $request = null, array $additionalParams = []): array
{
$this->throwable = $e;
$this->backtrace = $this->makeBacktrace();
Expand Down Expand Up @@ -138,10 +138,10 @@ private function makeBacktrace(): BacktraceFactory
}

/**
* @param \Symfony\Component\HttpFoundation\Request $request
* @param ?\Symfony\Component\HttpFoundation\Request $request
* @return \Honeybadger\Request
*/
private function makeRequest(FoundationRequest $request = null): Request
private function makeRequest(?FoundationRequest $request = null): Request
{
return (new Request($request))
->filterKeys($this->config['request']['filter']);
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/ServiceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function unexpectedResponseCode(int $code): self
* @param Throwable|null $e
* @return self
*/
public static function generic(Throwable $e = null): self
public static function generic(?Throwable $e = null): self
{
$message = $e
? 'There was an error sending the payload to Honeybadger: '.$e->getMessage()
Expand Down
2 changes: 1 addition & 1 deletion src/Handlers/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function register(): void
$this->previousHandler = set_error_handler([$this, 'handle']);
}

public function handle(int $level, string $error, string $file = null, int $line = null)
public function handle(int $level, string $error, ?string $file = null, ?int $line = null)
{
// When the @ operator is used, it temporarily changes `error_reporting()`'s return value
// to reflect what error types should be reported. This means we should get 0 (no errors).
Expand Down
6 changes: 3 additions & 3 deletions src/Honeybadger.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Honeybadger implements Reporter
*/
protected $events;

public function __construct(array $config = [], Client $client = null, BulkEventDispatcher $eventsDispatcher = null)
public function __construct(array $config = [], ?Client $client = null, ?BulkEventDispatcher $eventsDispatcher = null)
{
$this->config = new Config($config);

Expand All @@ -84,7 +84,7 @@ public function __construct(array $config = [], Client $client = null, BulkEvent
/**
* {@inheritdoc}
*/
public function notify(Throwable $throwable, FoundationRequest $request = null, array $additionalParams = []): array
public function notify(Throwable $throwable, ?FoundationRequest $request = null, array $additionalParams = []): array
{
if (! $this->shouldReport($throwable)) {
return [];
Expand Down Expand Up @@ -223,7 +223,7 @@ public function clear(): Reporter
/**
* {@inheritdoc}
*/
public function event($eventTypeOrPayload, array $payload = null): void
public function event($eventTypeOrPayload, ?array $payload = null): void
{
if (empty($this->config['api_key']) || ! $this->config['events']['enabled']) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class Request
protected $request;

/**
* @param \Symfony\Component\HttpFoundation\Request $request
* @param ?\Symfony\Component\HttpFoundation\Request $request
* @param array $options
*/
public function __construct(FoundationRequest $request = null)
public function __construct(?FoundationRequest $request = null)
{
$this->request = $request ?? FoundationRequest::createFromGlobals();

Expand Down
18 changes: 14 additions & 4 deletions tests/BacktraceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ public function it_correctly_formats_annonymous_functions()
$backtrace = (new BacktraceFactory($e, new Config))->trace();
}

$this->assertEquals('Honeybadger\Tests\{closure}', $backtrace[0]['method']);
// if php version is 8.4.0 or higher, then we need to check for a more specific closure name
if (version_compare(PHP_VERSION, '8.4.0', '>=')) {
$this->assertEquals('{closure:Honeybadger\Tests\BacktraceFactoryTest::it_correctly_formats_annonymous_functions():33}', $backtrace[0]['method']);
} else {
$this->assertEquals('Honeybadger\Tests\{closure}', $backtrace[0]['method']);
}
$this->assertEquals(['bar'], $backtrace[0]['args']);
}

Expand All @@ -62,7 +67,7 @@ function throwTestException()
}

/** @test */
public function bactraces_send_class()
public function backtraces_send_class()
{
try {
throw new Exception('test');
Expand All @@ -74,7 +79,7 @@ public function bactraces_send_class()
}

/** @test */
public function bactraces_send_type()
public function backtraces_send_type()
{
try {
throw new Exception('test');
Expand Down Expand Up @@ -153,7 +158,12 @@ public function args_with_object_should_be_literals()
$backtrace = (new BacktraceFactory($e, new Config))->trace();
}

$this->assertEquals('Honeybadger\Tests\{closure}', $backtrace[0]['method']);
// if php version is 8.4.0 or higher, then we need to check for a more specific closure name
if (version_compare(PHP_VERSION, '8.4.0', '>=')) {
$this->assertEquals('{closure:Honeybadger\Tests\BacktraceFactoryTest::args_with_object_should_be_literals():151}', $backtrace[0]['method']);
} else {
$this->assertEquals('Honeybadger\Tests\{closure}', $backtrace[0]['method']);
}
$this->assertEquals(['bar', '[LITERAL]Object('.TestClass::class.')'], $backtrace[0]['args']);
}
}
Expand Down

0 comments on commit de5747f

Please sign in to comment.