mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-30 03:59:11 +00:00
Slight Increase in Coverage Reading BIFF8
After breaking up Xls Reader (PR #4118), it is a little easier to identify uncovered code. BIFF8 had no tests involving constant arrays. This PR adds some. Most of the work is in the tests, but some source code is modernized to use things like null coercion.
This commit is contained in:
@@ -24,12 +24,6 @@ class Color
|
||||
return $palette[$color - 8];
|
||||
}
|
||||
|
||||
// default color table
|
||||
if ($version == Xls::XLS_BIFF8) {
|
||||
return Color\BIFF8::lookup($color);
|
||||
}
|
||||
|
||||
// BIFF5
|
||||
return Color\BIFF5::lookup($color);
|
||||
return ($version === Xls::XLS_BIFF8) ? Color\BIFF8::lookup($color) : Color\BIFF5::lookup($color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,20 +36,12 @@ class ConditionalFormatting extends Xls
|
||||
|
||||
public static function type(int $type): ?string
|
||||
{
|
||||
if (isset(self::$types[$type])) {
|
||||
return self::$types[$type];
|
||||
}
|
||||
|
||||
return null;
|
||||
return self::$types[$type] ?? null;
|
||||
}
|
||||
|
||||
public static function operator(int $operator): ?string
|
||||
{
|
||||
if (isset(self::$operators[$operator])) {
|
||||
return self::$operators[$operator];
|
||||
}
|
||||
|
||||
return null;
|
||||
return self::$operators[$operator] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,29 +48,17 @@ class DataValidationHelper extends Xls
|
||||
|
||||
public static function type(int $type): ?string
|
||||
{
|
||||
if (isset(self::$types[$type])) {
|
||||
return self::$types[$type];
|
||||
}
|
||||
|
||||
return null;
|
||||
return self::$types[$type] ?? null;
|
||||
}
|
||||
|
||||
public static function errorStyle(int $errorStyle): ?string
|
||||
{
|
||||
if (isset(self::$errorStyles[$errorStyle])) {
|
||||
return self::$errorStyles[$errorStyle];
|
||||
}
|
||||
|
||||
return null;
|
||||
return self::$errorStyles[$errorStyle] ?? null;
|
||||
}
|
||||
|
||||
public static function operator(int $operator): ?string
|
||||
{
|
||||
if (isset(self::$operators[$operator])) {
|
||||
return self::$operators[$operator];
|
||||
}
|
||||
|
||||
return null;
|
||||
return self::$operators[$operator] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,12 +44,10 @@ class ListFunctions extends Xls
|
||||
}
|
||||
|
||||
foreach ($xls->sheets as $sheet) {
|
||||
if ($sheet['sheetType'] != 0x00) {
|
||||
if ($sheet['sheetType'] === 0x00) {
|
||||
// 0x00: Worksheet, 0x02: Chart, 0x06: Visual Basic module
|
||||
continue;
|
||||
$worksheetNames[] = $sheet['name'];
|
||||
}
|
||||
|
||||
$worksheetNames[] = $sheet['name'];
|
||||
}
|
||||
|
||||
return $worksheetNames;
|
||||
@@ -93,7 +91,7 @@ class ListFunctions extends Xls
|
||||
|
||||
// Parse the individual sheets
|
||||
foreach ($xls->sheets as $sheet) {
|
||||
if ($sheet['sheetType'] != 0x00) {
|
||||
if ($sheet['sheetType'] !== 0x00) {
|
||||
// 0x00: Worksheet
|
||||
// 0x02: Chart
|
||||
// 0x06: Visual Basic module
|
||||
|
||||
@@ -28,10 +28,6 @@ class Border
|
||||
|
||||
public static function lookup(int $index): string
|
||||
{
|
||||
if (isset(self::$borderStyleMap[$index])) {
|
||||
return self::$borderStyleMap[$index];
|
||||
}
|
||||
|
||||
return StyleBorder::BORDER_NONE;
|
||||
return self::$borderStyleMap[$index] ?? StyleBorder::BORDER_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,10 +37,6 @@ class FillPattern
|
||||
*/
|
||||
public static function lookup(int $index): string
|
||||
{
|
||||
if (isset(self::$fillPatternMap[$index])) {
|
||||
return self::$fillPatternMap[$index];
|
||||
}
|
||||
|
||||
return Fill::FILL_NONE;
|
||||
return self::$fillPatternMap[$index] ?? Fill::FILL_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xls;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class Biff8CoverTest extends TestCase
|
||||
{
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
|
||||
}
|
||||
|
||||
public function testBiff8Coverage(): void
|
||||
{
|
||||
$filename = 'tests/data/Reader/XLS/biff8cover.xls';
|
||||
$reader = new Xls();
|
||||
$spreadsheet = $reader->load($filename);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
self::assertSame('=SUM({1;2;3;4;5})', $sheet->getCell('A1')->getValue());
|
||||
self::assertSame(15, $sheet->getCell('A1')->getCalculatedValue());
|
||||
self::assertSame(
|
||||
'=VLOOKUP("hello",'
|
||||
. '{"what",1;"why",TRUE;"hello","there";"when",FALSE}'
|
||||
. ',2,FALSE)',
|
||||
$sheet->getCell('C1')->getValue()
|
||||
);
|
||||
self::assertSame('there', $sheet->getCell('C1')->getCalculatedValue());
|
||||
self::assertSame(2, $sheet->getCell('A3')->getValue());
|
||||
self::assertTrue(
|
||||
$sheet->getStyle('A3')->getFont()->getSuperscript()
|
||||
);
|
||||
self::assertSame('n', $sheet->getCell('B3')->getValue());
|
||||
self::assertTrue(
|
||||
$sheet->getStyle('B3')->getFont()->getSubscript()
|
||||
);
|
||||
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user