Rectorification (#1010)

* A few loose to strict comparisons

* More loose to strict comparisons

* Revert accidental composer hacks that shouldn't have been committed
This commit is contained in:
Mark Baker 2019-06-14 08:31:27 +02:00 committed by GitHub
parent 5fd954d2c2
commit 71f3631cfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 36 deletions

View File

@ -1009,7 +1009,7 @@ class Parser
break; break;
case '>': case '>':
if ($this->lookAhead == '=') { // it's a GE token if ($this->lookAhead === '=') { // it's a GE token
break; break;
} }
@ -1018,7 +1018,7 @@ class Parser
break; break;
case '<': case '<':
// it's a LE or a NE token // it's a LE or a NE token
if (($this->lookAhead == '=') or ($this->lookAhead == '>')) { if (($this->lookAhead === '=') or ($this->lookAhead === '>')) {
break; break;
} }
@ -1027,12 +1027,12 @@ class Parser
break; break;
default: default:
// if it's a reference A1 or $A$1 or $A1 or A$1 // 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; 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) // If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1 or Sheet1!$A$1 or Sheet1:Sheet2!$A$1)
return $token; 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) // If it's an external reference ('Sheet1'!A1 or 'Sheet1:Sheet2'!A1 or 'Sheet1'!$A$1 or 'Sheet1:Sheet2'!$A$1)
return $token; 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)) { } elseif (preg_match('/^(\$)?[A-Ia-i]?[A-Za-z](\$)?\d+:(\$)?[A-Ia-i]?[A-Za-z](\$)?\d+$/', $token) && !preg_match('/\d/', $this->lookAhead)) {
@ -1044,19 +1044,19 @@ class Parser
} 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)) { } 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 // 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; 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) // If it's a number (check that it's not a sheet name or range)
return $token; 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) // If it's a string (of maximum 255 characters)
return $token; 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 // If it's an error code
return $token; 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 // if it's a function call
return $token; return $token;
} elseif (substr($token, -1) == ')') { } elseif (substr($token, -1) === ')') {
// It's an argument of some description (e.g. a named range), // It's an argument of some description (e.g. a named range),
// precise nature yet to be determined // precise nature yet to be determined
return $token; return $token;
@ -1078,8 +1078,7 @@ class Parser
{ {
$this->currentCharacter = 0; $this->currentCharacter = 0;
$this->formula = $formula; $this->formula = $formula;
$this->lookAhead = isset($formula[1]) ? $formula[1] $this->lookAhead = isset($formula[1]) ? $formula[1] : '';
: '';
$this->advance(); $this->advance();
$this->parseTree = $this->condition(); $this->parseTree = $this->condition();
@ -1248,10 +1247,10 @@ class Parser
*/ */
private function fact() private function fact()
{ {
if ($this->currentToken == '(') { if ($this->currentToken === '(') {
$this->advance(); // eat the "(" $this->advance(); // eat the "("
$result = $this->parenthesizedExpression(); $result = $this->parenthesizedExpression();
if ($this->currentToken != ')') { if ($this->currentToken !== ')') {
throw new WriterException("')' token expected."); throw new WriterException("')' token expected.");
} }
$this->advance(); // eat the ")" $this->advance(); // eat the ")"
@ -1299,7 +1298,7 @@ class Parser
return $result; return $result;
} elseif (is_numeric($this->currentToken)) { } elseif (is_numeric($this->currentToken)) {
// If it's a number or a percent // If it's a number or a percent
if ($this->lookAhead == '%') { if ($this->lookAhead === '%') {
$result = $this->createTree('ptgPercent', $this->currentToken, ''); $result = $this->createTree('ptgPercent', $this->currentToken, '');
$this->advance(); // Skip the percentage operator once we've pre-built that tree $this->advance(); // Skip the percentage operator once we've pre-built that tree
} else { } else {
@ -1331,9 +1330,9 @@ class Parser
$result = ''; // initialize result $result = ''; // initialize result
$this->advance(); $this->advance();
$this->advance(); // eat the "(" $this->advance(); // eat the "("
while ($this->currentToken != ')') { while ($this->currentToken !== ')') {
if ($num_args > 0) { if ($num_args > 0) {
if ($this->currentToken == ',' || $this->currentToken == ';') { if ($this->currentToken === ',' || $this->currentToken === ';') {
$this->advance(); // eat the "," or ";" $this->advance(); // eat the "," or ";"
} else { } else {
throw new WriterException("Syntax error: comma expected in function $function, arg #{$num_args}"); throw new WriterException("Syntax error: comma expected in function $function, arg #{$num_args}");

View File

@ -267,9 +267,7 @@ class Workbook extends BIFFwriter
$this->xfWriters[] = $xfWriter; $this->xfWriters[] = $xfWriter;
$xfIndex = count($this->xfWriters) - 1; return count($this->xfWriters) - 1;
return $xfIndex;
} }
/** /**
@ -319,7 +317,7 @@ class Workbook extends BIFFwriter
if ($colorIndex) { if ($colorIndex) {
$this->colors[$rgb] = $colorIndex; $this->colors[$rgb] = $colorIndex;
} else { } else {
if (count($this->colors) == 0) { if (count($this->colors) === 0) {
$lastColor = 7; $lastColor = 7;
} else { } else {
$lastColor = end($this->colors); $lastColor = end($this->colors);
@ -437,7 +435,7 @@ class Workbook extends BIFFwriter
// Prepare part 3 of the workbook global stream, what goes after the SHEET records // Prepare part 3 of the workbook global stream, what goes after the SHEET records
$part3 = ''; $part3 = '';
if ($this->countryCode != -1) { if ($this->countryCode !== -1) {
$part3 .= $this->writeCountry(); $part3 .= $this->writeCountry();
} }
$part3 .= $this->writeRecalcId(); $part3 .= $this->writeRecalcId();
@ -918,7 +916,7 @@ class Workbook extends BIFFwriter
$record = 0x0022; // Record identifier $record = 0x0022; // Record identifier
$length = 0x0002; // Bytes to follow $length = 0x0002; // Bytes to follow
$f1904 = (Date::getExcelCalendar() == Date::CALENDAR_MAC_1904) $f1904 = (Date::getExcelCalendar() === Date::CALENDAR_MAC_1904)
? 1 ? 1
: 0; // Flag for 1904 date system : 0; // Flag for 1904 date system

View File

@ -93,7 +93,7 @@ class Workbook extends WriterPart
{ {
$objWriter->startElement('workbookPr'); $objWriter->startElement('workbookPr');
if (Date::getExcelCalendar() == Date::CALENDAR_MAC_1904) { if (Date::getExcelCalendar() === Date::CALENDAR_MAC_1904) {
$objWriter->writeAttribute('date1904', '1'); $objWriter->writeAttribute('date1904', '1');
} }
@ -225,7 +225,7 @@ class Workbook extends WriterPart
$objWriter->startElement('sheet'); $objWriter->startElement('sheet');
$objWriter->writeAttribute('name', $pSheetname); $objWriter->writeAttribute('name', $pSheetname);
$objWriter->writeAttribute('sheetId', $pSheetId); $objWriter->writeAttribute('sheetId', $pSheetId);
if ($sheetState != 'visible' && $sheetState != '') { if ($sheetState !== 'visible' && $sheetState != '') {
$objWriter->writeAttribute('state', $sheetState); $objWriter->writeAttribute('state', $sheetState);
} }
$objWriter->writeAttribute('r:id', 'rId' . $pRelId); $objWriter->writeAttribute('r:id', 'rId' . $pRelId);

View File

@ -141,7 +141,7 @@ class Worksheet extends WriterPart
$objWriter->startElement('sheetPr'); $objWriter->startElement('sheetPr');
if ($pSheet->getParent()->hasMacros()) { if ($pSheet->getParent()->hasMacros()) {
//if the workbook have macros, we need to have codeName for the sheet //if the workbook have macros, we need to have codeName for the sheet
if ($pSheet->hasCodeName() == false) { if (!$pSheet->hasCodeName()) {
$pSheet->setCodeName($pSheet->getTitle()); $pSheet->setCodeName($pSheet->getTitle());
} }
$objWriter->writeAttribute('codeName', $pSheet->getCodeName()); $objWriter->writeAttribute('codeName', $pSheet->getCodeName());
@ -322,7 +322,7 @@ class Worksheet extends WriterPart
} }
// Set Zero Height row // Set Zero Height row
if ((string) $pSheet->getDefaultRowDimension()->getZeroHeight() == '1' || if ((string) $pSheet->getDefaultRowDimension()->getZeroHeight() === '1' ||
strtolower((string) $pSheet->getDefaultRowDimension()->getZeroHeight()) == 'true') { strtolower((string) $pSheet->getDefaultRowDimension()->getZeroHeight()) == 'true') {
$objWriter->writeAttribute('zeroHeight', '1'); $objWriter->writeAttribute('zeroHeight', '1');
} }
@ -428,7 +428,7 @@ class Worksheet extends WriterPart
// sheetProtection // sheetProtection
$objWriter->startElement('sheetProtection'); $objWriter->startElement('sheetProtection');
if ($pSheet->getProtection()->getPassword() != '') { if ($pSheet->getProtection()->getPassword() !== '') {
$objWriter->writeAttribute('password', $pSheet->getProtection()->getPassword()); $objWriter->writeAttribute('password', $pSheet->getProtection()->getPassword());
} }
@ -627,7 +627,7 @@ class Worksheet extends WriterPart
$objWriter->writeAttribute('location', str_replace('sheet://', '', $hyperlink->getUrl())); $objWriter->writeAttribute('location', str_replace('sheet://', '', $hyperlink->getUrl()));
} }
if ($hyperlink->getTooltip() != '') { if ($hyperlink->getTooltip() !== '') {
$objWriter->writeAttribute('tooltip', $hyperlink->getTooltip()); $objWriter->writeAttribute('tooltip', $hyperlink->getTooltip());
$objWriter->writeAttribute('display', $hyperlink->getTooltip()); $objWriter->writeAttribute('display', $hyperlink->getTooltip());
} }
@ -995,12 +995,12 @@ class Worksheet extends WriterPart
} }
// Row visibility // Row visibility
if ($rowDimension->getVisible() == false) { if (!$rowDimension->getVisible()) {
$objWriter->writeAttribute('hidden', 'true'); $objWriter->writeAttribute('hidden', 'true');
} }
// Collapsed // Collapsed
if ($rowDimension->getCollapsed() == true) { if ($rowDimension->getCollapsed()) {
$objWriter->writeAttribute('collapsed', 'true'); $objWriter->writeAttribute('collapsed', 'true');
} }
@ -1105,7 +1105,7 @@ class Worksheet extends WriterPart
break; break;
case 'f': // Formula case 'f': // Formula
$attributes = $pCell->getFormulaAttributes(); $attributes = $pCell->getFormulaAttributes();
if ($attributes['t'] == 'array') { if ($attributes['t'] === 'array') {
$objWriter->startElement('f'); $objWriter->startElement('f');
$objWriter->writeAttribute('t', 'array'); $objWriter->writeAttribute('t', 'array');
$objWriter->writeAttribute('ref', $pCellAddress); $objWriter->writeAttribute('ref', $pCellAddress);
@ -1118,7 +1118,7 @@ class Worksheet extends WriterPart
} }
if ($this->getParentWriter()->getOffice2003Compatibility() === false) { if ($this->getParentWriter()->getOffice2003Compatibility() === false) {
if ($this->getParentWriter()->getPreCalculateFormulas()) { 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)); $objWriter->writeElement('v', StringHelper::formatNumber($calculatedValue));
} else { } else {
$objWriter->writeElement('v', '0'); $objWriter->writeElement('v', '0');
@ -1139,7 +1139,7 @@ class Worksheet extends WriterPart
break; break;
case 'e': // Error case 'e': // Error
if (substr($cellValue, 0, 1) == '=') { if (substr($cellValue, 0, 1) === '=') {
$objWriter->writeElement('f', substr($cellValue, 1)); $objWriter->writeElement('f', substr($cellValue, 1));
$objWriter->writeElement('v', substr($cellValue, 1)); $objWriter->writeElement('v', substr($cellValue, 1));
} else { } else {