phpstan-conditional.php 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. $config = [];
  3. if (PHP_VERSION_ID < 80000) {
  4. // GdImage not available before PHP8
  5. $config['parameters']['ignoreErrors'][] = [
  6. 'message' => '~^Method .* has invalid return type GdImage\.$~',
  7. 'path' => __DIR__ . '/src/PhpSpreadsheet/Shared/Drawing.php',
  8. 'count' => 1,
  9. ];
  10. $config['parameters']['ignoreErrors'][] = [
  11. 'message' => '~^Property .* has unknown class GdImage as its type\.$~',
  12. 'path' => __DIR__ . '/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php',
  13. 'count' => 1,
  14. ];
  15. $config['parameters']['ignoreErrors'][] = [
  16. 'message' => '~^Method .* has invalid return type GdImage\.$~',
  17. 'path' => __DIR__ . '/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php',
  18. 'count' => 1,
  19. ];
  20. $config['parameters']['ignoreErrors'][] = [
  21. 'message' => '~^Parameter .* of method .* has invalid type GdImage\.$~',
  22. 'path' => __DIR__ . '/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php',
  23. 'count' => 1,
  24. ];
  25. $config['parameters']['ignoreErrors'][] = [
  26. 'message' => '~^Class GdImage not found\.$~',
  27. 'path' => __DIR__ . '/src/PhpSpreadsheet/Writer/Xls/Worksheet.php',
  28. 'count' => 1,
  29. ];
  30. $config['parameters']['ignoreErrors'][] = [
  31. 'message' => '~^Parameter .* of method .* has invalid type GdImage\.$~',
  32. 'path' => __DIR__ . '/src/PhpSpreadsheet/Writer/Xls/Worksheet.php',
  33. 'count' => 1,
  34. ];
  35. // GdImage with Phpstan 1.9.2
  36. $config['parameters']['ignoreErrors'][] = [
  37. 'message' => '~Class GdImage not found.*$~',
  38. 'path' => __DIR__ . '/tests/PhpSpreadsheetTests/Worksheet/MemoryDrawingTest.php',
  39. 'count' => 3,
  40. ];
  41. // Erroneous analysis by Phpstan before PHP8 - 3rd parameter is nullable
  42. // Fixed for Php7 with Phpstan 1.9.
  43. //$config['parameters']['ignoreErrors'][] = [
  44. // 'message' => '#^Parameter \\#3 \\$namespace of method XMLWriter\\:\\:startElementNs\\(\\) expects string, null given\\.$#',
  45. // 'path' => __DIR__ . '/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php',
  46. // 'count' => 8,
  47. //];
  48. // Erroneous analysis by Phpstan before PHP8 - mb_strlen does not return false
  49. $config['parameters']['ignoreErrors'][] = [
  50. 'message' => '#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:countCharacters\\(\\) should return int but returns int(<0, max>)?\\|false\\.$#',
  51. 'path' => __DIR__ . '/src/PhpSpreadsheet/Shared/StringHelper.php',
  52. 'count' => 1,
  53. ];
  54. // New with Phpstan 1.9.2 for Php7 only
  55. $config['parameters']['ignoreErrors'][] = [
  56. 'message' => '#^Parameter \\#2 \\.\\.\\.\\$args of function array_merge expects array, array<int, mixed>\\|false given.$#',
  57. 'path' => __DIR__ . '/src/PhpSpreadsheet/Calculation/LookupRef/Sort.php',
  58. 'count' => 1,
  59. ];
  60. $config['parameters']['ignoreErrors'][] = [
  61. 'message' => '#^Parameter \\#1 \\$input of function array_chunk expects array, array<int, float\\|int>\\|false given.$#',
  62. 'path' => __DIR__ . '/src/PhpSpreadsheet/Calculation/MathTrig/MatrixFunctions.php',
  63. 'count' => 1,
  64. ];
  65. $config['parameters']['ignoreErrors'][] = [
  66. 'message' => '#^Parameter \\#2 \\$array of function array_map expects array, array<int, float|int>\\|false given.$#',
  67. 'path' => __DIR__ . '/src/PhpSpreadsheet/Calculation/MathTrig/Random.php',
  68. 'count' => 1,
  69. ];
  70. $config['parameters']['ignoreErrors'][] = [
  71. 'message' => '#^Parameter \\#2 \\.\\.\\.\\$args of function array_merge expects array, array<int, mixed>\\|false given.$#',
  72. 'path' => __DIR__ . '/src/PhpSpreadsheet/Calculation/TextData/Text.php',
  73. 'count' => 1,
  74. ];
  75. } else {
  76. // Flagged in Php8+ - unsure how to correct code
  77. $config['parameters']['ignoreErrors'][] = [
  78. 'message' => '#^Binary operation "/" between float and array[|]float[|]int[|]string results in an error.#',
  79. 'path' => __DIR__ . '/src/PhpSpreadsheet/Calculation/MathTrig/Combinations.php',
  80. 'count' => 1,
  81. ];
  82. }
  83. return $config;