kiwilan / php-audio

PHP package to parse and update audio files metadata, with JamesHeinrich/getID3.
MIT License
15 stars 0 forks source link

[Bug]: Call to a member function format() on false in AudioCore.php:543 #29

Closed panVag closed 5 months ago

panVag commented 5 months ago

What happened?

When trying to parse a specific date I get an error.

[2024-06-03 05:51:03] production.ERROR: Call to a member function format() on false {"exception":"[object] (Error(code: 0): Call to a member function format() on false at /app/vendor/kiwilan/php-audio/src/Models/AudioCore.php:543)
[stacktrace]
#0 /app/vendor/kiwilan/php-audio/src/Audio.php(420): Kiwilan\\Audio\\Models\\AudioCore::fromQuicktime()
#1 /app/vendor/kiwilan/php-audio/src/Audio.php(102): Kiwilan\\Audio\\Audio->parse()

How to reproduce the bug

Try a date that doesn't match the format specified in https://github.com/kiwilan/php-audio/blob/main/src/Models/AudioCore.php#L543

I get this with dates that don't include time like 2024-01-01.

The following snippet can simulate the issue:

$creation_date = '2024-01-01';
$creation_date = date_create_from_format('Y-m-d\TH:i:s\Z', $creation_date);
var_dump($creation_date?->format('Y-m-d\TH:i:s\Z'));

Package Version

v3.0.06

PHP Version

8.3

Which operating systems does with happen with?

Linux

Notes

The date_create_from_format() will return false when it can't parse the date according to the manual. In which case the null safe operator will not work because it's a boolean. I think this is not intended.

Up to now it only happened with quicktime format. Haven't dig the code in order to figure out why is that, so it might make sense to check if there are other snippets that could cause the same issue.