@@ -77,7 +77,7 @@ public static function decode(
77
77
$ fc1InEffect = true ;
78
78
} elseif ($ mode == Mode::$ STRUCTURED_APPEND ) {
79
79
if ($ bits ->available () < 16 ) {
80
- throw FormatException:: getFormatInstance ("Bits available < 16 " );
80
+ throw new FormatException ("Bits available < 16 " );
81
81
}
82
82
// sequence number and parity is added later to the result metadata
83
83
// Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
@@ -88,7 +88,7 @@ public static function decode(
88
88
$ value = self ::parseECIValue ($ bits );
89
89
$ currentCharacterSetECI = CharacterSetECI::getCharacterSetECIByValue ($ value );
90
90
if ($ currentCharacterSetECI == null ) {
91
- throw FormatException:: getFormatInstance ("Current character set ECI is null " );
91
+ throw new FormatException ("Current character set ECI is null " );
92
92
}
93
93
} else {
94
94
// First handle Hanzi mode which does not start with character count
@@ -112,15 +112,15 @@ public static function decode(
112
112
} elseif ($ mode == Mode::$ KANJI ) {
113
113
self ::decodeKanjiSegment ($ bits , $ result , $ count );
114
114
} else {
115
- throw FormatException:: getFormatInstance ("Unknown mode $ mode to decode " );
115
+ throw new FormatException ("Unknown mode $ mode to decode " );
116
116
}
117
117
}
118
118
}
119
119
}
120
120
} while ($ mode != Mode::$ TERMINATOR );
121
121
} catch (\InvalidArgumentException $ e ) {
122
122
// 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 ());
124
124
}
125
125
126
126
return new DecoderResult (
@@ -152,7 +152,7 @@ private static function parseECIValue(BitSource $bits): int
152
152
153
153
return (($ firstByte & 0x1F ) << 16 ) | $ secondThirdBytes ;
154
154
}
155
- throw FormatException:: getFormatInstance ("ECI Value parsing failed. " );
155
+ throw new FormatException ("ECI Value parsing failed. " );
156
156
}
157
157
158
158
/**
@@ -167,7 +167,7 @@ private static function decodeHanziSegment(
167
167
): void {
168
168
// Don't crash trying to read more bits than we have available.
169
169
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 " );
171
171
}
172
172
173
173
// Each character will require 2 bytes. Read the characters as 2-byte pairs
@@ -202,36 +202,36 @@ private static function decodeNumericSegment(
202
202
while ($ count >= 3 ) {
203
203
// Each 10 bits encodes three digits
204
204
if ($ bits ->available () < 10 ) {
205
- throw FormatException:: getFormatInstance ("Not enough bits available " );
205
+ throw new FormatException ("Not enough bits available " );
206
206
}
207
207
$ threeDigitsBits = $ bits ->readBits (10 );
208
208
if ($ threeDigitsBits >= 1000 ) {
209
- throw FormatException:: getFormatInstance ("Too many three digit bits " );
209
+ throw new FormatException ("Too many three digit bits " );
210
210
}
211
211
$ result .= (self ::toAlphaNumericChar ($ threeDigitsBits / 100 ));
212
- $ result .= (self ::toAlphaNumericChar (($ threeDigitsBits / 10 ) % 10 ));
212
+ $ result .= (self ::toAlphaNumericChar ((( int ) round ( $ threeDigitsBits / 10 ) ) % 10 ));
213
213
$ result .= (self ::toAlphaNumericChar ($ threeDigitsBits % 10 ));
214
214
$ count -= 3 ;
215
215
}
216
216
if ($ count == 2 ) {
217
217
// Two digits left over to read, encoded in 7 bits
218
218
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 ' );
220
220
}
221
221
$ twoDigitsBits = $ bits ->readBits (7 );
222
222
if ($ twoDigitsBits >= 100 ) {
223
- throw FormatException:: getFormatInstance ("Too many bits: $ twoDigitsBits expected < 100 " );
223
+ throw new FormatException ("Too many bits: $ twoDigitsBits expected < 100 " );
224
224
}
225
225
$ result .= (self ::toAlphaNumericChar ($ twoDigitsBits / 10 ));
226
226
$ result .= (self ::toAlphaNumericChar ($ twoDigitsBits % 10 ));
227
227
} elseif ($ count == 1 ) {
228
228
// One digit left over to read
229
229
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 " );
231
231
}
232
232
$ digitBits = $ bits ->readBits (4 );
233
233
if ($ digitBits >= 10 ) {
234
- throw FormatException:: getFormatInstance ("Too many bits: $ digitBits expected < 10 " );
234
+ throw new FormatException ("Too many bits: $ digitBits expected < 10 " );
235
235
}
236
236
$ result .= (self ::toAlphaNumericChar ($ digitBits ));
237
237
}
@@ -242,11 +242,12 @@ private static function decodeNumericSegment(
242
242
*/
243
243
private static function toAlphaNumericChar (int |float $ value )
244
244
{
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 " );
247
248
}
248
249
249
- return self ::$ ALPHANUMERIC_CHARS [$ value ];
250
+ return self ::$ ALPHANUMERIC_CHARS [( int )( $ intVal ) ];
250
251
}
251
252
252
253
private static function decodeAlphanumericSegment (
@@ -259,7 +260,7 @@ private static function decodeAlphanumericSegment(
259
260
$ start = strlen ((string ) $ result );
260
261
while ($ count > 1 ) {
261
262
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 " );
263
264
}
264
265
$ nextTwoCharsBits = $ bits ->readBits (11 );
265
266
$ result .= (self ::toAlphaNumericChar ($ nextTwoCharsBits / 45 ));
@@ -269,7 +270,7 @@ private static function decodeAlphanumericSegment(
269
270
if ($ count == 1 ) {
270
271
// special case: one character left
271
272
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 " );
273
274
}
274
275
$ result .= self ::toAlphaNumericChar ($ bits ->readBits (6 ));
275
276
}
@@ -300,7 +301,7 @@ private static function decodeByteSegment(
300
301
): void {
301
302
// Don't crash trying to read more bits than we have available.
302
303
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 " );
304
305
}
305
306
306
307
$ readBytes = fill_array (0 , $ count , 0 );
@@ -337,7 +338,7 @@ private static function decodeKanjiSegment(
337
338
): void {
338
339
// Don't crash trying to read more bits than we have available.
339
340
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 " );
341
342
}
342
343
343
344
// Each character will require 2 bytes. Read the characters as 2-byte pairs
0 commit comments