Minor improvements (#1029)

* Another collection of minor improvements

* Fix broken test

* And style

* Seriously?!? The order of returned types declared in a docblock is majorly important?
This commit is contained in:
Mark Baker 2019-06-22 23:15:14 +02:00 committed by GitHub
parent 2adaad3b01
commit 1b00fac6ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 88 additions and 81 deletions

View File

@ -523,7 +523,7 @@ class Cell
/** /**
* If this cell is in a merge range, then return the range. * If this cell is in a merge range, then return the range.
* *
* @return string * @return false|string
*/ */
public function getMergeRange() public function getMergeRange()
{ {

View File

@ -157,14 +157,12 @@ abstract class Coordinate
} }
// Build range // Build range
$imploded = [];
$counter = count($pRange); $counter = count($pRange);
for ($i = 0; $i < $counter; ++$i) { for ($i = 0; $i < $counter; ++$i) {
$pRange[$i] = implode(':', $pRange[$i]); $pRange[$i] = implode(':', $pRange[$i]);
} }
$imploded = implode(',', $pRange);
return $imploded; return implode(',', $pRange);
} }
/** /**

View File

@ -241,7 +241,7 @@ class Cells
*/ */
public function getHighestColumn($row = null) public function getHighestColumn($row = null)
{ {
if ($row == null) { if ($row === null) {
$colRow = $this->getHighestRowAndColumn(); $colRow = $this->getHighestRowAndColumn();
return $colRow['column']; return $colRow['column'];
@ -272,7 +272,7 @@ class Cells
*/ */
public function getHighestRow($column = null) public function getHighestRow($column = null)
{ {
if ($column == null) { if ($column === null) {
$colRow = $this->getHighestRowAndColumn(); $colRow = $this->getHighestRowAndColumn();
return $colRow['row']; return $colRow['row'];

View File

@ -143,7 +143,7 @@ class Csv extends BaseReader
return; return;
} }
return $this->skipBOM(); $this->skipBOM();
} }
/** /**
@ -184,8 +184,9 @@ class Csv extends BaseReader
// If number of lines is 0, nothing to infer : fall back to the default // If number of lines is 0, nothing to infer : fall back to the default
if ($numberLines === 0) { if ($numberLines === 0) {
$this->delimiter = reset($potentialDelimiters); $this->delimiter = reset($potentialDelimiters);
$this->skipBOM();
return $this->skipBOM(); return;
} }
// Calculate the mean square deviations for each delimiter (ignoring delimiters that haven't been found consistently) // Calculate the mean square deviations for each delimiter (ignoring delimiters that haven't been found consistently)
@ -230,7 +231,7 @@ class Csv extends BaseReader
$this->delimiter = reset($potentialDelimiters); $this->delimiter = reset($potentialDelimiters);
} }
return $this->skipBOM(); $this->skipBOM();
} }
/** /**

View File

@ -52,7 +52,7 @@ class Ods extends BaseReader
$stat = $zip->statName('mimetype'); $stat = $zip->statName('mimetype');
if ($stat && ($stat['size'] <= 255)) { if ($stat && ($stat['size'] <= 255)) {
$mimeType = $zip->getFromName($stat['name']); $mimeType = $zip->getFromName($stat['name']);
} elseif ($stat = $zip->statName('META-INF/manifest.xml')) { } elseif ($zip->statName('META-INF/manifest.xml')) {
$xml = simplexml_load_string( $xml = simplexml_load_string(
$this->securityScanner->scan($zip->getFromName('META-INF/manifest.xml')), $this->securityScanner->scan($zip->getFromName('META-INF/manifest.xml')),
'SimpleXMLElement', 'SimpleXMLElement',
@ -513,7 +513,7 @@ class Ods extends BaseReader
foreach ($paragraphs as $pData) { foreach ($paragraphs as $pData) {
$dataArray[] = $this->scanElementForText($pData); $dataArray[] = $this->scanElementForText($pData);
} }
$allCellDataText = implode($dataArray, "\n"); $allCellDataText = implode("\n", $dataArray);
$type = $cellData->getAttributeNS($officeNs, 'value-type'); $type = $cellData->getAttributeNS($officeNs, 'value-type');
@ -580,12 +580,12 @@ class Ods extends BaseReader
); );
$dataValue = Date::formattedPHPToExcel( $dataValue = Date::formattedPHPToExcel(
$year, (int) $year,
$month, (int) $month,
$day, (int) $day,
$hour, (int) $hour,
$minute, (int) $minute,
$second (int) $second
); );
if ($dataValue != floor($dataValue)) { if ($dataValue != floor($dataValue)) {

View File

@ -82,13 +82,10 @@ class ReferenceHelper
*/ */
public static function cellSort($a, $b) public static function cellSort($a, $b)
{ {
$ac = $bc = '';
$ar = $br = 0;
sscanf($a, '%[A-Z]%d', $ac, $ar); sscanf($a, '%[A-Z]%d', $ac, $ar);
sscanf($b, '%[A-Z]%d', $bc, $br); sscanf($b, '%[A-Z]%d', $bc, $br);
if ($ar == $br) { if ($ar === $br) {
return strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc); return strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc);
} }
@ -106,13 +103,10 @@ class ReferenceHelper
*/ */
public static function cellReverseSort($a, $b) public static function cellReverseSort($a, $b)
{ {
$ac = $bc = '';
$ar = $br = 0;
sscanf($a, '%[A-Z]%d', $ac, $ar); sscanf($a, '%[A-Z]%d', $ac, $ar);
sscanf($b, '%[A-Z]%d', $bc, $br); sscanf($b, '%[A-Z]%d', $bc, $br);
if ($ar == $br) { if ($ar === $br) {
return 1 - strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc); return 1 - strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc);
} }
@ -625,7 +619,7 @@ class ReferenceHelper
* Update references within formulas. * Update references within formulas.
* *
* @param string $pFormula Formula to update * @param string $pFormula Formula to update
* @param int $pBefore Insert before this one * @param string $pBefore Insert before this one
* @param int $pNumCols Number of columns to insert * @param int $pNumCols Number of columns to insert
* @param int $pNumRows Number of rows to insert * @param int $pNumRows Number of rows to insert
* @param string $sheetName Worksheet name/title * @param string $sheetName Worksheet name/title

View File

@ -35,27 +35,11 @@ abstract class BaseWriter implements IWriter
*/ */
private $diskCachingDirectory = './'; private $diskCachingDirectory = './';
/**
* Write charts in workbook?
* If this is true, then the Writer will write definitions for any charts that exist in the PhpSpreadsheet object.
* If false (the default) it will ignore any charts defined in the PhpSpreadsheet object.
*
* @return bool
*/
public function getIncludeCharts() public function getIncludeCharts()
{ {
return $this->includeCharts; return $this->includeCharts;
} }
/**
* Set write charts in workbook
* Set to true, to advise the Writer to include any charts that exist in the PhpSpreadsheet object.
* Set to false (the default) to ignore charts.
*
* @param bool $pValue
*
* @return IWriter
*/
public function setIncludeCharts($pValue) public function setIncludeCharts($pValue)
{ {
$this->includeCharts = (bool) $pValue; $this->includeCharts = (bool) $pValue;
@ -63,30 +47,11 @@ abstract class BaseWriter implements IWriter
return $this; return $this;
} }
/**
* Get Pre-Calculate Formulas flag
* If this is true (the default), then the writer will recalculate all formulae in a workbook when saving,
* so that the pre-calculated values are immediately available to MS Excel or other office spreadsheet
* viewer when opening the file
* If false, then formulae are not calculated on save. This is faster for saving in PhpSpreadsheet, but slower
* when opening the resulting file in MS Excel, because Excel has to recalculate the formulae itself.
*
* @return bool
*/
public function getPreCalculateFormulas() public function getPreCalculateFormulas()
{ {
return $this->preCalculateFormulas; return $this->preCalculateFormulas;
} }
/**
* Set Pre-Calculate Formulas
* Set to true (the default) to advise the Writer to calculate all formulae on save
* Set to false to prevent precalculation of formulae on save.
*
* @param bool $pValue Pre-Calculate Formulas?
*
* @return IWriter
*/
public function setPreCalculateFormulas($pValue) public function setPreCalculateFormulas($pValue)
{ {
$this->preCalculateFormulas = (bool) $pValue; $this->preCalculateFormulas = (bool) $pValue;
@ -94,26 +59,11 @@ abstract class BaseWriter implements IWriter
return $this; return $this;
} }
/**
* Get use disk caching where possible?
*
* @return bool
*/
public function getUseDiskCaching() public function getUseDiskCaching()
{ {
return $this->useDiskCaching; return $this->useDiskCaching;
} }
/**
* Set use disk caching where possible?
*
* @param bool $pValue
* @param string $pDirectory Disk caching directory
*
* @throws Exception when directory does not exist
*
* @return IWriter
*/
public function setUseDiskCaching($pValue, $pDirectory = null) public function setUseDiskCaching($pValue, $pDirectory = null)
{ {
$this->useDiskCaching = $pValue; $this->useDiskCaching = $pValue;
@ -129,11 +79,6 @@ abstract class BaseWriter implements IWriter
return $this; return $this;
} }
/**
* Get disk caching directory.
*
* @return string
*/
public function getDiskCachingDirectory() public function getDiskCachingDirectory()
{ {
return $this->diskCachingDirectory; return $this->diskCachingDirectory;

View File

@ -13,6 +13,49 @@ interface IWriter
*/ */
public function __construct(Spreadsheet $spreadsheet); public function __construct(Spreadsheet $spreadsheet);
/**
* Write charts in workbook?
* If this is true, then the Writer will write definitions for any charts that exist in the PhpSpreadsheet object.
* If false (the default) it will ignore any charts defined in the PhpSpreadsheet object.
*
* @return bool
*/
public function getIncludeCharts();
/**
* Set write charts in workbook
* Set to true, to advise the Writer to include any charts that exist in the PhpSpreadsheet object.
* Set to false (the default) to ignore charts.
*
* @param bool $pValue
*
* @return IWriter
*/
public function setIncludeCharts($pValue);
/**
* Get Pre-Calculate Formulas flag
* If this is true (the default), then the writer will recalculate all formulae in a workbook when saving,
* so that the pre-calculated values are immediately available to MS Excel or other office spreadsheet
* viewer when opening the file
* If false, then formulae are not calculated on save. This is faster for saving in PhpSpreadsheet, but slower
* when opening the resulting file in MS Excel, because Excel has to recalculate the formulae itself.
*
* @return bool
*/
public function getPreCalculateFormulas();
/**
* Set Pre-Calculate Formulas
* Set to true (the default) to advise the Writer to calculate all formulae on save
* Set to false to prevent precalculation of formulae on save.
*
* @param bool $pValue Pre-Calculate Formulas?
*
* @return IWriter
*/
public function setPreCalculateFormulas($pValue);
/** /**
* Save PhpSpreadsheet to file. * Save PhpSpreadsheet to file.
* *
@ -21,4 +64,30 @@ interface IWriter
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/ */
public function save($pFilename); public function save($pFilename);
/**
* Get use disk caching where possible?
*
* @return bool
*/
public function getUseDiskCaching();
/**
* Set use disk caching where possible?
*
* @param bool $pValue
* @param string $pDirectory Disk caching directory
*
* @throws Exception when directory does not exist
*
* @return IWriter
*/
public function setUseDiskCaching($pValue, $pDirectory = null);
/**
* Get disk caching directory.
*
* @return string
*/
public function getDiskCachingDirectory();
} }