From 9eba4ada081ab888f4317c4df2b0d53b2be2a8d0 Mon Sep 17 00:00:00 2001 From: smiley Date: Mon, 13 Mar 2023 15:17:24 +0100 Subject: [PATCH] :octocat: remove unnecessary Mode::getLengthBitsForMode() --- src/Common/Mode.php | 14 -------------- src/Data/QRData.php | 2 +- tests/Common/ModeTest.php | 7 ------- 3 files changed, 1 insertion(+), 22 deletions(-) diff --git a/src/Common/Mode.php b/src/Common/Mode.php index c226e5b2a..a9479c51e 100644 --- a/src/Common/Mode.php +++ b/src/Common/Mode.php @@ -92,18 +92,4 @@ final class Mode{ throw new QRCodeException(sprintf('invalid version number: %d', $version)); } - /** - * returns the array of length bits for the given mode - * - * @throws \chillerlan\QRCode\QRCodeException - */ - public static function getLengthBitsForMode(int $mode):array{ - - if(isset(self::LENGTH_BITS[$mode])){ - return self::LENGTH_BITS[$mode]; - } - - throw new QRCodeException('invalid mode given'); - } - } diff --git a/src/Data/QRData.php b/src/Data/QRData.php index 9be3f84ab..0e51ed689 100644 --- a/src/Data/QRData.php +++ b/src/Data/QRData.php @@ -140,7 +140,7 @@ final class QRData{ foreach($this->dataSegments as $segment){ // data length in bits of the current segment +4 bits for each mode descriptor - $length += ($segment->getLengthInBits() + Mode::getLengthBitsForMode($segment->getDataMode())[0] + 4); + $length += ($segment->getLengthInBits() + Mode::getLengthBitsForVersion($segment->getDataMode(), 1) + 4); if(!$segment instanceof ECI){ // mode length bits margin to the next breakpoint diff --git a/tests/Common/ModeTest.php b/tests/Common/ModeTest.php index b9abcac73..bd729129f 100644 --- a/tests/Common/ModeTest.php +++ b/tests/Common/ModeTest.php @@ -54,11 +54,4 @@ final class ModeTest extends TestCase{ Mode::getLengthBitsForVersion(Mode::BYTE, 69); } - public function testGetLengthBitsForModeInvalidModeException():void{ - $this->expectException(QRCodeException::class); - $this->expectExceptionMessage('invalid mode given'); - /** @phan-suppress-next-line PhanNoopNew */ - Mode::getLengthBitsForMode(42); - } - }