From ac8302f4be9a62d3a3fc28fd05e3a9761adbf00e Mon Sep 17 00:00:00 2001 From: Gemorroj Date: Mon, 29 Dec 2025 20:06:33 +0300 Subject: [PATCH] fix php warnings --- .gitignore | 4 ++-- composer.json | 2 +- phpunit.xml.dist | 2 +- src/PhpTabs/Music/Scale.php | 2 +- src/PhpTabs/Music/Song.php | 4 ++-- src/PhpTabs/PhpTabs.php | 5 +++-- .../Reader/GuitarPro/GuitarPro3Reader.php | 7 +------ .../Reader/GuitarPro/GuitarPro4Reader.php | 7 +------ .../Reader/GuitarPro/GuitarPro5Reader.php | 5 ----- .../Reader/GuitarPro/GuitarProReaderBase.php | 5 +++++ .../Reader/GuitarPro/Helper/GuitarPro3Track.php | 2 +- .../Reader/GuitarPro/Helper/GuitarPro4Track.php | 2 +- .../Reader/GuitarPro/Helper/GuitarPro5Track.php | 2 +- src/PhpTabs/Reader/Midi/MidiAdjuster.php | 2 +- src/PhpTabs/Reader/Midi/MidiReader.php | 17 ++++++++++++++++- src/PhpTabs/Renderer/Ascii/AsciiBase.php | 6 +++--- src/PhpTabs/Writer/Midi/MidiSequenceParser.php | 1 - src/PhpTabs/Writer/Midi/MidiWriter.php | 2 +- 18 files changed, 41 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index 0fb1424..a6a47d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /vendor -/cache +/.phpunit.cache /build - +composer.lock diff --git a/composer.json b/composer.json index e5881f3..885d3d7 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } }, "require-dev": { - "phpunit/phpunit": "*" + "phpunit/phpunit": "<12" }, "config": { } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2847f90..400218e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,5 @@ - + diff --git a/src/PhpTabs/Music/Scale.php b/src/PhpTabs/Music/Scale.php index 2f38a57..b1af0ef 100644 --- a/src/PhpTabs/Music/Scale.php +++ b/src/PhpTabs/Music/Scale.php @@ -40,7 +40,7 @@ public function setNote(int $note, bool $on): void $this->notes[$note] = $on; } - public function getNote(int $note): int + public function getNote(int $note): bool { return $this->notes[($note + 12 - $this->key) % 12]; } diff --git a/src/PhpTabs/Music/Song.php b/src/PhpTabs/Music/Song.php index d545217..c3da3ad 100644 --- a/src/PhpTabs/Music/Song.php +++ b/src/PhpTabs/Music/Song.php @@ -20,7 +20,7 @@ final class Song extends SongBase /** * Get the list of instruments * - * @return array> + * @return array */ public function getInstruments(): array { @@ -52,7 +52,7 @@ public function countInstruments(): int /** * Gets an instrument by channelId * - * @return array> + * @return array{id: int, name: string}|null */ public function getInstrument(int $index): ?array { diff --git a/src/PhpTabs/PhpTabs.php b/src/PhpTabs/PhpTabs.php index 7de8da7..113a6ca 100644 --- a/src/PhpTabs/PhpTabs.php +++ b/src/PhpTabs/PhpTabs.php @@ -85,9 +85,10 @@ public function setTablature(Tablature $tablature): self public function fromArray(array $data): self { $importer = new Importer($data); + $tabulature = new Tablature(); + $tabulature->setSong($importer->getSong()); - $this->setTablature(new Tablature()) - ->setSong($importer->getSong()); + $this->setTablature($tabulature); return $this; } diff --git a/src/PhpTabs/Reader/GuitarPro/GuitarPro3Reader.php b/src/PhpTabs/Reader/GuitarPro/GuitarPro3Reader.php index 9deda5a..768173f 100644 --- a/src/PhpTabs/Reader/GuitarPro/GuitarPro3Reader.php +++ b/src/PhpTabs/Reader/GuitarPro/GuitarPro3Reader.php @@ -37,11 +37,6 @@ final class GuitarPro3Reader extends GuitarProReaderBase */ protected $tripletFeel; - /** - * @var int - */ - protected $keySignature; - /** * @param \PhpTabs\Component\InputStream $file An input file to read */ @@ -135,7 +130,7 @@ private function readMeasureHeaders(Song $song, int $count): void /** * Loops on tracks to read * - * @param array $channels + * @param array<\PhpTabs\Music\Channel> $channels */ private function readTracks(Song $song, int $count, array $channels): void { diff --git a/src/PhpTabs/Reader/GuitarPro/GuitarPro4Reader.php b/src/PhpTabs/Reader/GuitarPro/GuitarPro4Reader.php index a1b4ea6..f273123 100644 --- a/src/PhpTabs/Reader/GuitarPro/GuitarPro4Reader.php +++ b/src/PhpTabs/Reader/GuitarPro/GuitarPro4Reader.php @@ -41,11 +41,6 @@ final class GuitarPro4Reader extends GuitarProReaderBase */ protected $tripletFeel; - /** - * @var int - */ - protected $keySignature; - /** * @var \PhpTabs\Component\Tablature */ @@ -185,7 +180,7 @@ private function readMeasureHeaders(Song $song, int $count): void /** * Loop on tracks to read * - * @param array $channels + * @param array<\PhpTabs\Music\Channel> $channels */ private function readTracks(Song $song, int $count, array $channels, Lyric $lyric, int $lyricTrack): void { diff --git a/src/PhpTabs/Reader/GuitarPro/GuitarPro5Reader.php b/src/PhpTabs/Reader/GuitarPro/GuitarPro5Reader.php index 9a27fff..0e4f704 100644 --- a/src/PhpTabs/Reader/GuitarPro/GuitarPro5Reader.php +++ b/src/PhpTabs/Reader/GuitarPro/GuitarPro5Reader.php @@ -31,11 +31,6 @@ final class GuitarPro5Reader extends GuitarProReaderBase 'FICHIER GUITAR PRO v5.10', ]; - /** - * @var int - */ - protected $keySignature; - /** * @var \PhpTabs\Component\Tablature */ diff --git a/src/PhpTabs/Reader/GuitarPro/GuitarProReaderBase.php b/src/PhpTabs/Reader/GuitarPro/GuitarProReaderBase.php index 1ae6690..be84d48 100644 --- a/src/PhpTabs/Reader/GuitarPro/GuitarProReaderBase.php +++ b/src/PhpTabs/Reader/GuitarPro/GuitarProReaderBase.php @@ -40,6 +40,11 @@ abstract class GuitarProReaderBase implements GuitarProReaderInterface */ private $file; + /** + * @var int + */ + protected $keySignature; + /** * @param \PhpTabs\Component\InputStream $file An input file to read */ diff --git a/src/PhpTabs/Reader/GuitarPro/Helper/GuitarPro3Track.php b/src/PhpTabs/Reader/GuitarPro/Helper/GuitarPro3Track.php index 964787a..e061c52 100644 --- a/src/PhpTabs/Reader/GuitarPro/Helper/GuitarPro3Track.php +++ b/src/PhpTabs/Reader/GuitarPro/Helper/GuitarPro3Track.php @@ -22,7 +22,7 @@ final class GuitarPro3Track extends AbstractReader /** * Reads track informations * - * @param array $channels + * @param array<\PhpTabs\Music\Channel> $channels */ public function readTrack(Song $song, array $channels = []): Track { diff --git a/src/PhpTabs/Reader/GuitarPro/Helper/GuitarPro4Track.php b/src/PhpTabs/Reader/GuitarPro/Helper/GuitarPro4Track.php index 3b11793..10b66d2 100644 --- a/src/PhpTabs/Reader/GuitarPro/Helper/GuitarPro4Track.php +++ b/src/PhpTabs/Reader/GuitarPro/Helper/GuitarPro4Track.php @@ -23,7 +23,7 @@ final class GuitarPro4Track extends AbstractReader /** * Reads track informations * - * @param array $channels + * @param array<\PhpTabs\Music\Channel> $channels */ public function readTrack(Song $song, array $channels, Lyric $lyrics): Track { diff --git a/src/PhpTabs/Reader/GuitarPro/Helper/GuitarPro5Track.php b/src/PhpTabs/Reader/GuitarPro/Helper/GuitarPro5Track.php index 2854505..36a6a1f 100644 --- a/src/PhpTabs/Reader/GuitarPro/Helper/GuitarPro5Track.php +++ b/src/PhpTabs/Reader/GuitarPro/Helper/GuitarPro5Track.php @@ -23,7 +23,7 @@ final class GuitarPro5Track extends AbstractReader /** * Read track informations * - * @param array $channels + * @param array<\PhpTabs\Music\Channel> $channels */ public function readTrack(Song $song, array $channels, Lyric $lyrics): Track { diff --git a/src/PhpTabs/Reader/Midi/MidiAdjuster.php b/src/PhpTabs/Reader/Midi/MidiAdjuster.php index c211322..5817757 100644 --- a/src/PhpTabs/Reader/Midi/MidiAdjuster.php +++ b/src/PhpTabs/Reader/Midi/MidiAdjuster.php @@ -215,7 +215,7 @@ private function adjustStrings(Beat $beat): void } /** - * @param array $strings + * @param array<\PhpTabs\Music\TabString> $strings */ private function getStringForValue(array $strings, int $value): int { diff --git a/src/PhpTabs/Reader/Midi/MidiReader.php b/src/PhpTabs/Reader/Midi/MidiReader.php index 8fd81f2..2735d88 100644 --- a/src/PhpTabs/Reader/Midi/MidiReader.php +++ b/src/PhpTabs/Reader/Midi/MidiReader.php @@ -81,6 +81,21 @@ final class MidiReader extends MidiReaderBase */ private $settings; + /** + * @var Tablature|null + */ + private $tablature; + + /** + * @var MidiSequence + */ + private $sequence; + + /** + * @var ChannelRouter + */ + private $channelRouter; + /** * @param \PhpTabs\Component\InputStream $file An input file to read */ @@ -92,7 +107,7 @@ public function __construct(InputStream $file) $this->setTablature($song); - $this->settings = (new MidiSettings())->getDefaults(); + $this->settings = MidiSettings::getDefaults(); $this->sequence = $this->getSequence(); $this->initFields($this->sequence); diff --git a/src/PhpTabs/Renderer/Ascii/AsciiBase.php b/src/PhpTabs/Renderer/Ascii/AsciiBase.php index 664ad93..a1bda36 100644 --- a/src/PhpTabs/Renderer/Ascii/AsciiBase.php +++ b/src/PhpTabs/Renderer/Ascii/AsciiBase.php @@ -47,11 +47,11 @@ public function drawBarSegment(): void public function drawNote(string $fret): void { $this->movePoint( - $this->getPosX() + mb_strlen(strval($fret)), + $this->getPosX() + mb_strlen($fret), $this->getPosY() ); - $this->append(strval($fret)); + $this->append($fret); } /** @@ -205,7 +205,7 @@ public function output(): string for ($line = 0; $line <= $maxLines; $line++) { for ($col = 0; $col <= $maxCols; $col++) { - if (isset($this->content[$line], $this->content[$line][$col])) { + if (isset($this->content[$line][$col])) { $content .= $this->content[$line][$col]; } } diff --git a/src/PhpTabs/Writer/Midi/MidiSequenceParser.php b/src/PhpTabs/Writer/Midi/MidiSequenceParser.php index a38b9e2..0493a3b 100644 --- a/src/PhpTabs/Writer/Midi/MidiSequenceParser.php +++ b/src/PhpTabs/Writer/Midi/MidiSequenceParser.php @@ -212,7 +212,6 @@ private function makeBeats(MidiSequenceHelper $helper, Channel $channel, Track $ $stroke[] = 0; } - $track->getStrings(); $previous = null; $countBeats = $measure->countBeats(); diff --git a/src/PhpTabs/Writer/Midi/MidiWriter.php b/src/PhpTabs/Writer/Midi/MidiWriter.php index 005ec43..29ae66a 100644 --- a/src/PhpTabs/Writer/Midi/MidiWriter.php +++ b/src/PhpTabs/Writer/Midi/MidiWriter.php @@ -55,7 +55,7 @@ public function __construct(Song $song) $channelRouter = new ChannelRouter(); $channelRouterConfigurator = new ChannelRouterConfigurator($channelRouter); $channelRouterConfigurator->configureRouter($song->getChannels()); - $settings = (new MidiSettings())->getDefaults(); + $settings = MidiSettings::getDefaults(); $midiSequenceParser = new MidiSequenceParser( $song,