@@ -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,36 +202,36 @@ 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 ));
212- $ result .= (self ::toAlphaNumericChar (($ threeDigitsBits / 10 ) % 10 ));
212+ $ result .= (self ::toAlphaNumericChar ((( int ) round ( $ threeDigitsBits / 10 ) ) % 10 ));
213213 $ result .= (self ::toAlphaNumericChar ($ threeDigitsBits % 10 ));
214214 $ count -= 3 ;
215215 }
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 }
@@ -242,11 +242,12 @@ private static function decodeNumericSegment(
242242 */
243243 private static function toAlphaNumericChar (int |float $ value )
244244 {
245- if ($ value >= count (self ::$ ALPHANUMERIC_CHARS )) {
246- throw FormatException::getFormatInstance ("$ value has too many alphanumeric chars " );
245+ $ intVal = (int ) $ value ;
246+ if ($ intVal >= count (self ::$ ALPHANUMERIC_CHARS )) {
247+ throw new FormatException ("$ intVal is too many alphanumeric chars " );
247248 }
248249
249- return self ::$ ALPHANUMERIC_CHARS [$ value ];
250+ return self ::$ ALPHANUMERIC_CHARS [( int )( $ intVal ) ];
250251 }
251252
252253 private static function decodeAlphanumericSegment (
@@ -259,7 +260,7 @@ private static function decodeAlphanumericSegment(
259260 $ start = strlen ((string ) $ result );
260261 while ($ count > 1 ) {
261262 if ($ bits ->available () < 11 ) {
262- throw FormatException:: getFormatInstance ("Not enough bits available to read two expected characters " );
263+ throw new FormatException ("Not enough bits available to read two expected characters " );
263264 }
264265 $ nextTwoCharsBits = $ bits ->readBits (11 );
265266 $ result .= (self ::toAlphaNumericChar ($ nextTwoCharsBits / 45 ));
@@ -269,7 +270,7 @@ private static function decodeAlphanumericSegment(
269270 if ($ count == 1 ) {
270271 // special case: one character left
271272 if ($ bits ->available () < 6 ) {
272- throw FormatException:: getFormatInstance ("Not enough bits available to read one expected character " );
273+ throw new FormatException ("Not enough bits available to read one expected character " );
273274 }
274275 $ result .= self ::toAlphaNumericChar ($ bits ->readBits (6 ));
275276 }
@@ -300,7 +301,7 @@ private static function decodeByteSegment(
300301 ): void {
301302 // Don't crash trying to read more bits than we have available.
302303 if (8 * $ count > $ bits ->available ()) {
303- throw FormatException:: getFormatInstance ("Trying to read more bits than we have available " );
304+ throw new FormatException ("Trying to read more bits than we have available " );
304305 }
305306
306307 $ readBytes = fill_array (0 , $ count , 0 );
@@ -337,7 +338,7 @@ private static function decodeKanjiSegment(
337338 ): void {
338339 // Don't crash trying to read more bits than we have available.
339340 if ($ count * 13 > $ bits ->available ()) {
340- throw FormatException:: getFormatInstance ("Trying to read more bits than we have available " );
341+ throw new FormatException ("Trying to read more bits than we have available " );
341342 }
342343
343344 // Each character will require 2 bytes. Read the characters as 2-byte pairs
0 commit comments