Skip to content

Commit 1b00fac

Browse files
author
Mark Baker
authored
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?
1 parent 2adaad3 commit 1b00fac

File tree

8 files changed

+88
-81
lines changed

8 files changed

+88
-81
lines changed

src/PhpSpreadsheet/Cell/Cell.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ public function isMergeRangeValueCell()
523523
/**
524524
* If this cell is in a merge range, then return the range.
525525
*
526-
* @return string
526+
* @return false|string
527527
*/
528528
public function getMergeRange()
529529
{

src/PhpSpreadsheet/Cell/Coordinate.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,12 @@ public static function buildRange(array $pRange)
157157
}
158158

159159
// Build range
160-
$imploded = [];
161160
$counter = count($pRange);
162161
for ($i = 0; $i < $counter; ++$i) {
163162
$pRange[$i] = implode(':', $pRange[$i]);
164163
}
165-
$imploded = implode(',', $pRange);
166164

167-
return $imploded;
165+
return implode(',', $pRange);
168166
}
169167

170168
/**

src/PhpSpreadsheet/Collection/Cells.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public function getCurrentRow()
241241
*/
242242
public function getHighestColumn($row = null)
243243
{
244-
if ($row == null) {
244+
if ($row === null) {
245245
$colRow = $this->getHighestRowAndColumn();
246246

247247
return $colRow['column'];
@@ -272,7 +272,7 @@ public function getHighestColumn($row = null)
272272
*/
273273
public function getHighestRow($column = null)
274274
{
275-
if ($column == null) {
275+
if ($column === null) {
276276
$colRow = $this->getHighestRowAndColumn();
277277

278278
return $colRow['row'];

src/PhpSpreadsheet/Reader/Csv.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ protected function checkSeparator()
143143
return;
144144
}
145145

146-
return $this->skipBOM();
146+
$this->skipBOM();
147147
}
148148

149149
/**
@@ -184,8 +184,9 @@ protected function inferSeparator()
184184
// If number of lines is 0, nothing to infer : fall back to the default
185185
if ($numberLines === 0) {
186186
$this->delimiter = reset($potentialDelimiters);
187+
$this->skipBOM();
187188

188-
return $this->skipBOM();
189+
return;
189190
}
190191

191192
// Calculate the mean square deviations for each delimiter (ignoring delimiters that haven't been found consistently)
@@ -230,7 +231,7 @@ function ($sum, $value) use ($median) {
230231
$this->delimiter = reset($potentialDelimiters);
231232
}
232233

233-
return $this->skipBOM();
234+
$this->skipBOM();
234235
}
235236

236237
/**

src/PhpSpreadsheet/Reader/Ods.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function canRead($pFilename)
5252
$stat = $zip->statName('mimetype');
5353
if ($stat && ($stat['size'] <= 255)) {
5454
$mimeType = $zip->getFromName($stat['name']);
55-
} elseif ($stat = $zip->statName('META-INF/manifest.xml')) {
55+
} elseif ($zip->statName('META-INF/manifest.xml')) {
5656
$xml = simplexml_load_string(
5757
$this->securityScanner->scan($zip->getFromName('META-INF/manifest.xml')),
5858
'SimpleXMLElement',
@@ -513,7 +513,7 @@ public function loadIntoExisting($pFilename, Spreadsheet $spreadsheet)
513513
foreach ($paragraphs as $pData) {
514514
$dataArray[] = $this->scanElementForText($pData);
515515
}
516-
$allCellDataText = implode($dataArray, "\n");
516+
$allCellDataText = implode("\n", $dataArray);
517517

518518
$type = $cellData->getAttributeNS($officeNs, 'value-type');
519519

@@ -580,12 +580,12 @@ public function loadIntoExisting($pFilename, Spreadsheet $spreadsheet)
580580
);
581581

582582
$dataValue = Date::formattedPHPToExcel(
583-
$year,
584-
$month,
585-
$day,
586-
$hour,
587-
$minute,
588-
$second
583+
(int) $year,
584+
(int) $month,
585+
(int) $day,
586+
(int) $hour,
587+
(int) $minute,
588+
(int) $second
589589
);
590590

591591
if ($dataValue != floor($dataValue)) {

src/PhpSpreadsheet/ReferenceHelper.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,10 @@ public static function columnReverseSort($a, $b)
8282
*/
8383
public static function cellSort($a, $b)
8484
{
85-
$ac = $bc = '';
86-
$ar = $br = 0;
87-
8885
sscanf($a, '%[A-Z]%d', $ac, $ar);
8986
sscanf($b, '%[A-Z]%d', $bc, $br);
9087

91-
if ($ar == $br) {
88+
if ($ar === $br) {
9289
return strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc);
9390
}
9491

@@ -106,13 +103,10 @@ public static function cellSort($a, $b)
106103
*/
107104
public static function cellReverseSort($a, $b)
108105
{
109-
$ac = $bc = '';
110-
$ar = $br = 0;
111-
112106
sscanf($a, '%[A-Z]%d', $ac, $ar);
113107
sscanf($b, '%[A-Z]%d', $bc, $br);
114108

115-
if ($ar == $br) {
109+
if ($ar === $br) {
116110
return 1 - strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc);
117111
}
118112

@@ -625,7 +619,7 @@ public function insertNewBefore($pBefore, $pNumCols, $pNumRows, Worksheet $pShee
625619
* Update references within formulas.
626620
*
627621
* @param string $pFormula Formula to update
628-
* @param int $pBefore Insert before this one
622+
* @param string $pBefore Insert before this one
629623
* @param int $pNumCols Number of columns to insert
630624
* @param int $pNumRows Number of rows to insert
631625
* @param string $sheetName Worksheet name/title

src/PhpSpreadsheet/Writer/BaseWriter.php

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -35,85 +35,35 @@ abstract class BaseWriter implements IWriter
3535
*/
3636
private $diskCachingDirectory = './';
3737

38-
/**
39-
* Write charts in workbook?
40-
* If this is true, then the Writer will write definitions for any charts that exist in the PhpSpreadsheet object.
41-
* If false (the default) it will ignore any charts defined in the PhpSpreadsheet object.
42-
*
43-
* @return bool
44-
*/
4538
public function getIncludeCharts()
4639
{
4740
return $this->includeCharts;
4841
}
4942

50-
/**
51-
* Set write charts in workbook
52-
* Set to true, to advise the Writer to include any charts that exist in the PhpSpreadsheet object.
53-
* Set to false (the default) to ignore charts.
54-
*
55-
* @param bool $pValue
56-
*
57-
* @return IWriter
58-
*/
5943
public function setIncludeCharts($pValue)
6044
{
6145
$this->includeCharts = (bool) $pValue;
6246

6347
return $this;
6448
}
6549

66-
/**
67-
* Get Pre-Calculate Formulas flag
68-
* If this is true (the default), then the writer will recalculate all formulae in a workbook when saving,
69-
* so that the pre-calculated values are immediately available to MS Excel or other office spreadsheet
70-
* viewer when opening the file
71-
* If false, then formulae are not calculated on save. This is faster for saving in PhpSpreadsheet, but slower
72-
* when opening the resulting file in MS Excel, because Excel has to recalculate the formulae itself.
73-
*
74-
* @return bool
75-
*/
7650
public function getPreCalculateFormulas()
7751
{
7852
return $this->preCalculateFormulas;
7953
}
8054

81-
/**
82-
* Set Pre-Calculate Formulas
83-
* Set to true (the default) to advise the Writer to calculate all formulae on save
84-
* Set to false to prevent precalculation of formulae on save.
85-
*
86-
* @param bool $pValue Pre-Calculate Formulas?
87-
*
88-
* @return IWriter
89-
*/
9055
public function setPreCalculateFormulas($pValue)
9156
{
9257
$this->preCalculateFormulas = (bool) $pValue;
9358

9459
return $this;
9560
}
9661

97-
/**
98-
* Get use disk caching where possible?
99-
*
100-
* @return bool
101-
*/
10262
public function getUseDiskCaching()
10363
{
10464
return $this->useDiskCaching;
10565
}
10666

107-
/**
108-
* Set use disk caching where possible?
109-
*
110-
* @param bool $pValue
111-
* @param string $pDirectory Disk caching directory
112-
*
113-
* @throws Exception when directory does not exist
114-
*
115-
* @return IWriter
116-
*/
11767
public function setUseDiskCaching($pValue, $pDirectory = null)
11868
{
11969
$this->useDiskCaching = $pValue;
@@ -129,11 +79,6 @@ public function setUseDiskCaching($pValue, $pDirectory = null)
12979
return $this;
13080
}
13181

132-
/**
133-
* Get disk caching directory.
134-
*
135-
* @return string
136-
*/
13782
public function getDiskCachingDirectory()
13883
{
13984
return $this->diskCachingDirectory;

src/PhpSpreadsheet/Writer/IWriter.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,49 @@ interface IWriter
1313
*/
1414
public function __construct(Spreadsheet $spreadsheet);
1515

16+
/**
17+
* Write charts in workbook?
18+
* If this is true, then the Writer will write definitions for any charts that exist in the PhpSpreadsheet object.
19+
* If false (the default) it will ignore any charts defined in the PhpSpreadsheet object.
20+
*
21+
* @return bool
22+
*/
23+
public function getIncludeCharts();
24+
25+
/**
26+
* Set write charts in workbook
27+
* Set to true, to advise the Writer to include any charts that exist in the PhpSpreadsheet object.
28+
* Set to false (the default) to ignore charts.
29+
*
30+
* @param bool $pValue
31+
*
32+
* @return IWriter
33+
*/
34+
public function setIncludeCharts($pValue);
35+
36+
/**
37+
* Get Pre-Calculate Formulas flag
38+
* If this is true (the default), then the writer will recalculate all formulae in a workbook when saving,
39+
* so that the pre-calculated values are immediately available to MS Excel or other office spreadsheet
40+
* viewer when opening the file
41+
* If false, then formulae are not calculated on save. This is faster for saving in PhpSpreadsheet, but slower
42+
* when opening the resulting file in MS Excel, because Excel has to recalculate the formulae itself.
43+
*
44+
* @return bool
45+
*/
46+
public function getPreCalculateFormulas();
47+
48+
/**
49+
* Set Pre-Calculate Formulas
50+
* Set to true (the default) to advise the Writer to calculate all formulae on save
51+
* Set to false to prevent precalculation of formulae on save.
52+
*
53+
* @param bool $pValue Pre-Calculate Formulas?
54+
*
55+
* @return IWriter
56+
*/
57+
public function setPreCalculateFormulas($pValue);
58+
1659
/**
1760
* Save PhpSpreadsheet to file.
1861
*
@@ -21,4 +64,30 @@ public function __construct(Spreadsheet $spreadsheet);
2164
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
2265
*/
2366
public function save($pFilename);
67+
68+
/**
69+
* Get use disk caching where possible?
70+
*
71+
* @return bool
72+
*/
73+
public function getUseDiskCaching();
74+
75+
/**
76+
* Set use disk caching where possible?
77+
*
78+
* @param bool $pValue
79+
* @param string $pDirectory Disk caching directory
80+
*
81+
* @throws Exception when directory does not exist
82+
*
83+
* @return IWriter
84+
*/
85+
public function setUseDiskCaching($pValue, $pDirectory = null);
86+
87+
/**
88+
* Get disk caching directory.
89+
*
90+
* @return string
91+
*/
92+
public function getDiskCachingDirectory();
2493
}

0 commit comments

Comments
 (0)