| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Excel 97/2003 Reader Class |
| 4 | 4 | * |
| 5 | 5 | * Based on PHP Excel Reader 2.21. |
| 6 | + * | |
| 6 | 7 | * @link https://code.google.com/archive/p/php-excel-reader/ |
| 7 | 8 | * |
| 8 | 9 | * @package TablePress |
| 9 | 10 | * @subpackage Import |
| @@ -56,35 +57,31 @@ | ||
| 56 | 57 | /** |
| 57 | 58 | * [$data description] |
| 58 | 59 | * |
| 59 | 60 | * @since 1.0.0 |
| 60 | - * @var string | |
| 61 | 61 | */ |
| 62 | - protected $data = ''; | |
| 62 | + protected string $data = ''; | |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * [$error description] |
| 66 | 66 | * |
| 67 | 67 | * @since 1.0.0 |
| 68 | - * @var int | |
| 69 | 68 | */ |
| 70 | - public $error; | |
| 69 | + public int $error; | |
| 71 | 70 | |
| 72 | 71 | /** |
| 73 | 72 | * [$bigBlockChain description] |
| 74 | 73 | * |
| 75 | 74 | * @since 1.0.0 |
| 76 | - * @var array | |
| 77 | 75 | */ |
| 78 | - protected $bigBlockChain = array(); | |
| 76 | + protected array $bigBlockChain = array(); | |
| 79 | 77 | |
| 80 | 78 | /** |
| 81 | 79 | * [$smallBlockChain description] |
| 82 | 80 | * |
| 83 | 81 | * @since 1.0.0 |
| 84 | - * @var array | |
| 85 | 82 | */ |
| 86 | - protected $smallBlockChain = array(); | |
| 83 | + protected array $smallBlockChain = array(); | |
| 87 | 84 | |
| 88 | 85 | /** |
| 89 | 86 | * [$entry description] |
| 90 | 87 | * |
| @@ -130,9 +127,9 @@ | ||
| 130 | 127 | * [read description] |
| 131 | 128 | * |
| 132 | 129 | * @since 1.0.0 |
| 133 | 130 | * |
| 134 | - * @param [type] $data [description] | |
| 131 | + * @param string $data [description] | |
| 135 | 132 | * @return [type] [description] |
| 136 | 133 | */ |
| 137 | 134 | public function read( $data ) { |
| 138 | 135 | $this->data = $data; |
| @@ -139,9 +136,9 @@ | ||
| 139 | 136 | if ( ! $this->data ) { |
| 140 | 137 | $this->error = 1; |
| 141 | 138 | return false; |
| 142 | 139 | } |
| 143 | - if ( IDENTIFIER_OLE !== substr( $this->data, 0, 8 ) ) { | |
| 140 | + if ( str_starts_with( $this->data, IDENTIFIER_OLE ) ) { | |
| 144 | 141 | $this->error = 2; |
| 145 | 142 | return false; |
| 146 | 143 | } |
| 147 | 144 | $numBigBlockDepotBlocks = $this->_GetInt4d( $this->data, NUM_BIG_BLOCK_DEPOT_BLOCKS_POS ); |
| @@ -185,9 +182,9 @@ | ||
| 185 | 182 | $pos = ( $bigBlockDepotBlocks[ $i ] + 1 ) * BIG_BLOCK_SIZE; |
| 186 | 183 | for ( $j = 0; $j < BIG_BLOCK_SIZE / 4; $j++ ) { |
| 187 | 184 | $this->bigBlockChain[ $index ] = $this->_GetInt4d( $this->data, $pos ); |
| 188 | 185 | $pos += 4; |
| 189 | - $index++; | |
| 186 | + ++$index; | |
| 190 | 187 | } |
| 191 | 188 | } |
| 192 | 189 | |
| 193 | 190 | // readSmallBlockDepot(); |
| @@ -199,9 +196,9 @@ | ||
| 199 | 196 | $pos = ( $sbdBlock + 1 ) * BIG_BLOCK_SIZE; |
| 200 | 197 | for ( $j = 0; $j < BIG_BLOCK_SIZE / 4; $j++ ) { |
| 201 | 198 | $this->smallBlockChain[ $index ] = $this->_GetInt4d( $this->data, $pos ); |
| 202 | 199 | $pos += 4; |
| 203 | - $index++; | |
| 200 | + ++$index; | |
| 204 | 201 | } |
| 205 | 202 | $sbdBlock = $this->bigBlockChain[ $sbdBlock ]; |
| 206 | 203 | } |
| 207 | 204 | |
| @@ -216,11 +213,11 @@ | ||
| 216 | 213 | * |
| 217 | 214 | * @since 1.0.0 |
| 218 | 215 | * |
| 219 | 216 | * @param [type] $bl [description] |
| 220 | - * @return [type] [description] | |
| 217 | + * @return string [description] | |
| 221 | 218 | */ |
| 222 | - protected function _readData( $bl ) { | |
| 219 | + protected function _readData( $bl ): string { | |
| 223 | 220 | $block = $bl; |
| 224 | 221 | $data = ''; |
| 225 | 222 | while ( -2 !== $block ) { |
| 226 | 223 | $pos = ( $block + 1 ) * BIG_BLOCK_SIZE; |
| @@ -286,9 +283,9 @@ | ||
| 286 | 283 | return $streamData; |
| 287 | 284 | } else { |
| 288 | 285 | $numBlocks = $this->props[ $this->wrkbook ]['size'] / BIG_BLOCK_SIZE; |
| 289 | 286 | if ( 0 !== $this->props[ $this->wrkbook ]['size'] % BIG_BLOCK_SIZE ) { |
| 290 | - $numBlocks++; | |
| 287 | + ++$numBlocks; | |
| 291 | 288 | } |
| 292 | 289 | |
| 293 | 290 | if ( 0 === $numBlocks ) { |
| 294 | 291 | return ''; |
| @@ -310,11 +307,11 @@ | ||
| 310 | 307 | * @since 1.0.0 |
| 311 | 308 | * |
| 312 | 309 | * @param [type] $data [description] |
| 313 | 310 | * @param [type] $pos [description] |
| 314 | - * @return [type] [description] | |
| 311 | + * @return int [description] | |
| 315 | 312 | */ |
| 316 | - protected function _GetInt4d( $data, $pos ) { | |
| 313 | + protected function _GetInt4d( $data, $pos ): int { | |
| 317 | 314 | $value = ord( $data[ $pos ] ) | ( ord( $data[ $pos + 1 ] ) << 8 ) | ( ord( $data[ $pos + 2 ] ) << 16 ) | ( ord( $data[ $pos + 3 ] ) << 24 ); |
| 318 | 315 | if ( $value >= 4294967294 ) { |
| 319 | 316 | $value = -2; |
| 320 | 317 | } |
| @@ -368,11 +365,11 @@ | ||
| 368 | 365 | define( 'SPREADSHEET_EXCEL_READER_TYPE_DEFCOLWIDTH', 0x55 ); |
| 369 | 366 | define( 'SPREADSHEET_EXCEL_READER_TYPE_STANDARDWIDTH', 0x99 ); |
| 370 | 367 | define( 'SPREADSHEET_EXCEL_READER_DEF_NUM_FORMAT', '%s' ); |
| 371 | 368 | |
| 372 | -/* | |
| 373 | -* Main Class | |
| 374 | -*/ | |
| 369 | +/** | |
| 370 | + * Main Class | |
| 371 | + */ | |
| 375 | 372 | class Spreadsheet_Excel_Reader { |
| 376 | 373 | |
| 377 | 374 | /* |
| 378 | 375 | * The following four public constants were added to make data retrieval easier. |
| @@ -381,35 +378,31 @@ | ||
| 381 | 378 | /** |
| 382 | 379 | * [$colnames description] |
| 383 | 380 | * |
| 384 | 381 | * @since 1.0.0 |
| 385 | - * @var array | |
| 386 | 382 | */ |
| 387 | - public $colnames = array(); | |
| 383 | + public array $colnames = array(); | |
| 388 | 384 | |
| 389 | 385 | /** |
| 390 | 386 | * [$colindexes description] |
| 391 | 387 | * |
| 392 | 388 | * @since 1.0.0 |
| 393 | - * @var array | |
| 394 | 389 | */ |
| 395 | - public $colindexes = array(); | |
| 390 | + public array $colindexes = array(); | |
| 396 | 391 | |
| 397 | 392 | /** |
| 398 | 393 | * [$standardColWidth description] |
| 399 | 394 | * |
| 400 | 395 | * @since 1.0.0 |
| 401 | - * @var int | |
| 402 | 396 | */ |
| 403 | - public $standardColWidth = 0; | |
| 397 | + public int $standardColWidth = 0; | |
| 404 | 398 | |
| 405 | 399 | /** |
| 406 | 400 | * [$defaultColWidth description] |
| 407 | 401 | * |
| 408 | 402 | * @since 1.0.0 |
| 409 | - * @var int | |
| 410 | 403 | */ |
| 411 | - public $defaultColWidth = 0; | |
| 404 | + public int $defaultColWidth = 0; | |
| 412 | 405 | |
| 413 | 406 | /** |
| 414 | 407 | * [$store_extended_info description] |
| 415 | 408 | * |
| @@ -447,11 +440,11 @@ | ||
| 447 | 440 | * |
| 448 | 441 | * @since 1.0.0 |
| 449 | 442 | * |
| 450 | 443 | * @param [type] $d [description] |
| 451 | - * @return [type] [description] | |
| 444 | + * @return string [description] | |
| 452 | 445 | */ |
| 453 | - protected function myHex( $d ) { | |
| 446 | + protected function myHex( $d ): string { | |
| 454 | 447 | if ( $d < 16 ) { |
| 455 | 448 | return '0' . dechex( $d ); |
| 456 | 449 | } |
| 457 | 450 | return dechex( $d ); |
| @@ -464,11 +457,11 @@ | ||
| 464 | 457 | * |
| 465 | 458 | * @param [type] $data [description] |
| 466 | 459 | * @param [type] $pos [description] |
| 467 | 460 | * @param [type] $length [description] |
| 468 | - * @return [type] [description] | |
| 461 | + * @return string [description] | |
| 469 | 462 | */ |
| 470 | - protected function dumpHexData( $data, $pos, $length ) { | |
| 463 | + protected function dumpHexData( $data, $pos, $length ): string { | |
| 471 | 464 | $info = ''; |
| 472 | 465 | for ( $i = 0; $i <= $length; $i++ ) { |
| 473 | 466 | if ( 0 !== $i ) { |
| 474 | 467 | $info .= ' '; |
| @@ -588,11 +581,11 @@ | ||
| 588 | 581 | * |
| 589 | 582 | * @param [type] $row [description] |
| 590 | 583 | * @param [type] $col [description] |
| 591 | 584 | * @param int $sheet Optional. [description] |
| 592 | - * @return [type] [description] | |
| 585 | + * @return int [description] | |
| 593 | 586 | */ |
| 594 | - public function rowspan( $row, $col, $sheet = 0 ) { | |
| 587 | + public function rowspan( $row, $col, $sheet = 0 ): int { | |
| 595 | 588 | $value = $this->info( $row, $col, 'rowspan', $sheet ); |
| 596 | 589 | if ( '' === $value ) { |
| 597 | 590 | return 1; |
| 598 | 591 | } else { |
| @@ -608,11 +601,11 @@ | ||
| 608 | 601 | * |
| 609 | 602 | * @param [type] $row [description] |
| 610 | 603 | * @param [type] $col [description] |
| 611 | 604 | * @param int $sheet Optional. [description] |
| 612 | - * @return [type] [description] | |
| 605 | + * @return int [description] | |
| 613 | 606 | */ |
| 614 | - public function colspan( $row, $col, $sheet = 0 ) { | |
| 607 | + public function colspan( $row, $col, $sheet = 0 ): int { | |
| 615 | 608 | $value = $this->info( $row, $col, 'colspan', $sheet ); |
| 616 | 609 | if ( '' === $value ) { |
| 617 | 610 | return 1; |
| 618 | 611 | } else { |
| @@ -683,11 +676,11 @@ | ||
| 683 | 676 | * @since 1.0.0 |
| 684 | 677 | * |
| 685 | 678 | * @param [type] $col [description] |
| 686 | 679 | * @param int $sheet Optional. [description] |
| 687 | - * @return [type] [description] | |
| 680 | + * @return bool [description] | |
| 688 | 681 | */ |
| 689 | - public function colhidden( $col, $sheet = 0 ) { | |
| 682 | + public function colhidden( $col, $sheet = 0 ): bool { | |
| 690 | 683 | return (bool) $this->colInfo[ $sheet ][ $col ]['hidden']; |
| 691 | 684 | } |
| 692 | 685 | |
| 693 | 686 | /** |
| @@ -709,11 +702,11 @@ | ||
| 709 | 702 | * @since 1.0.0 |
| 710 | 703 | * |
| 711 | 704 | * @param [type] $row [description] |
| 712 | 705 | * @param int $sheet Optional. [description] |
| 713 | - * @return [type] [description] | |
| 706 | + * @return bool [description] | |
| 714 | 707 | */ |
| 715 | - public function rowhidden( $row, $sheet = 0 ) { | |
| 708 | + public function rowhidden( $row, $sheet = 0 ): bool { | |
| 716 | 709 | return (bool) $this->rowInfo[ $sheet ][ $row ]['hidden']; |
| 717 | 710 | } |
| 718 | 711 | |
| 719 | 712 | // GET THE CSS FOR FORMATTING |
| @@ -726,11 +719,11 @@ | ||
| 726 | 719 | * |
| 727 | 720 | * @param [type] $row [description] |
| 728 | 721 | * @param [type] $col [description] |
| 729 | 722 | * @param int $sheet Optional. [description] |
| 730 | - * @return [type] [description] | |
| 723 | + * @return string [description] | |
| 731 | 724 | */ |
| 732 | - public function style( $row, $col, $sheet = 0 ) { | |
| 725 | + public function style( $row, $col, $sheet = 0 ): string { | |
| 733 | 726 | $css = ''; |
| 734 | 727 | $font = $this->font( $row, $col, $sheet ); |
| 735 | 728 | if ( '' !== $font ) { |
| 736 | 729 | $css .= "font-family:{$font};"; |
| @@ -1062,13 +1055,13 @@ | ||
| 1062 | 1055 | * @since 1.0.0 |
| 1063 | 1056 | * |
| 1064 | 1057 | * @param [type] $row [description] |
| 1065 | 1058 | * @param [type] $col [description] |
| 1066 | - * @param int $sheet Optional. [description] | |
| 1067 | - * @param [type] $prop [description] | |
| 1059 | + * @param int $sheet [description] | |
| 1060 | + * @param string $prop [description] | |
| 1068 | 1061 | * @return [type] [description] |
| 1069 | 1062 | */ |
| 1070 | - public function fontProperty( $row, $col, $sheet = 0, $prop ) { | |
| 1063 | + public function fontProperty( $row, $col, $sheet, $prop ) { | |
| 1071 | 1064 | $font = $this->fontRecord( $row, $col, $sheet ); |
| 1072 | 1065 | if ( null !== $font ) { |
| 1073 | 1066 | return $font[ $prop ]; |
| 1074 | 1067 | } |
| @@ -1204,11 +1197,11 @@ | ||
| 1204 | 1197 | * @param bool $row_numbers Optional. [description] |
| 1205 | 1198 | * @param bool $col_letters Optional. [description] |
| 1206 | 1199 | * @param int $sheet Optional. [description] |
| 1207 | 1200 | * @param string $table_class Optional. [description] |
| 1208 | - * @return [type] [description] | |
| 1201 | + * @return string [description] | |
| 1209 | 1202 | */ |
| 1210 | - public function dump( $row_numbers = false, $col_letters = false, $sheet = 0, $table_class = 'excel' ) { | |
| 1203 | + public function dump( $row_numbers = false, $col_letters = false, $sheet = 0, $table_class = 'excel' ): string { | |
| 1211 | 1204 | $out = "<table class=\"$table_class\" cellspacing=0>"; |
| 1212 | 1205 | if ( $col_letters ) { |
| 1213 | 1206 | $out .= "<thead>\n\t<tr>"; |
| 1214 | 1207 | if ( $row_numbers ) { |
| @@ -1274,33 +1267,32 @@ | ||
| 1274 | 1267 | |
| 1275 | 1268 | // -------------- |
| 1276 | 1269 | // END PUBLIC API |
| 1277 | 1270 | |
| 1278 | - protected $boundsheets = array(); | |
| 1279 | - protected $formatRecords = array(); | |
| 1280 | - protected $fontRecords = array(); | |
| 1281 | - protected $xfRecords = array(); | |
| 1282 | - protected $colInfo = array(); | |
| 1283 | - protected $rowInfo = array(); | |
| 1271 | + protected array $boundsheets = array(); | |
| 1272 | + protected array $formatRecords = array(); | |
| 1273 | + protected array $fontRecords = array(); | |
| 1274 | + protected array $xfRecords = array(); | |
| 1275 | + protected array $colInfo = array(); | |
| 1276 | + protected array $rowInfo = array(); | |
| 1284 | 1277 | |
| 1285 | - protected $sst = array(); | |
| 1286 | - protected $sheets = array(); | |
| 1278 | + protected array $sst = array(); | |
| 1279 | + protected array $sheets = array(); | |
| 1287 | 1280 | |
| 1288 | 1281 | protected $data; |
| 1289 | 1282 | protected $_ole; |
| 1290 | - protected $_defaultEncoding = 'UTF-8'; | |
| 1291 | - protected $_defaultFormat = SPREADSHEET_EXCEL_READER_DEF_NUM_FORMAT; | |
| 1292 | - protected $_columnsFormat = array(); | |
| 1293 | - protected $_rowoffset = 1; | |
| 1294 | - protected $_coloffset = 1; | |
| 1283 | + protected string $_defaultEncoding = 'UTF-8'; | |
| 1284 | + protected string $_defaultFormat = SPREADSHEET_EXCEL_READER_DEF_NUM_FORMAT; | |
| 1285 | + protected array $_columnsFormat = array(); | |
| 1286 | + protected int $_rowoffset = 1; | |
| 1287 | + protected int $_coloffset = 1; | |
| 1295 | 1288 | |
| 1296 | 1289 | /** |
| 1297 | 1290 | * List of default date formats used by Excel |
| 1298 | 1291 | * |
| 1299 | 1292 | * @since 1.0.0 |
| 1300 | - * @var array | |
| 1301 | 1293 | */ |
| 1302 | - protected $dateFormats = array( | |
| 1294 | + protected array $dateFormats = array( | |
| 1303 | 1295 | 0xe => 'm/d/Y', |
| 1304 | 1296 | 0xf => 'M-d-Y', |
| 1305 | 1297 | 0x10 => 'd-M', |
| 1306 | 1298 | 0x11 => 'M-Y', |
| @@ -1317,11 +1309,10 @@ | ||
| 1317 | 1309 | /** |
| 1318 | 1310 | * Default number formats used by Excel |
| 1319 | 1311 | * |
| 1320 | 1312 | * @since 1.0.0 |
| 1321 | - * @var array | |
| 1322 | 1313 | */ |
| 1323 | - protected $numberFormats = array( | |
| 1314 | + protected array $numberFormats = array( | |
| 1324 | 1315 | 0x1 => '0', |
| 1325 | 1316 | 0x2 => '0.00', |
| 1326 | 1317 | 0x3 => '#,##0', |
| 1327 | 1318 | 0x4 => '#,##0.00', |
| @@ -1346,11 +1337,10 @@ | ||
| 1346 | 1337 | /** |
| 1347 | 1338 | * [$colors description] |
| 1348 | 1339 | * |
| 1349 | 1340 | * @since 1.0.0 |
| 1350 | - * @var array | |
| 1351 | 1341 | */ |
| 1352 | - protected $colors = array( | |
| 1342 | + protected array $colors = array( | |
| 1353 | 1343 | 0x00 => '#000000', |
| 1354 | 1344 | 0x01 => '#FFFFFF', |
| 1355 | 1345 | 0x02 => '#FF0000', |
| 1356 | 1346 | 0x03 => '#00FF00', |
| @@ -1428,11 +1418,10 @@ | ||
| 1428 | 1418 | /** |
| 1429 | 1419 | * [$lineStyles description] |
| 1430 | 1420 | * |
| 1431 | 1421 | * @since 1.0.0 |
| 1432 | - * @var array | |
| 1433 | 1422 | */ |
| 1434 | - protected $lineStyles = array( | |
| 1423 | + protected array $lineStyles = array( | |
| 1435 | 1424 | 0x00 => '', |
| 1436 | 1425 | 0x01 => 'Thin', |
| 1437 | 1426 | 0x02 => 'Medium', |
| 1438 | 1427 | 0x03 => 'Dashed', |
| @@ -1451,11 +1440,10 @@ | ||
| 1451 | 1440 | /** |
| 1452 | 1441 | * [$lineStylesCss description] |
| 1453 | 1442 | * |
| 1454 | 1443 | * @since 1.0.0 |
| 1455 | - * @var array | |
| 1456 | 1444 | */ |
| 1457 | - protected $lineStylesCss = array( | |
| 1445 | + protected array $lineStylesCss = array( | |
| 1458 | 1446 | 'Thin' => '1px solid', |
| 1459 | 1447 | 'Medium' => '2px solid', |
| 1460 | 1448 | 'Dashed' => '1px dashed', |
| 1461 | 1449 | 'Dotted' => '1px dotted', |
| @@ -1476,14 +1464,14 @@ | ||
| 1476 | 1464 | * @since 1.0.0 |
| 1477 | 1465 | * |
| 1478 | 1466 | * @param [type] $data [description] |
| 1479 | 1467 | * @param [type] $start [description] |
| 1480 | - * @return [type] [description] | |
| 1468 | + * @return string [description] | |
| 1481 | 1469 | */ |
| 1482 | - protected function read16bitstring( $data, $start ) { | |
| 1470 | + protected function read16bitstring( $data, $start ): string { | |
| 1483 | 1471 | $len = 0; |
| 1484 | 1472 | while ( ord( $data[ $start + $len ] ) + ord( $data[ $start + $len + 1 ] ) > 0 ) { |
| 1485 | - $len++; | |
| 1473 | + ++$len; | |
| 1486 | 1474 | } |
| 1487 | 1475 | return substr( $data, $start, $len ); |
| 1488 | 1476 | } |
| 1489 | 1477 | |
| @@ -1495,11 +1483,11 @@ | ||
| 1495 | 1483 | * |
| 1496 | 1484 | * @param [type] $format [description] |
| 1497 | 1485 | * @param [type] $num [description] |
| 1498 | 1486 | * @param [type] $f [description] |
| 1499 | - * @return [type] [description] | |
| 1487 | + * @return array<string, mixed> [description] | |
| 1500 | 1488 | */ |
| 1501 | - protected function _format_value( $format, $num, $f ) { | |
| 1489 | + protected function _format_value( $format, $num, $f ): array { | |
| 1502 | 1490 | // 49 = TEXT format |
| 1503 | 1491 | // https://code.google.com/archive/p/php-excel-reader/issues/7 |
| 1504 | 1492 | if ( ( ! $f && '%s' === $format ) || ( 49 === (int) $f ) || ( 'GENERAL' === $format ) ) { |
| 1505 | 1493 | return array( |
| @@ -1556,10 +1544,10 @@ | ||
| 1556 | 1544 | |
| 1557 | 1545 | // Handle the number itself. |
| 1558 | 1546 | $number_regex = '/(\d+)(\.?)(\d*)/'; |
| 1559 | 1547 | if ( preg_match( $number_regex, $pattern, $matches ) ) { |
| 1560 | - //$left = $matches[1]; | |
| 1561 | - //$dec = $matches[2]; | |
| 1548 | + // $left = $matches[1]; | |
| 1549 | + // $dec = $matches[2]; | |
| 1562 | 1550 | $right = $matches[3]; |
| 1563 | 1551 | if ( $has_commas ) { |
| 1564 | 1552 | $formatted = number_format( $num, strlen( $right ) ); |
| 1565 | 1553 | } else { |
| @@ -1607,9 +1595,9 @@ | ||
| 1607 | 1595 | * @since 1.0.0 |
| 1608 | 1596 | * |
| 1609 | 1597 | * @param [type] $encoding [description] |
| 1610 | 1598 | */ |
| 1611 | - public function setOutputEncoding( $encoding ) { | |
| 1599 | + public function setOutputEncoding( $encoding ): void { | |
| 1612 | 1600 | $this->_defaultEncoding = $encoding; |
| 1613 | 1601 | } |
| 1614 | 1602 | |
| 1615 | 1603 | /** |
| @@ -1621,9 +1609,9 @@ | ||
| 1621 | 1609 | * @since 1.0.0 |
| 1622 | 1610 | * |
| 1623 | 1611 | * @param string $encoder Optional. [description] |
| 1624 | 1612 | */ |
| 1625 | - public function setUTFEncoder( $encoder = 'iconv' ) { | |
| 1613 | + public function setUTFEncoder( $encoder = 'iconv' ): void { | |
| 1626 | 1614 | $this->_encoderFunction = ''; |
| 1627 | 1615 | if ( 'iconv' === $encoder ) { |
| 1628 | 1616 | $this->_encoderFunction = function_exists( 'iconv' ) ? 'iconv' : ''; |
| 1629 | 1617 | } elseif ( 'mb' === $encoder ) { |
| @@ -1637,9 +1625,9 @@ | ||
| 1637 | 1625 | * @since 1.0.0 |
| 1638 | 1626 | * |
| 1639 | 1627 | * @param [type] $iOffset [description] |
| 1640 | 1628 | */ |
| 1641 | - public function setRowColOffset( $iOffset ) { | |
| 1629 | + public function setRowColOffset( $iOffset ): void { | |
| 1642 | 1630 | $this->_rowoffset = $iOffset; |
| 1643 | 1631 | $this->_coloffset = $iOffset; |
| 1644 | 1632 | } |
| 1645 | 1633 | |
| @@ -1649,9 +1637,9 @@ | ||
| 1649 | 1637 | * @since 1.0.0 |
| 1650 | 1638 | * |
| 1651 | 1639 | * @param [type] $sFormat [description] |
| 1652 | 1640 | */ |
| 1653 | - public function setDefaultFormat( $sFormat ) { | |
| 1641 | + public function setDefaultFormat( $sFormat ): void { | |
| 1654 | 1642 | $this->_defaultFormat = $sFormat; |
| 1655 | 1643 | } |
| 1656 | 1644 | |
| 1657 | 1645 | /** |
| @@ -1661,9 +1649,9 @@ | ||
| 1661 | 1649 | * |
| 1662 | 1650 | * @param [type] $column [description] |
| 1663 | 1651 | * @param [type] $sFormat [description] |
| 1664 | 1652 | */ |
| 1665 | - public function setColumnFormat( $column, $sFormat ) { | |
| 1653 | + public function setColumnFormat( $column, $sFormat ): void { | |
| 1666 | 1654 | $this->_columnsFormat[ $column ] = $sFormat; |
| 1667 | 1655 | } |
| 1668 | 1656 | |
| 1669 | 1657 | /** |
| @@ -1670,12 +1658,11 @@ | ||
| 1670 | 1658 | * Read the spreadsheet file using OLE, then parse. |
| 1671 | 1659 | * |
| 1672 | 1660 | * @since 1.0.0 |
| 1673 | 1661 | * |
| 1674 | - * @param [type] $data [description] | |
| 1675 | - * @return [type] [description] | |
| 1662 | + * @param string $data [description] | |
| 1676 | 1663 | */ |
| 1677 | - public function read( $data ) { | |
| 1664 | + public function read( $data ): void { | |
| 1678 | 1665 | $res = $this->_ole->read( $data ); |
| 1679 | 1666 | |
| 1680 | 1667 | // oops, something goes wrong (Darko Miljanovic) |
| 1681 | 1668 | if ( false === $res ) { |
| @@ -1701,9 +1688,9 @@ | ||
| 1701 | 1688 | protected function _parse() { |
| 1702 | 1689 | $pos = 0; |
| 1703 | 1690 | $data = $this->data; |
| 1704 | 1691 | |
| 1705 | - //$code = $this->v( $data, $pos ); | |
| 1692 | + // $code = $this->v( $data, $pos ); | |
| 1706 | 1693 | $length = $this->v( $data, $pos + 2 ); |
| 1707 | 1694 | $version = $this->v( $data, $pos + 4 ); |
| 1708 | 1695 | $substreamType = $this->v( $data, $pos + 6 ); |
| 1709 | 1696 | if ( SPREADSHEET_EXCEL_READER_BIFF8 !== $version && SPREADSHEET_EXCEL_READER_BIFF7 !== $version ) { |
| @@ -1739,9 +1726,9 @@ | ||
| 1739 | 1726 | } |
| 1740 | 1727 | $numChars = ord( $data[ $spos ] ) | ( ord( $data[ $spos + 1 ] ) << 8 ); |
| 1741 | 1728 | $spos += 2; |
| 1742 | 1729 | $optionFlags = ord( $data[ $spos ] ); |
| 1743 | - $spos++; | |
| 1730 | + ++$spos; | |
| 1744 | 1731 | $asciiEncoding = ( 0 === ( $optionFlags & 0x01 ) ); |
| 1745 | 1732 | $extendedString = ( 0 !== ( $optionFlags & 0x04 ) ); |
| 1746 | 1733 | |
| 1747 | 1734 | // See if string contains formatting information. |
| @@ -1986,10 +1973,10 @@ | ||
| 1986 | 1973 | $this->nineteenFour = ( 1 === ord( $data[ $pos + 4 ] ) ); |
| 1987 | 1974 | break; |
| 1988 | 1975 | case SPREADSHEET_EXCEL_READER_TYPE_BOUNDSHEET: |
| 1989 | 1976 | $rec_offset = $this->_GetInt4d( $data, $pos + 4 ); |
| 1990 | - //$rec_typeFlag = ord( $data[ $pos + 8 ] ); | |
| 1991 | - //$rec_visibilityFlag = ord( $data[ $pos + 9 ] ); | |
| 1977 | + // $rec_typeFlag = ord( $data[ $pos + 8 ] ); | |
| 1978 | + // $rec_visibilityFlag = ord( $data[ $pos + 9 ] ); | |
| 1992 | 1979 | $rec_length = ord( $data[ $pos + 10 ] ); |
| 1993 | 1980 | |
| 1994 | 1981 | if ( SPREADSHEET_EXCEL_READER_BIFF8 === $version ) { |
| 1995 | 1982 | $chartype = ord( $data[ $pos + 11 ] ); |
| @@ -2164,10 +2151,10 @@ | ||
| 2164 | 2151 | break; |
| 2165 | 2152 | case SPREADSHEET_EXCEL_READER_TYPE_BOOLERR: |
| 2166 | 2153 | $row = ord( $data[ $spos ] ) | ord( $data[ $spos + 1 ] ) << 8; |
| 2167 | 2154 | $column = ord( $data[ $spos + 2 ] ) | ord( $data[ $spos + 3 ] ) << 8; |
| 2168 | - $string = ord( $data[ $spos + 6 ] ); | |
| 2169 | - $this->addcell( $row, $column, $string ); | |
| 2155 | + $a_string = ord( $data[ $spos + 6 ] ); | |
| 2156 | + $this->addcell( $row, $column, $a_string ); | |
| 2170 | 2157 | break; |
| 2171 | 2158 | case SPREADSHEET_EXCEL_READER_TYPE_STRING: |
| 2172 | 2159 | // https://code.google.com/archive/p/php-excel-reader/issues/4 |
| 2173 | 2160 | if ( SPREADSHEET_EXCEL_READER_BIFF8 === $version ) { |
| @@ -2175,9 +2162,9 @@ | ||
| 2175 | 2162 | $xpos = $spos; |
| 2176 | 2163 | $numChars = ord( $data[ $xpos ] ) | ( ord( $data[ $xpos + 1 ] ) << 8 ); |
| 2177 | 2164 | $xpos += 2; |
| 2178 | 2165 | $optionFlags = ord( $data[ $xpos ] ); |
| 2179 | - $xpos++; | |
| 2166 | + ++$xpos; | |
| 2180 | 2167 | $asciiEncoding = ( 0 === ( $optionFlags & 0x01 ) ); |
| 2181 | 2168 | $extendedString = ( 0 !== ( $optionFlags & 0x04 ) ); |
| 2182 | 2169 | // See if string contains formatting information |
| 2183 | 2170 | $richString = ( 0 !== ( $optionFlags & 0x08 ) ); |
| @@ -2312,9 +2299,9 @@ | ||
| 2312 | 2299 | * |
| 2313 | 2300 | * @param [type] $spos [description] |
| 2314 | 2301 | * @return bool [description] |
| 2315 | 2302 | */ |
| 2316 | - protected function isDate( $spos ) { | |
| 2303 | + protected function isDate( $spos ): bool { | |
| 2317 | 2304 | $xfindex = ord( $this->data[ $spos + 4 ] ) | ord( $this->data[ $spos + 5 ] ) << 8; |
| 2318 | 2305 | return ( 'date' === $this->xfRecords[ $xfindex ]['type'] ); |
| 2319 | 2306 | } |
| 2320 | 2307 | /** |
| @@ -2321,18 +2308,18 @@ | ||
| 2321 | 2308 | * [gmgetdate description] |
| 2322 | 2309 | * |
| 2323 | 2310 | * @since 1.0.0 |
| 2324 | 2311 | * |
| 2325 | - * @param [type] $ts Optional. [description] | |
| 2326 | - * @return [type] [description] | |
| 2312 | + * @param int $ts Optional. Timestamp. Defaults to current Unix timestamp. | |
| 2313 | + * @return array<string, string> [description] | |
| 2327 | 2314 | */ |
| 2328 | - protected function gmgetdate( $ts = null ) { | |
| 2315 | + protected function gmgetdate( $ts = null ): array { | |
| 2329 | 2316 | $k = array( 'seconds', 'minutes', 'hours', 'mday', 'wday', 'mon', 'year', 'yday', 'weekday', 'month', 0 ); |
| 2330 | 2317 | return array_combine( $k, explode( ':', gmdate( 's:i:G:j:w:n:Y:z:l:F:U', is_null( $ts ) ? time() : $ts ) ) ); |
| 2331 | 2318 | } |
| 2332 | 2319 | |
| 2333 | 2320 | /** |
| 2334 | - * Get the details for a particular cell | |
| 2321 | + * Gets the details for a particular cell. | |
| 2335 | 2322 | * |
| 2336 | 2323 | * @since 1.0.0 |
| 2337 | 2324 | * |
| 2338 | 2325 | * @param [type] $spos [description] |
| @@ -2337,11 +2324,11 @@ | ||
| 2337 | 2324 | * |
| 2338 | 2325 | * @param [type] $spos [description] |
| 2339 | 2326 | * @param [type] $numValue [description] |
| 2340 | 2327 | * @param [type] $column [description] |
| 2341 | - * @return [type] [description] | |
| 2328 | + * @return array<string, mixed> [description] | |
| 2342 | 2329 | */ |
| 2343 | - protected function _getCellDetails( $spos, $numValue, $column ) { | |
| 2330 | + protected function _getCellDetails( $spos, $numValue, $column ): array { | |
| 2344 | 2331 | $xfindex = ord( $this->data[ $spos + 4 ] ) | ord( $this->data[ $spos + 5 ] ) << 8; |
| 2345 | 2332 | $xfrecord = $this->xfRecords[ $xfindex ]; |
| 2346 | 2333 | $type = $xfrecord['type']; |
| 2347 | 2334 | |
| @@ -2367,15 +2354,15 @@ | ||
| 2367 | 2354 | |
| 2368 | 2355 | $totalseconds = floor( SPREADSHEET_EXCEL_READER_MSINADAY * $fractionalDay ); |
| 2369 | 2356 | $secs = $totalseconds % 60; |
| 2370 | 2357 | $totalseconds -= $secs; |
| 2371 | - $hours = (int) floor( $totalseconds / ( 60 * 60 ) ); | |
| 2372 | - $mins = (int) floor( $totalseconds / 60 ) % 60; | |
| 2373 | - $string = date( $format, mktime( $hours, $mins, $secs, $dateinfo['mon'], $dateinfo['mday'], $dateinfo['year'] ) ); | |
| 2358 | + $hours = intdiv( $totalseconds, 60 * 60 ); | |
| 2359 | + $mins = intdiv( $totalseconds, 60 ) % 60; | |
| 2360 | + $a_string = date( $format, mktime( $hours, $mins, $secs, $dateinfo['mon'], $dateinfo['mday'], $dateinfo['year'] ) ); | |
| 2374 | 2361 | } elseif ( 'number' === $type ) { |
| 2375 | 2362 | $rectype = 'number'; |
| 2376 | 2363 | $formatted = $this->_format_value( $format, $numValue, $formatIndex ); |
| 2377 | - $string = $formatted['string']; | |
| 2364 | + $a_string = $formatted['string']; | |
| 2378 | 2365 | $formatColor = $formatted['formatColor']; |
| 2379 | 2366 | $raw = $numValue; |
| 2380 | 2367 | } else { |
| 2381 | 2368 | if ( '' === $format ) { |
| @@ -2382,9 +2369,9 @@ | ||
| 2382 | 2369 | $format = $this->_defaultFormat; |
| 2383 | 2370 | } |
| 2384 | 2371 | $rectype = 'unknown'; |
| 2385 | 2372 | $formatted = $this->_format_value( $format, $numValue, $formatIndex ); |
| 2386 | - $string = $formatted['string']; | |
| 2373 | + $a_string = $formatted['string']; | |
| 2387 | 2374 | $formatColor = $formatted['formatColor']; |
| 2388 | 2375 | $raw = $numValue; |
| 2389 | 2376 | } |
| 2390 | 2377 | |
| @@ -2431,12 +2418,12 @@ | ||
| 2431 | 2418 | * [addcell description] |
| 2432 | 2419 | * |
| 2433 | 2420 | * @since 1.0.0 |
| 2434 | 2421 | * |
| 2435 | - * @param [type] $row [description] | |
| 2436 | - * @param [type] $col [description] | |
| 2437 | - * @param [type] $string [description] | |
| 2438 | - * @param [type] $info Optional. [description] | |
| 2422 | + * @param [type] $row [description] | |
| 2423 | + * @param [type] $col [description] | |
| 2424 | + * @param [type] $a_string [description] | |
| 2425 | + * @param array<string, mixed> $info Optional. [description] | |
| 2439 | 2426 | * @return [type] [description] |
| 2440 | 2427 | */ |
| 2441 | 2428 | protected function addcell( $row, $col, $string, $info = null ) { |
| 2442 | 2429 | $this->sheets[ $this->sn ]['maxrow'] = max( $this->sheets[ $this->sn ]['maxrow'], $row + $this->_rowoffset ); |
| @@ -2484,19 +2471,19 @@ | ||
| 2484 | 2471 | * [_encodeUTF16 description] |
| 2485 | 2472 | * |
| 2486 | 2473 | * @since 1.0.0 |
| 2487 | 2474 | * |
| 2488 | - * @param [type] $string [description] | |
| 2475 | + * @param [type] $a_string [description] | |
| 2489 | 2476 | * @return [type] [description] |
| 2490 | 2477 | */ |
| 2491 | - protected function _encodeUTF16( $string ) { | |
| 2478 | + protected function _encodeUTF16( $a_string ) { | |
| 2492 | 2479 | if ( $this->_defaultEncoding ) { |
| 2493 | 2480 | switch ( $this->_encoderFunction ) { |
| 2494 | 2481 | case 'iconv': |
| 2495 | - $string = iconv( 'UTF-16LE', $this->_defaultEncoding, $string ); | |
| 2482 | + $a_string = iconv( 'UTF-16LE', $this->_defaultEncoding, $a_string ); | |
| 2496 | 2483 | break; |
| 2497 | 2484 | case 'mb_convert_encoding': |
| 2498 | - $string = mb_convert_encoding( $string, $this->_defaultEncoding, 'UTF-16LE' ); | |
| 2485 | + $a_string = mb_convert_encoding( $string, $this->_defaultEncoding, 'UTF-16LE' ); | |
| 2499 | 2486 | break; |
| 2500 | 2487 | } |
| 2501 | 2488 | } |
| 2502 | 2489 | return $string; |
| @@ -2508,11 +2495,11 @@ | ||
| 2508 | 2495 | * @since 1.0.0 |
| 2509 | 2496 | * |
| 2510 | 2497 | * @param [type] $data [description] |
| 2511 | 2498 | * @param [type] $pos [description] |
| 2512 | - * @return [type] [description] | |
| 2499 | + * @return int [description] | |
| 2513 | 2500 | */ |
| 2514 | - protected function _GetInt4d( $data, $pos ) { | |
| 2501 | + protected function _GetInt4d( $data, $pos ): int { | |
| 2515 | 2502 | $value = ord( $data[ $pos ] ) | ( ord( $data[ $pos + 1 ] ) << 8 ) | ( ord( $data[ $pos + 2 ] ) << 16 ) | ( ord( $data[ $pos + 3 ] ) << 24 ); |
| 2516 | 2503 | if ( $value >= 4294967294 ) { |
| 2517 | 2504 | $value = -2; |
| 2518 | 2505 | } |
| @@ -2525,11 +2512,11 @@ | ||
| 2525 | 2512 | * @since 1.0.0 |
| 2526 | 2513 | * |
| 2527 | 2514 | * @param [type] $data [description] |
| 2528 | 2515 | * @param [type] $pos [description] |
| 2529 | - * @return [type] [description] | |
| 2516 | + * @return int [description] | |
| 2530 | 2517 | */ |
| 2531 | - protected function v( $data, $pos ) { | |
| 2518 | + protected function v( $data, $pos ): int { | |
| 2532 | 2519 | return ord( $data[ $pos ] ) | ord( $data[ $pos + 1 ] ) << 8; |
| 2533 | 2520 | } |
| 2534 | 2521 | |
| 2535 | 2522 | } // class Spreadsheet_Excel_Reader |