Skip to content

Commit

Permalink
Rectorification (#1010)
Browse files Browse the repository at this point in the history
* A few loose to strict comparisons

* More loose to strict comparisons

* Revert accidental composer hacks that shouldn't have been committed
  • Loading branch information
Mark Baker committed Jun 14, 2019
1 parent 5fd954d commit 71f3631
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 36 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -84,4 +84,4 @@
"PhpOffice\\PhpSpreadsheetTests\\": "tests/PhpSpreadsheetTests"
}
}
}
}
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 16 additions & 17 deletions src/PhpSpreadsheet/Writer/Xls/Parser.php
Expand Up @@ -1009,7 +1009,7 @@ private function match($token)

break;
case '>':
if ($this->lookAhead == '=') { // it's a GE token
if ($this->lookAhead === '=') { // it's a GE token
break;
}

Expand All @@ -1018,7 +1018,7 @@ private function match($token)
break;
case '<':
// it's a LE or a NE token
if (($this->lookAhead == '=') or ($this->lookAhead == '>')) {
if (($this->lookAhead === '=') or ($this->lookAhead === '>')) {
break;
}

Expand All @@ -1027,12 +1027,12 @@ private function match($token)
break;
default:
// if it's a reference A1 or $A$1 or $A1 or A$1
if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?\d+$/', $token) and !preg_match('/\d/', $this->lookAhead) and ($this->lookAhead != ':') and ($this->lookAhead != '.') and ($this->lookAhead != '!')) {
if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?\d+$/', $token) and !preg_match('/\d/', $this->lookAhead) and ($this->lookAhead !== ':') and ($this->lookAhead !== '.') and ($this->lookAhead !== '!')) {
return $token;
} elseif (preg_match('/^' . self::REGEX_SHEET_TITLE_UNQUOTED . '(\\:' . self::REGEX_SHEET_TITLE_UNQUOTED . ')?\\!\$?[A-Ia-i]?[A-Za-z]\$?\\d+$/u', $token) and !preg_match('/\d/', $this->lookAhead) and ($this->lookAhead != ':') and ($this->lookAhead != '.')) {
} elseif (preg_match('/^' . self::REGEX_SHEET_TITLE_UNQUOTED . '(\\:' . self::REGEX_SHEET_TITLE_UNQUOTED . ')?\\!\$?[A-Ia-i]?[A-Za-z]\$?\\d+$/u', $token) and !preg_match('/\d/', $this->lookAhead) and ($this->lookAhead !== ':') and ($this->lookAhead !== '.')) {
// If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1 or Sheet1!$A$1 or Sheet1:Sheet2!$A$1)
return $token;
} elseif (preg_match("/^'" . self::REGEX_SHEET_TITLE_QUOTED . '(\\:' . self::REGEX_SHEET_TITLE_QUOTED . ")?'\\!\\$?[A-Ia-i]?[A-Za-z]\\$?\\d+$/u", $token) and !preg_match('/\d/', $this->lookAhead) and ($this->lookAhead != ':') and ($this->lookAhead != '.')) {
} elseif (preg_match("/^'" . self::REGEX_SHEET_TITLE_QUOTED . '(\\:' . self::REGEX_SHEET_TITLE_QUOTED . ")?'\\!\\$?[A-Ia-i]?[A-Za-z]\\$?\\d+$/u", $token) and !preg_match('/\d/', $this->lookAhead) and ($this->lookAhead !== ':') and ($this->lookAhead !== '.')) {
// If it's an external reference ('Sheet1'!A1 or 'Sheet1:Sheet2'!A1 or 'Sheet1'!$A$1 or 'Sheet1:Sheet2'!$A$1)
return $token;
} elseif (preg_match('/^(\$)?[A-Ia-i]?[A-Za-z](\$)?\d+:(\$)?[A-Ia-i]?[A-Za-z](\$)?\d+$/', $token) && !preg_match('/\d/', $this->lookAhead)) {
Expand All @@ -1044,19 +1044,19 @@ private function match($token)
} elseif (preg_match("/^'" . self::REGEX_SHEET_TITLE_QUOTED . '(\\:' . self::REGEX_SHEET_TITLE_QUOTED . ")?'\\!\\$?([A-Ia-i]?[A-Za-z])?\\$?\\d+:\\$?([A-Ia-i]?[A-Za-z])?\\$?\\d+$/u", $token) and !preg_match('/\d/', $this->lookAhead)) {
// If it's an external range like 'Sheet1'!A1:B2 or 'Sheet1:Sheet2'!A1:B2 or 'Sheet1'!$A$1:$B$2 or 'Sheet1:Sheet2'!$A$1:$B$2
return $token;
} elseif (is_numeric($token) and (!is_numeric($token . $this->lookAhead) or ($this->lookAhead == '')) and ($this->lookAhead != '!') and ($this->lookAhead != ':')) {
} elseif (is_numeric($token) and (!is_numeric($token . $this->lookAhead) or ($this->lookAhead == '')) and ($this->lookAhead !== '!') and ($this->lookAhead !== ':')) {
// If it's a number (check that it's not a sheet name or range)
return $token;
} elseif (preg_match('/"([^"]|""){0,255}"/', $token) and $this->lookAhead != '"' and (substr_count($token, '"') % 2 == 0)) {
} elseif (preg_match('/"([^"]|""){0,255}"/', $token) and $this->lookAhead !== '"' and (substr_count($token, '"') % 2 == 0)) {
// If it's a string (of maximum 255 characters)
return $token;
} elseif (preg_match('/^#[A-Z0\\/]{3,5}[!?]{1}$/', $token) or $token == '#N/A') {
} elseif (preg_match('/^#[A-Z0\\/]{3,5}[!?]{1}$/', $token) or $token === '#N/A') {
// If it's an error code
return $token;
} elseif (preg_match("/^[A-Z0-9\xc0-\xdc\\.]+$/i", $token) and ($this->lookAhead == '(')) {
} elseif (preg_match("/^[A-Z0-9\xc0-\xdc\\.]+$/i", $token) and ($this->lookAhead === '(')) {
// if it's a function call
return $token;
} elseif (substr($token, -1) == ')') {
} elseif (substr($token, -1) === ')') {
// It's an argument of some description (e.g. a named range),
// precise nature yet to be determined
return $token;
Expand All @@ -1078,8 +1078,7 @@ public function parse($formula)
{
$this->currentCharacter = 0;
$this->formula = $formula;
$this->lookAhead = isset($formula[1]) ? $formula[1]
: '';
$this->lookAhead = isset($formula[1]) ? $formula[1] : '';
$this->advance();
$this->parseTree = $this->condition();

Expand Down Expand Up @@ -1248,10 +1247,10 @@ private function term()
*/
private function fact()
{
if ($this->currentToken == '(') {
if ($this->currentToken === '(') {
$this->advance(); // eat the "("
$result = $this->parenthesizedExpression();
if ($this->currentToken != ')') {
if ($this->currentToken !== ')') {
throw new WriterException("')' token expected.");
}
$this->advance(); // eat the ")"
Expand Down Expand Up @@ -1299,7 +1298,7 @@ private function fact()
return $result;
} elseif (is_numeric($this->currentToken)) {
// If it's a number or a percent
if ($this->lookAhead == '%') {
if ($this->lookAhead === '%') {
$result = $this->createTree('ptgPercent', $this->currentToken, '');
$this->advance(); // Skip the percentage operator once we've pre-built that tree
} else {
Expand Down Expand Up @@ -1331,9 +1330,9 @@ private function func()
$result = ''; // initialize result
$this->advance();
$this->advance(); // eat the "("
while ($this->currentToken != ')') {
while ($this->currentToken !== ')') {
if ($num_args > 0) {
if ($this->currentToken == ',' || $this->currentToken == ';') {
if ($this->currentToken === ',' || $this->currentToken === ';') {
$this->advance(); // eat the "," or ";"
} else {
throw new WriterException("Syntax error: comma expected in function $function, arg #{$num_args}");
Expand Down
10 changes: 4 additions & 6 deletions src/PhpSpreadsheet/Writer/Xls/Workbook.php
Expand Up @@ -267,9 +267,7 @@ public function addXfWriter(Style $style, $isStyleXf = false)

$this->xfWriters[] = $xfWriter;

$xfIndex = count($this->xfWriters) - 1;

return $xfIndex;
return count($this->xfWriters) - 1;
}

/**
Expand Down Expand Up @@ -319,7 +317,7 @@ private function addColor($rgb)
if ($colorIndex) {
$this->colors[$rgb] = $colorIndex;
} else {
if (count($this->colors) == 0) {
if (count($this->colors) === 0) {
$lastColor = 7;
} else {
$lastColor = end($this->colors);
Expand Down Expand Up @@ -437,7 +435,7 @@ public function writeWorkbook(array $pWorksheetSizes)

// Prepare part 3 of the workbook global stream, what goes after the SHEET records
$part3 = '';
if ($this->countryCode != -1) {
if ($this->countryCode !== -1) {
$part3 .= $this->writeCountry();
}
$part3 .= $this->writeRecalcId();
Expand Down Expand Up @@ -918,7 +916,7 @@ private function writeDateMode()
$record = 0x0022; // Record identifier
$length = 0x0002; // Bytes to follow

$f1904 = (Date::getExcelCalendar() == Date::CALENDAR_MAC_1904)
$f1904 = (Date::getExcelCalendar() === Date::CALENDAR_MAC_1904)
? 1
: 0; // Flag for 1904 date system

Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Writer/Xlsx/Workbook.php
Expand Up @@ -93,7 +93,7 @@ private function writeWorkbookPr(XMLWriter $objWriter)
{
$objWriter->startElement('workbookPr');

if (Date::getExcelCalendar() == Date::CALENDAR_MAC_1904) {
if (Date::getExcelCalendar() === Date::CALENDAR_MAC_1904) {
$objWriter->writeAttribute('date1904', '1');
}

Expand Down Expand Up @@ -225,7 +225,7 @@ private function writeSheet(XMLWriter $objWriter, $pSheetname, $pSheetId = 1, $p
$objWriter->startElement('sheet');
$objWriter->writeAttribute('name', $pSheetname);
$objWriter->writeAttribute('sheetId', $pSheetId);
if ($sheetState != 'visible' && $sheetState != '') {
if ($sheetState !== 'visible' && $sheetState != '') {
$objWriter->writeAttribute('state', $sheetState);
}
$objWriter->writeAttribute('r:id', 'rId' . $pRelId);
Expand Down
18 changes: 9 additions & 9 deletions src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
Expand Up @@ -141,7 +141,7 @@ private function writeSheetPr(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSh
$objWriter->startElement('sheetPr');
if ($pSheet->getParent()->hasMacros()) {
//if the workbook have macros, we need to have codeName for the sheet
if ($pSheet->hasCodeName() == false) {
if (!$pSheet->hasCodeName()) {
$pSheet->setCodeName($pSheet->getTitle());
}
$objWriter->writeAttribute('codeName', $pSheet->getCodeName());
Expand Down Expand Up @@ -322,7 +322,7 @@ private function writeSheetFormatPr(XMLWriter $objWriter, PhpspreadsheetWorkshee
}

// Set Zero Height row
if ((string) $pSheet->getDefaultRowDimension()->getZeroHeight() == '1' ||
if ((string) $pSheet->getDefaultRowDimension()->getZeroHeight() === '1' ||
strtolower((string) $pSheet->getDefaultRowDimension()->getZeroHeight()) == 'true') {
$objWriter->writeAttribute('zeroHeight', '1');
}
Expand Down Expand Up @@ -428,7 +428,7 @@ private function writeSheetProtection(XMLWriter $objWriter, PhpspreadsheetWorksh
// sheetProtection
$objWriter->startElement('sheetProtection');

if ($pSheet->getProtection()->getPassword() != '') {
if ($pSheet->getProtection()->getPassword() !== '') {
$objWriter->writeAttribute('password', $pSheet->getProtection()->getPassword());
}

Expand Down Expand Up @@ -627,7 +627,7 @@ private function writeHyperlinks(XMLWriter $objWriter, PhpspreadsheetWorksheet $
$objWriter->writeAttribute('location', str_replace('sheet://', '', $hyperlink->getUrl()));
}

if ($hyperlink->getTooltip() != '') {
if ($hyperlink->getTooltip() !== '') {
$objWriter->writeAttribute('tooltip', $hyperlink->getTooltip());
$objWriter->writeAttribute('display', $hyperlink->getTooltip());
}
Expand Down Expand Up @@ -995,12 +995,12 @@ private function writeSheetData(XMLWriter $objWriter, PhpspreadsheetWorksheet $p
}

// Row visibility
if ($rowDimension->getVisible() == false) {
if (!$rowDimension->getVisible()) {
$objWriter->writeAttribute('hidden', 'true');
}

// Collapsed
if ($rowDimension->getCollapsed() == true) {
if ($rowDimension->getCollapsed()) {
$objWriter->writeAttribute('collapsed', 'true');
}

Expand Down Expand Up @@ -1105,7 +1105,7 @@ private function writeCell(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet
break;
case 'f': // Formula
$attributes = $pCell->getFormulaAttributes();
if ($attributes['t'] == 'array') {
if ($attributes['t'] === 'array') {
$objWriter->startElement('f');
$objWriter->writeAttribute('t', 'array');
$objWriter->writeAttribute('ref', $pCellAddress);
Expand All @@ -1118,7 +1118,7 @@ private function writeCell(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet
}
if ($this->getParentWriter()->getOffice2003Compatibility() === false) {
if ($this->getParentWriter()->getPreCalculateFormulas()) {
if (!is_array($calculatedValue) && substr($calculatedValue, 0, 1) != '#') {
if (!is_array($calculatedValue) && substr($calculatedValue, 0, 1) !== '#') {
$objWriter->writeElement('v', StringHelper::formatNumber($calculatedValue));
} else {
$objWriter->writeElement('v', '0');
Expand All @@ -1139,7 +1139,7 @@ private function writeCell(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet

break;
case 'e': // Error
if (substr($cellValue, 0, 1) == '=') {
if (substr($cellValue, 0, 1) === '=') {
$objWriter->writeElement('f', substr($cellValue, 1));
$objWriter->writeElement('v', substr($cellValue, 1));
} else {
Expand Down

0 comments on commit 71f3631

Please sign in to comment.