Skip to content

Commit f2ea8b6

Browse files
Fix PHPStan type safety issues in DimensionsRecordTest
Add proper type assertions to handle potential false returns: - Assert file_get_contents() returns string, not false - Assert strpos() returns int, not false - Assert unpack() returns array, not false This resolves all 7 PHPStan errors reported in CI while maintaining test functionality (12 assertions, all passing).
1 parent b9857e5 commit f2ea8b6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tests/PhpSpreadsheetTests/Writer/Xls/DimensionsRecordTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,22 @@ public function testDimensionsRecordUsesZeroBasedColumnIndices(): void
4545

4646
// Read the binary file and find the DIMENSIONS record
4747
$fileContent = file_get_contents($filename);
48+
self::assertIsString($fileContent, 'Failed to read XLS file');
4849
unlink($filename);
4950

5051
// Find the DIMENSIONS record: 0x0200 (2 bytes) + length 0x000E (2 bytes)
5152
$recordSignature = pack('v', 0x0200) . pack('v', 0x000E);
5253
$pos = strpos($fileContent, $recordSignature);
5354

54-
self::assertNotFalse($pos, 'DIMENSIONS record not found in XLS file');
55+
self::assertIsInt($pos, 'DIMENSIONS record not found in XLS file');
5556

5657
// Parse the DIMENSIONS record (skip 4-byte header)
5758
$dataPos = $pos + 4;
5859
$dimensionsData = substr($fileContent, $dataPos, 14);
5960

6061
// Unpack DIMENSIONS record
6162
$data = unpack('VrwMic/VrwMac/vcolMic/vcolMac/vreserved', $dimensionsData);
63+
self::assertIsArray($data, 'Failed to unpack DIMENSIONS record');
6264

6365
// Verify the values are correct (0-based for columns, 1-based for rows)
6466
// First used row is 1
@@ -100,20 +102,22 @@ public function testDimensionsRecordCapsColumnIndexAt255(): void
100102

101103
// Read the binary file and find the DIMENSIONS record
102104
$fileContent = file_get_contents($filename);
105+
self::assertIsString($fileContent, 'Failed to read XLS file');
103106
unlink($filename);
104107

105108
// Find the DIMENSIONS record: 0x0200 (2 bytes) + length 0x000E (2 bytes)
106109
$recordSignature = pack('v', 0x0200) . pack('v', 0x000E);
107110
$pos = strpos($fileContent, $recordSignature);
108111

109-
self::assertNotFalse($pos, 'DIMENSIONS record not found in XLS file');
112+
self::assertIsInt($pos, 'DIMENSIONS record not found in XLS file');
110113

111114
// Parse the DIMENSIONS record (skip 4-byte header)
112115
$dataPos = $pos + 4;
113116
$dimensionsData = substr($fileContent, $dataPos, 14);
114117

115118
// Unpack DIMENSIONS record
116119
$data = unpack('VrwMic/VrwMac/vcolMic/vcolMac/vreserved', $dimensionsData);
120+
self::assertIsArray($data, 'Failed to unpack DIMENSIONS record');
117121

118122
// Last column should be capped at 256 (255 + 1 for "last used + 1")
119123
// The min(255, ...) ensures we don't exceed the BIFF8 limit

0 commit comments

Comments
 (0)