Leverage type hinting to assert array parameters
This commit is contained in:
parent
033a4bdad5
commit
06ca8f9b04
|
@ -709,10 +709,10 @@ class Cell
|
|||
*
|
||||
* @return string String representation of $pRange
|
||||
*/
|
||||
public static function buildRange($pRange)
|
||||
public static function buildRange(array $pRange)
|
||||
{
|
||||
// Verify range
|
||||
if (!is_array($pRange) || empty($pRange) || !is_array($pRange[0])) {
|
||||
if (empty($pRange) || !is_array($pRange[0])) {
|
||||
throw new Exception('Range does not contain any information');
|
||||
}
|
||||
|
||||
|
|
|
@ -84,13 +84,9 @@ class IOFactory
|
|||
*
|
||||
* @throws Reader\Exception
|
||||
*/
|
||||
public static function setSearchLocations($value)
|
||||
public static function setSearchLocations(array $value)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
self::$searchLocations = $value;
|
||||
} else {
|
||||
throw new Reader\Exception('Invalid parameter passed.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -462,12 +462,8 @@ class HeaderFooter
|
|||
*
|
||||
* @return HeaderFooter
|
||||
*/
|
||||
public function setImages($images)
|
||||
public function setImages(array $images)
|
||||
{
|
||||
if (!is_array($images)) {
|
||||
throw new \PhpOffice\PhpSpreadsheet\Exception('Invalid parameter!');
|
||||
}
|
||||
|
||||
$this->headerFooterImages = $images;
|
||||
|
||||
return $this;
|
||||
|
|
|
@ -1172,15 +1172,14 @@ class Html extends BaseWriter implements IWriter
|
|||
* @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet \PhpOffice\PhpSpreadsheet\Worksheet
|
||||
* @param array $pValues Array containing cells in a row
|
||||
* @param int $pRow Row number (0-based)
|
||||
* @param mixed $cellType
|
||||
* @param mixed $cellType eg: 'td'
|
||||
*
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateRow(\PhpOffice\PhpSpreadsheet\Worksheet $pSheet, $pValues = null, $pRow = 0, $cellType = 'td')
|
||||
private function generateRow(\PhpOffice\PhpSpreadsheet\Worksheet $pSheet, array $pValues, $pRow, $cellType)
|
||||
{
|
||||
if (is_array($pValues)) {
|
||||
// Construct HTML
|
||||
$html = '';
|
||||
|
||||
|
@ -1418,8 +1417,6 @@ class Html extends BaseWriter implements IWriter
|
|||
// Return
|
||||
return $html;
|
||||
}
|
||||
throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Invalid parameters passed.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes array where of CSS properties / values and converts to CSS string.
|
||||
|
|
|
@ -210,7 +210,7 @@ class ContentTypes extends WriterPart
|
|||
*
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||
*/
|
||||
private function writeDefaultContentType(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter = null, $pPartname = '', $pContentType = '')
|
||||
private function writeDefaultContentType(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $pPartname, $pContentType)
|
||||
{
|
||||
if ($pPartname != '' && $pContentType != '') {
|
||||
// Write content type
|
||||
|
@ -232,7 +232,7 @@ class ContentTypes extends WriterPart
|
|||
*
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||
*/
|
||||
private function writeOverrideContentType(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter = null, $pPartname = '', $pContentType = '')
|
||||
private function writeOverrideContentType(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $pPartname, $pContentType)
|
||||
{
|
||||
if ($pPartname != '' && $pContentType != '') {
|
||||
// Write content type
|
||||
|
|
|
@ -163,7 +163,7 @@ class Drawing extends WriterPart
|
|||
*
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||
*/
|
||||
public function writeDrawing(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter = null, \PhpOffice\PhpSpreadsheet\Worksheet\BaseDrawing $pDrawing = null, $pRelationId = -1)
|
||||
public function writeDrawing(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet\BaseDrawing $pDrawing, $pRelationId = -1)
|
||||
{
|
||||
if ($pRelationId >= 0) {
|
||||
// xdr:oneCellAnchor
|
||||
|
@ -271,54 +271,6 @@ class Drawing extends WriterPart
|
|||
|
||||
$objWriter->endElement();
|
||||
}
|
||||
/*
|
||||
|
||||
// a:scene3d
|
||||
$objWriter->startElement('a:scene3d');
|
||||
|
||||
// a:camera
|
||||
$objWriter->startElement('a:camera');
|
||||
$objWriter->writeAttribute('prst', 'orthographicFront');
|
||||
$objWriter->endElement();
|
||||
|
||||
// a:lightRig
|
||||
$objWriter->startElement('a:lightRig');
|
||||
$objWriter->writeAttribute('rig', 'twoPt');
|
||||
$objWriter->writeAttribute('dir', 't');
|
||||
|
||||
// a:rot
|
||||
$objWriter->startElement('a:rot');
|
||||
$objWriter->writeAttribute('lat', '0');
|
||||
$objWriter->writeAttribute('lon', '0');
|
||||
$objWriter->writeAttribute('rev', '0');
|
||||
$objWriter->endElement();
|
||||
|
||||
$objWriter->endElement();
|
||||
|
||||
$objWriter->endElement();
|
||||
*/
|
||||
/*
|
||||
// a:sp3d
|
||||
$objWriter->startElement('a:sp3d');
|
||||
|
||||
// a:bevelT
|
||||
$objWriter->startElement('a:bevelT');
|
||||
$objWriter->writeAttribute('w', '25400');
|
||||
$objWriter->writeAttribute('h', '19050');
|
||||
$objWriter->endElement();
|
||||
|
||||
// a:contourClr
|
||||
$objWriter->startElement('a:contourClr');
|
||||
|
||||
// a:srgbClr
|
||||
$objWriter->startElement('a:srgbClr');
|
||||
$objWriter->writeAttribute('val', 'FFFFFF');
|
||||
$objWriter->endElement();
|
||||
|
||||
$objWriter->endElement();
|
||||
|
||||
$objWriter->endElement();
|
||||
*/
|
||||
$objWriter->endElement();
|
||||
|
||||
$objWriter->endElement();
|
||||
|
|
|
@ -397,7 +397,7 @@ class Rels extends WriterPart
|
|||
*
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||
*/
|
||||
private function writeRelationship(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
|
||||
private function writeRelationship(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $pId, $pType, $pTarget, $pTargetMode = '')
|
||||
{
|
||||
if ($pType != '' && $pTarget != '') {
|
||||
// Write relationship
|
||||
|
|
|
@ -241,7 +241,7 @@ class Workbook extends WriterPart
|
|||
*
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||
*/
|
||||
private function writeSheet(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $pSheetname = '', $pSheetId = 1, $pRelId = 1, $sheetState = 'visible')
|
||||
private function writeSheet(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $pSheetname, $pSheetId = 1, $pRelId = 1, $sheetState = 'visible')
|
||||
{
|
||||
if ($pSheetname != '') {
|
||||
// Write sheet
|
||||
|
|
|
@ -978,9 +978,8 @@ class Worksheet extends WriterPart
|
|||
*
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||
*/
|
||||
private function writeSheetData(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter = null, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet = null, $pStringTable = null)
|
||||
private function writeSheetData(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet, array $pStringTable)
|
||||
{
|
||||
if (is_array($pStringTable)) {
|
||||
// Flipped stringtable, for faster index searching
|
||||
$aFlippedStringTable = $this->getParentWriter()->getWriterPart('stringtable')->flipStringTable($pStringTable);
|
||||
|
||||
|
@ -1045,7 +1044,7 @@ class Worksheet extends WriterPart
|
|||
if (isset($cellsByRow[$currentRow])) {
|
||||
foreach ($cellsByRow[$currentRow] as $cellAddress) {
|
||||
// Write cell
|
||||
$this->writeCell($objWriter, $pSheet, $cellAddress, $pStringTable, $aFlippedStringTable);
|
||||
$this->writeCell($objWriter, $pSheet, $cellAddress, $aFlippedStringTable);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1055,9 +1054,6 @@ class Worksheet extends WriterPart
|
|||
}
|
||||
|
||||
$objWriter->endElement();
|
||||
} else {
|
||||
throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Invalid parameters passed.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1071,9 +1067,8 @@ class Worksheet extends WriterPart
|
|||
*
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||
*/
|
||||
private function writeCell(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter = null, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet = null, $pCellAddress = null, $pStringTable = null, $pFlippedStringTable = null)
|
||||
private function writeCell(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet, $pCellAddress, array $pFlippedStringTable)
|
||||
{
|
||||
if (is_array($pStringTable) && is_array($pFlippedStringTable)) {
|
||||
// Cell
|
||||
$pCell = $pSheet->getCell($pCellAddress);
|
||||
$objWriter->startElement('c');
|
||||
|
@ -1175,9 +1170,6 @@ class Worksheet extends WriterPart
|
|||
}
|
||||
|
||||
$objWriter->endElement();
|
||||
} else {
|
||||
throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Invalid parameters passed.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -223,18 +223,17 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
return require 'data/CellBuildRange.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \TypeError
|
||||
*/
|
||||
public function testBuildRangeInvalid()
|
||||
{
|
||||
$cellRange = '';
|
||||
try {
|
||||
Cell::buildRange($cellRange);
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf(Exception::class, $e);
|
||||
$this->assertEquals($e->getMessage(), 'Range does not contain any information');
|
||||
|
||||
return;
|
||||
if (PHP_MAJOR_VERSION < 7) {
|
||||
$this->markTestSkipped('Cannot catch type hinting error with PHP 5.6');
|
||||
}
|
||||
$this->fail('An expected exception has not been raised.');
|
||||
|
||||
$cellRange = '';
|
||||
Cell::buildRange($cellRange);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue