Skip to content

Commit fbe9206

Browse files
committed
Link GitHub Actions, less Java, more PHP type code
1 parent ce350f7 commit fbe9206

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# QR code decoder / reader for PHP
2+
3+
[![Tests](https://github.com/khanamiryan/php-qrcode-detector-decoder/actions/workflows/tests.yml/badge.svg)](https://github.com/khanamiryan/php-qrcode-detector-decoder/actions/workflows/tests.yml)
4+
[![Static Tests](https://github.com/khanamiryan/php-qrcode-detector-decoder/actions/workflows/static_tests.yml/badge.svg)](https://github.com/khanamiryan/php-qrcode-detector-decoder/actions/workflows/static_tests.yml)
5+
26
This is a PHP library to detect and decode QR-codes.<br />This is first and only QR code reader that works without extensions.<br />
37
Ported from [ZXing library](https://github.com/zxing/zxing)
48

lib/Qrcode/Decoder/BitMatrixParser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct($bitMatrix)
4242
{
4343
$dimension = $bitMatrix->getHeight();
4444
if ($dimension < 21 || ($dimension & 0x03) != 1) {
45-
throw FormatException::getFormatInstance();
45+
throw new FormatException();
4646
}
4747
$this->bitMatrix = $bitMatrix;
4848
}
@@ -108,7 +108,7 @@ public function readCodewords()
108108
$readingUp ^= true; // readingUp = !readingUp; // switch directions
109109
}
110110
if ($resultOffset != $version->getTotalCodewords()) {
111-
throw FormatException::getFormatInstance();
111+
throw new FormatException();
112112
}
113113

114114
return $result;
@@ -156,7 +156,7 @@ public function readFormatInformation()
156156
if ($parsedFormatInfo != null) {
157157
return $parsedFormatInfo;
158158
}
159-
throw FormatException::getFormatInstance();
159+
throw new FormatException();
160160
}
161161

162162
/**
@@ -221,7 +221,7 @@ public function readVersion()
221221

222222
return $theParsedVersion;
223223
}
224-
throw FormatException::getFormatInstance("both version information locations cannot be parsed as the valid encoding of version information");
224+
throw new FormatException("both version information locations cannot be parsed as the valid encoding of version information");
225225
}
226226

227227
/**

lib/Qrcode/Decoder/DecodedBitStreamParser.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static function decode(
7777
$fc1InEffect = true;
7878
} elseif ($mode == Mode::$STRUCTURED_APPEND) {
7979
if ($bits->available() < 16) {
80-
throw FormatException::getFormatInstance("Bits available < 16");
80+
throw new FormatException("Bits available < 16");
8181
}
8282
// sequence number and parity is added later to the result metadata
8383
// Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
@@ -88,7 +88,7 @@ public static function decode(
8888
$value = self::parseECIValue($bits);
8989
$currentCharacterSetECI = CharacterSetECI::getCharacterSetECIByValue($value);
9090
if ($currentCharacterSetECI == null) {
91-
throw FormatException::getFormatInstance("Current character set ECI is null");
91+
throw new FormatException("Current character set ECI is null");
9292
}
9393
} else {
9494
// First handle Hanzi mode which does not start with character count
@@ -112,15 +112,15 @@ public static function decode(
112112
} elseif ($mode == Mode::$KANJI) {
113113
self::decodeKanjiSegment($bits, $result, $count);
114114
} else {
115-
throw FormatException::getFormatInstance("Unknown mode $mode to decode");
115+
throw new FormatException("Unknown mode $mode to decode");
116116
}
117117
}
118118
}
119119
}
120120
} while ($mode != Mode::$TERMINATOR);
121121
} catch (\InvalidArgumentException $e) {
122122
// from readBits() calls
123-
throw FormatException::getFormatInstance("Invalid argument exception when formatting: " . $e->getMessage());
123+
throw new FormatException("Invalid argument exception when formatting: " . $e->getMessage());
124124
}
125125

126126
return new DecoderResult(
@@ -152,7 +152,7 @@ private static function parseECIValue(BitSource $bits): int
152152

153153
return (($firstByte & 0x1F) << 16) | $secondThirdBytes;
154154
}
155-
throw FormatException::getFormatInstance("ECI Value parsing failed.");
155+
throw new FormatException("ECI Value parsing failed.");
156156
}
157157

158158
/**
@@ -167,7 +167,7 @@ private static function decodeHanziSegment(
167167
): void {
168168
// Don't crash trying to read more bits than we have available.
169169
if ($count * 13 > $bits->available()) {
170-
throw FormatException::getFormatInstance("Trying to read more bits than we have available");
170+
throw new FormatException("Trying to read more bits than we have available");
171171
}
172172

173173
// Each character will require 2 bytes. Read the characters as 2-byte pairs
@@ -202,11 +202,11 @@ private static function decodeNumericSegment(
202202
while ($count >= 3) {
203203
// Each 10 bits encodes three digits
204204
if ($bits->available() < 10) {
205-
throw FormatException::getFormatInstance("Not enough bits available");
205+
throw new FormatException("Not enough bits available");
206206
}
207207
$threeDigitsBits = $bits->readBits(10);
208208
if ($threeDigitsBits >= 1000) {
209-
throw FormatException::getFormatInstance("Too many three digit bits");
209+
throw new FormatException("Too many three digit bits");
210210
}
211211
$result .= (self::toAlphaNumericChar($threeDigitsBits / 100));
212212
$result .= (self::toAlphaNumericChar(($threeDigitsBits / 10) % 10));
@@ -216,22 +216,22 @@ private static function decodeNumericSegment(
216216
if ($count == 2) {
217217
// Two digits left over to read, encoded in 7 bits
218218
if ($bits->available() < 7) {
219-
throw FormatException::getFormatInstance("Two digits left over to read, encoded in 7 bits, but only " . $bits->available() . ' bits available');
219+
throw new FormatException("Two digits left over to read, encoded in 7 bits, but only " . $bits->available() . ' bits available');
220220
}
221221
$twoDigitsBits = $bits->readBits(7);
222222
if ($twoDigitsBits >= 100) {
223-
throw FormatException::getFormatInstance("Too many bits: $twoDigitsBits expected < 100");
223+
throw new FormatException("Too many bits: $twoDigitsBits expected < 100");
224224
}
225225
$result .= (self::toAlphaNumericChar($twoDigitsBits / 10));
226226
$result .= (self::toAlphaNumericChar($twoDigitsBits % 10));
227227
} elseif ($count == 1) {
228228
// One digit left over to read
229229
if ($bits->available() < 4) {
230-
throw FormatException::getFormatInstance("One digit left to read, but < 4 bits available");
230+
throw new FormatException("One digit left to read, but < 4 bits available");
231231
}
232232
$digitBits = $bits->readBits(4);
233233
if ($digitBits >= 10) {
234-
throw FormatException::getFormatInstance("Too many bits: $digitBits expected < 10");
234+
throw new FormatException("Too many bits: $digitBits expected < 10");
235235
}
236236
$result .= (self::toAlphaNumericChar($digitBits));
237237
}
@@ -243,10 +243,10 @@ private static function decodeNumericSegment(
243243
private static function toAlphaNumericChar(int|float $value)
244244
{
245245
if ($value >= count(self::$ALPHANUMERIC_CHARS)) {
246-
throw FormatException::getFormatInstance("$value has too many alphanumeric chars");
246+
throw new FormatException("$value has too many alphanumeric chars");
247247
}
248248

249-
return self::$ALPHANUMERIC_CHARS[$value];
249+
return self::$ALPHANUMERIC_CHARS[(int)round($value)];
250250
}
251251

252252
private static function decodeAlphanumericSegment(
@@ -259,7 +259,7 @@ private static function decodeAlphanumericSegment(
259259
$start = strlen((string) $result);
260260
while ($count > 1) {
261261
if ($bits->available() < 11) {
262-
throw FormatException::getFormatInstance("Not enough bits available to read two expected characters");
262+
throw new FormatException("Not enough bits available to read two expected characters");
263263
}
264264
$nextTwoCharsBits = $bits->readBits(11);
265265
$result .= (self::toAlphaNumericChar($nextTwoCharsBits / 45));
@@ -269,7 +269,7 @@ private static function decodeAlphanumericSegment(
269269
if ($count == 1) {
270270
// special case: one character left
271271
if ($bits->available() < 6) {
272-
throw FormatException::getFormatInstance("Not enough bits available to read one expected character");
272+
throw new FormatException("Not enough bits available to read one expected character");
273273
}
274274
$result .= self::toAlphaNumericChar($bits->readBits(6));
275275
}
@@ -300,7 +300,7 @@ private static function decodeByteSegment(
300300
): void {
301301
// Don't crash trying to read more bits than we have available.
302302
if (8 * $count > $bits->available()) {
303-
throw FormatException::getFormatInstance("Trying to read more bits than we have available");
303+
throw new FormatException("Trying to read more bits than we have available");
304304
}
305305

306306
$readBytes = fill_array(0, $count, 0);
@@ -337,7 +337,7 @@ private static function decodeKanjiSegment(
337337
): void {
338338
// Don't crash trying to read more bits than we have available.
339339
if ($count * 13 > $bits->available()) {
340-
throw FormatException::getFormatInstance("Trying to read more bits than we have available");
340+
throw new FormatException("Trying to read more bits than we have available");
341341
}
342342

343343
// Each character will require 2 bytes. Read the characters as 2-byte pairs

lib/Qrcode/Decoder/Version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ public function getECBlocksForLevel(ErrorCorrectionLevel $ecLevel)
100100
public static function getProvisionalVersionForDimension($dimension)
101101
{
102102
if ($dimension % 4 != 1) {
103-
throw FormatException::getFormatInstance();
103+
throw new FormatException();
104104
}
105105
try {
106106
return self::getVersionForNumber(($dimension - 17) / 4);
107107
} catch (\InvalidArgumentException) {
108-
throw FormatException::getFormatInstance();
108+
throw new FormatException();
109109
}
110110
}
111111

0 commit comments

Comments
 (0)