diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3040e0a..b84ac9f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: operating-system: [ ubuntu-latest ] - php-versions: [ '7.3', '7.4', '8.0', '8.1' ] + php-versions: [ '7.3', '7.4', '8.0', '8.1', '8.2' ] name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} steps: @@ -34,14 +34,9 @@ jobs: - name: Validate composer.json and composer.lock run: composer validate - - name: Install dependencies for PHP 7 - if: matrix.php-versions < '8.0' + - name: Install dependencies for PHP run: composer update --prefer-dist --no-progress - - name: Install dependencies for PHP 8 - if: matrix.php-versions >= '8.0' - run: composer update --prefer-dist --no-progress --ignore-platform-req=php - - name: Run test suite run: composer check env: diff --git a/src/AudioType.php b/src/AudioType.php index ed8a56e..f298f5d 100644 --- a/src/AudioType.php +++ b/src/AudioType.php @@ -2,8 +2,6 @@ namespace Selective\AudioType; -use InvalidArgumentException; - /** * Audio type value object. */ @@ -28,11 +26,11 @@ final class AudioType public function __construct(string $format, string $mime) { if (empty($format)) { - throw new InvalidArgumentException(sprintf('Invalid type: %s', $format)); + throw new \InvalidArgumentException(sprintf('Invalid type: %s', $format)); } if (empty($mime)) { - throw new InvalidArgumentException(sprintf('Invalid mime type: %s', $format)); + throw new \InvalidArgumentException(sprintf('Invalid mime type: %s', $format)); } $this->format = $format; @@ -68,7 +66,7 @@ public function getMimeType(): string */ public function equals(AudioType $other): bool { - return $this->format === $other->format && - $this->mime === $other->mime; + return $this->format === $other->format + && $this->mime === $other->mime; } } diff --git a/src/AudioTypeDetector.php b/src/AudioTypeDetector.php index a23d73b..06466ed 100644 --- a/src/AudioTypeDetector.php +++ b/src/AudioTypeDetector.php @@ -5,7 +5,6 @@ use Selective\AudioType\Detector\AudioDetectorInterface; use Selective\AudioType\Exception\AudioTypeDetectorException; use Selective\AudioType\Provider\ProviderInterface; -use SplFileObject; /** * Audio type detection. @@ -44,13 +43,13 @@ public function addProvider(ProviderInterface $provider): void /** * Detect audio type. * - * @param SplFileObject $file The audio file + * @param \SplFileObject $file The audio file * * @throws AudioTypeDetectorException * * @return AudioType The audio type */ - public function getAudioTypeFromFile(SplFileObject $file): AudioType + public function getAudioTypeFromFile(\SplFileObject $file): AudioType { $type = $this->detectFile($file); @@ -64,11 +63,11 @@ public function getAudioTypeFromFile(SplFileObject $file): AudioType /** * Reads and returns the type of the audio file. * - * @param SplFileObject $file The audio file + * @param \SplFileObject $file The audio file * * @return AudioType|null */ - private function detectFile(SplFileObject $file): ?AudioType + private function detectFile(\SplFileObject $file): ?AudioType { foreach ($this->detectors as $detector) { $file->rewind(); diff --git a/src/Detector/AacDetector.php b/src/Detector/AacDetector.php index ac36140..3d99aea 100644 --- a/src/Detector/AacDetector.php +++ b/src/Detector/AacDetector.php @@ -5,7 +5,6 @@ use Selective\AudioType\AudioFormat; use Selective\AudioType\AudioMimeType; use Selective\AudioType\AudioType; -use SplFileObject; /** * Detector. @@ -15,11 +14,11 @@ final class AacDetector implements AudioDetectorInterface /** * Detect AAC audio file format. * - * @param SplFileObject $file The audio file + * @param \SplFileObject $file The audio file * * @return AudioType|null The audio type */ - public function detect(SplFileObject $file): ?AudioType + public function detect(\SplFileObject $file): ?AudioType { // Skip 8 bytes $file->fread(8); diff --git a/src/Detector/AiffDetector.php b/src/Detector/AiffDetector.php index fc6959b..23ca01e 100644 --- a/src/Detector/AiffDetector.php +++ b/src/Detector/AiffDetector.php @@ -5,7 +5,6 @@ use Selective\AudioType\AudioFormat; use Selective\AudioType\AudioMimeType; use Selective\AudioType\AudioType; -use SplFileObject; /** * Detector. @@ -15,11 +14,11 @@ final class AiffDetector implements AudioDetectorInterface /** * Detect AIFF/AIFC soundfile format. * - * @param SplFileObject $file The audio file + * @param \SplFileObject $file The audio file * * @return AudioType|null The audio type */ - public function detect(SplFileObject $file): ?AudioType + public function detect(\SplFileObject $file): ?AudioType { $ckID = (string)$file->fread(4); diff --git a/src/Detector/AuDetector.php b/src/Detector/AuDetector.php index 0570daf..82ebd92 100644 --- a/src/Detector/AuDetector.php +++ b/src/Detector/AuDetector.php @@ -5,7 +5,6 @@ use Selective\AudioType\AudioFormat; use Selective\AudioType\AudioMimeType; use Selective\AudioType\AudioType; -use SplFileObject; /** * Detector. @@ -15,11 +14,11 @@ final class AuDetector implements AudioDetectorInterface /** * Detect AU audio file. * - * @param SplFileObject $file The audio file + * @param \SplFileObject $file The audio file * * @return AudioType|null The audio type */ - public function detect(SplFileObject $file): ?AudioType + public function detect(\SplFileObject $file): ?AudioType { $bytes = (string)$file->fread(4); diff --git a/src/Detector/AudioDetectorInterface.php b/src/Detector/AudioDetectorInterface.php index ff8aca8..300353e 100644 --- a/src/Detector/AudioDetectorInterface.php +++ b/src/Detector/AudioDetectorInterface.php @@ -3,7 +3,6 @@ namespace Selective\AudioType\Detector; use Selective\AudioType\AudioType; -use SplFileObject; /** * Detector. @@ -13,9 +12,9 @@ interface AudioDetectorInterface /** * Detect. * - * @param SplFileObject $file The file + * @param \SplFileObject $file The file * * @return AudioType|null The audio type */ - public function detect(SplFileObject $file): ?AudioType; + public function detect(\SplFileObject $file): ?AudioType; } diff --git a/src/Detector/CafDetector.php b/src/Detector/CafDetector.php index 00ef40e..2f28851 100644 --- a/src/Detector/CafDetector.php +++ b/src/Detector/CafDetector.php @@ -5,7 +5,6 @@ use Selective\AudioType\AudioFormat; use Selective\AudioType\AudioMimeType; use Selective\AudioType\AudioType; -use SplFileObject; /** * Detector. @@ -15,11 +14,11 @@ final class CafDetector implements AudioDetectorInterface /** * Detects CAF (Apple Core Audio File). * - * @param SplFileObject $file The file + * @param \SplFileObject $file The file * * @return AudioType|null The audio type */ - public function detect(SplFileObject $file): ?AudioType + public function detect(\SplFileObject $file): ?AudioType { return (string)$file->fread(4) === 'caff' ? new AudioType( AudioFormat::CAF, diff --git a/src/Detector/FlacDetector.php b/src/Detector/FlacDetector.php index b8553a0..ccc6d08 100644 --- a/src/Detector/FlacDetector.php +++ b/src/Detector/FlacDetector.php @@ -5,7 +5,6 @@ use Selective\AudioType\AudioFormat; use Selective\AudioType\AudioMimeType; use Selective\AudioType\AudioType; -use SplFileObject; /** * Detector. @@ -15,11 +14,11 @@ final class FlacDetector implements AudioDetectorInterface /** * Detect FLAC soundfile format. * - * @param SplFileObject $file The audio file + * @param \SplFileObject $file The audio file * * @return AudioType|null The audio type */ - public function detect(SplFileObject $file): ?AudioType + public function detect(\SplFileObject $file): ?AudioType { // Signature bytes $signature = (string)$file->fread(4); diff --git a/src/Detector/MidiDetector.php b/src/Detector/MidiDetector.php index 3a9db0b..c804c19 100644 --- a/src/Detector/MidiDetector.php +++ b/src/Detector/MidiDetector.php @@ -5,7 +5,6 @@ use Selective\AudioType\AudioFormat; use Selective\AudioType\AudioMimeType; use Selective\AudioType\AudioType; -use SplFileObject; /** * Detector. @@ -15,11 +14,11 @@ final class MidiDetector implements AudioDetectorInterface /** * Detects MIDI format. * - * @param SplFileObject $file The audio file + * @param \SplFileObject $file The audio file * * @return AudioType|null The audio type */ - public function detect(SplFileObject $file): ?AudioType + public function detect(\SplFileObject $file): ?AudioType { $chunkType = (string)$file->fread(4); diff --git a/src/Detector/MkaDetector.php b/src/Detector/MkaDetector.php index f4aa700..8abaec2 100644 --- a/src/Detector/MkaDetector.php +++ b/src/Detector/MkaDetector.php @@ -5,7 +5,6 @@ use Selective\AudioType\AudioFormat; use Selective\AudioType\AudioMimeType; use Selective\AudioType\AudioType; -use SplFileObject; /** * Detector. @@ -15,11 +14,11 @@ final class MkaDetector implements AudioDetectorInterface /** * Detect MKA (audio-only Matroska) container. * - * @param SplFileObject $file The audio file + * @param \SplFileObject $file The audio file * * @return AudioType|null The audio type */ - public function detect(SplFileObject $file): ?AudioType + public function detect(\SplFileObject $file): ?AudioType { $bytes = bin2hex((string)$file->fread(4)); $containedMatroska = strpos((string)$file->fread(46), 'matroska') !== false; diff --git a/src/Detector/Mp3Detector.php b/src/Detector/Mp3Detector.php index 43352ac..a710bd4 100644 --- a/src/Detector/Mp3Detector.php +++ b/src/Detector/Mp3Detector.php @@ -5,7 +5,6 @@ use Selective\AudioType\AudioFormat; use Selective\AudioType\AudioMimeType; use Selective\AudioType\AudioType; -use SplFileObject; /** * Detector. @@ -15,11 +14,11 @@ final class Mp3Detector implements AudioDetectorInterface /** * Detect MP3 (MPEG-1 Audio Layer 3 (MP3) audio file) format. * - * @param SplFileObject $file The audio file + * @param \SplFileObject $file The audio file * * @return AudioType|null The audio type */ - public function detect(SplFileObject $file): ?AudioType + public function detect(\SplFileObject $file): ?AudioType { // MP3 file with an ID3v2 container $hasId3v2Container = (string)$file->fread(3) === 'ID3'; diff --git a/src/Detector/OgaDetector.php b/src/Detector/OgaDetector.php index 5083355..bb6c18c 100644 --- a/src/Detector/OgaDetector.php +++ b/src/Detector/OgaDetector.php @@ -5,7 +5,6 @@ use Selective\AudioType\AudioFormat; use Selective\AudioType\AudioMimeType; use Selective\AudioType\AudioType; -use SplFileObject; /** * Detector. @@ -15,11 +14,11 @@ final class OgaDetector implements AudioDetectorInterface /** * Detect FLAC soundfile format. * - * @param SplFileObject $file The audio file + * @param \SplFileObject $file The audio file * * @return AudioType|null The audio type */ - public function detect(SplFileObject $file): ?AudioType + public function detect(\SplFileObject $file): ?AudioType { $bytes = (string)$file->fread(4); diff --git a/src/Detector/RealAudioDetector.php b/src/Detector/RealAudioDetector.php index 1cfe1c4..4d35939 100644 --- a/src/Detector/RealAudioDetector.php +++ b/src/Detector/RealAudioDetector.php @@ -5,7 +5,6 @@ use Selective\AudioType\AudioFormat; use Selective\AudioType\AudioMimeType; use Selective\AudioType\AudioType; -use SplFileObject; /** * Detector. @@ -15,11 +14,11 @@ final class RealAudioDetector implements AudioDetectorInterface /** * Detects RealAudio. * - * @param SplFileObject $file The file + * @param \SplFileObject $file The file * * @return AudioType|null The audio type */ - public function detect(SplFileObject $file): ?AudioType + public function detect(\SplFileObject $file): ?AudioType { return (string)$file->fread(3) === '.ra' ? new AudioType( AudioFormat::RA, diff --git a/src/Detector/RmiDetector.php b/src/Detector/RmiDetector.php index 8d64ee2..ab56a56 100644 --- a/src/Detector/RmiDetector.php +++ b/src/Detector/RmiDetector.php @@ -5,7 +5,6 @@ use Selective\AudioType\AudioFormat; use Selective\AudioType\AudioMimeType; use Selective\AudioType\AudioType; -use SplFileObject; /** * Detector. @@ -15,11 +14,11 @@ final class RmiDetector implements AudioDetectorInterface /** * Detect RMI, RIFF-MIDI audio format. * - * @param SplFileObject $file The audio file + * @param \SplFileObject $file The audio file * * @return AudioType|null The audio type */ - public function detect(SplFileObject $file): ?AudioType + public function detect(\SplFileObject $file): ?AudioType { $magicNumber = (string)$file->fread(4); $header = (string)$file->fread(25); diff --git a/src/Detector/WavDetector.php b/src/Detector/WavDetector.php index dba9919..4dcbaac 100644 --- a/src/Detector/WavDetector.php +++ b/src/Detector/WavDetector.php @@ -5,7 +5,6 @@ use Selective\AudioType\AudioFormat; use Selective\AudioType\AudioMimeType; use Selective\AudioType\AudioType; -use SplFileObject; /** * Detector. @@ -17,11 +16,11 @@ final class WavDetector implements AudioDetectorInterface * * http://soundfile.sapp.org/doc/WaveFormat/ * - * @param SplFileObject $file The audio file + * @param \SplFileObject $file The audio file * * @return AudioType|null The audio type */ - public function detect(SplFileObject $file): ?AudioType + public function detect(\SplFileObject $file): ?AudioType { $chunkId = (string)$file->fread(4); diff --git a/src/Detector/WebmDetector.php b/src/Detector/WebmDetector.php index 127ec8e..1ad3b9c 100644 --- a/src/Detector/WebmDetector.php +++ b/src/Detector/WebmDetector.php @@ -5,7 +5,6 @@ use Selective\AudioType\AudioFormat; use Selective\AudioType\AudioMimeType; use Selective\AudioType\AudioType; -use SplFileObject; /** * Detector. @@ -20,11 +19,11 @@ final class WebmDetector implements AudioDetectorInterface * * To generate a webm audio file, run: ffmpeg.exe -i test.mp3 -vn test.webm * - * @param SplFileObject $file The audio file + * @param \SplFileObject $file The audio file * * @return AudioType|null The audio type */ - public function detect(SplFileObject $file): ?AudioType + public function detect(\SplFileObject $file): ?AudioType { $ebmlHeader = bin2hex((string)$file->fread(4)); $containedWebM = strpos((string)$file->fread(40), 'webm') !== false; diff --git a/src/Detector/WmaDetector.php b/src/Detector/WmaDetector.php index 6b98ede..be27b3f 100644 --- a/src/Detector/WmaDetector.php +++ b/src/Detector/WmaDetector.php @@ -5,7 +5,6 @@ use Selective\AudioType\AudioFormat; use Selective\AudioType\AudioMimeType; use Selective\AudioType\AudioType; -use SplFileObject; /** * Detector. @@ -15,11 +14,11 @@ final class WmaDetector implements AudioDetectorInterface /** * Detect WMA audio format. * - * @param SplFileObject $file The audio file + * @param \SplFileObject $file The audio file * * @return AudioType|null The audio type */ - public function detect(SplFileObject $file): ?AudioType + public function detect(\SplFileObject $file): ?AudioType { $asfMagicNumber = bin2hex((string)$file->fread(4)); diff --git a/src/Exception/AudioTypeDetectorException.php b/src/Exception/AudioTypeDetectorException.php index bc129a7..1efa625 100644 --- a/src/Exception/AudioTypeDetectorException.php +++ b/src/Exception/AudioTypeDetectorException.php @@ -2,11 +2,9 @@ namespace Selective\AudioType\Exception; -use RuntimeException; - /** * Exception. */ -final class AudioTypeDetectorException extends RuntimeException +final class AudioTypeDetectorException extends \RuntimeException { } diff --git a/src/Exception/MimeTypeNotFoundException.php b/src/Exception/MimeTypeNotFoundException.php index 1265ff6..cd56836 100644 --- a/src/Exception/MimeTypeNotFoundException.php +++ b/src/Exception/MimeTypeNotFoundException.php @@ -2,11 +2,9 @@ namespace Selective\AudioType\Exception; -use RuntimeException; - /** * Mime type not found exception. */ -final class MimeTypeNotFoundException extends RuntimeException +final class MimeTypeNotFoundException extends \RuntimeException { } diff --git a/tests/AudioTypeDetectorTest.php b/tests/AudioTypeDetectorTest.php index d29a7c5..98be196 100644 --- a/tests/AudioTypeDetectorTest.php +++ b/tests/AudioTypeDetectorTest.php @@ -9,8 +9,6 @@ use Selective\AudioType\AudioTypeDetector; use Selective\AudioType\Exception\AudioTypeDetectorException; use Selective\AudioType\Provider\DefaultAudioProvider; -use SplFileObject; -use SplTempFileObject; /** * Test. @@ -47,7 +45,7 @@ public function testGetAudioTypeFromFile(string $file, string $format, string $m $this->assertFileExists($file); $detector = $this->createDetector(); - $file = new SplFileObject($file); + $file = new \SplFileObject($file); $actual = $detector->getAudioTypeFromFile($file); $this->assertSame($format, $actual->getFormat()); @@ -92,7 +90,7 @@ public function testGetAudioTypeWithUnknownFormat(): void $imageTypeDetector = new AudioTypeDetector(); - $image = new SplTempFileObject(); + $image = new \SplTempFileObject(); $image->fwrite('temp'); $imageTypeDetector->getAudioTypeFromFile($image); diff --git a/tests/AudioTypeTest.php b/tests/AudioTypeTest.php index 64cc6c7..7e83be9 100644 --- a/tests/AudioTypeTest.php +++ b/tests/AudioTypeTest.php @@ -2,7 +2,6 @@ namespace Selective\AudioType\Test; -use InvalidArgumentException; use PHPUnit\Framework\TestCase; use Selective\AudioType\AudioFormat; use Selective\AudioType\AudioMimeType; @@ -33,7 +32,7 @@ public function testCreateInstance(): void */ public function testCreateInstanceWithError(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); new AudioType('', ''); } @@ -44,7 +43,7 @@ public function testCreateInstanceWithError(): void */ public function testCreateInstanceWithError2(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); new AudioType(AudioFormat::WAV, ''); } }