Skip to content

Commit

Permalink
Fix PHP 8.1 compatibility (#361)
Browse files Browse the repository at this point in the history
The tests were failing on PHP 8.1 due to a `file_exists(): Passing null to parameter #1 ($filename) of type string is deprecated` notice coming from the `JobsRepository::dumpJsonFile()` method.

While it would probably be unlikely for this error condition ever to be hit in a real life situation, it is something which is likely to happen in the tests and well, a little defensive coding goes a long way.

With this fix in place, the tests now pass on PHP 8.1 and PHP 8.2 and compatibility with both can be declared. 🎉

Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
  • Loading branch information
jrfnl and jrfnl committed Jul 15, 2023
1 parent 93c4651 commit e2556b3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Bundle/CoverallsBundle/Repository/JobsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ protected function dumpJsonFile()

$this->api->dumpJsonFile();

$filesize = number_format(filesize($jsonPath) / 1024, 2); // kB
$filesize = 0;
if (\is_string($jsonPath) && file_exists($jsonPath)) {
$filesize = number_format(filesize($jsonPath) / 1024, 2); // kB
}
$this->logger->info(sprintf('File size: <info>%s</info> kB', $filesize));

return $this;
Expand Down

0 comments on commit e2556b3

Please sign in to comment.