Skip to content

Commit b881309

Browse files
committed
Rector StrContainsRector, StrStartsWithRector, StrEndsWithRector
1 parent bf46298 commit b881309

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+160
-160
lines changed

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,7 +3158,7 @@ public function setLocale(string $locale): bool
31583158
{
31593159
// Identify our locale and language
31603160
$language = $locale = strtolower($locale);
3161-
if (strpos($locale, '_') !== false) {
3161+
if (str_contains($locale, '_')) {
31623162
[$language] = explode('_', $locale);
31633163
}
31643164
if (count(self::$validLocaleLanguages) == 1) {
@@ -3187,9 +3187,9 @@ public function setLocale(string $locale): bool
31873187
$localeFunctions = file($functionNamesFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [];
31883188
foreach ($localeFunctions as $localeFunction) {
31893189
[$localeFunction] = explode('##', $localeFunction); // Strip out comments
3190-
if (strpos($localeFunction, '=') !== false) {
3190+
if (str_contains($localeFunction, '=')) {
31913191
[$fName, $lfName] = array_map('trim', explode('=', $localeFunction));
3192-
if ((substr($fName, 0, 1) === '*' || isset(self::$phpSpreadsheetFunctions[$fName])) && ($lfName != '') && ($fName != $lfName)) {
3192+
if ((str_starts_with($fName, '*') || isset(self::$phpSpreadsheetFunctions[$fName])) && ($lfName != '') && ($fName != $lfName)) {
31933193
self::$localeFunctions[$fName] = $lfName;
31943194
}
31953195
}
@@ -3211,7 +3211,7 @@ public function setLocale(string $locale): bool
32113211
$localeSettings = file($configFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [];
32123212
foreach ($localeSettings as $localeSetting) {
32133213
[$localeSetting] = explode('##', $localeSetting); // Strip out comments
3214-
if (strpos($localeSetting, '=') !== false) {
3214+
if (str_contains($localeSetting, '=')) {
32153215
[$settingName, $settingValue] = array_map('trim', explode('=', $localeSetting));
32163216
$settingName = strtoupper($settingName);
32173217
if ($settingValue !== '') {
@@ -3298,7 +3298,7 @@ private static function translateFormula(array $from, array $to, string $formula
32983298
$inFunctionBracesLevel = 0;
32993299
$inMatrixBracesLevel = 0;
33003300
// If there is the possibility of separators within a quoted string, then we treat them as literals
3301-
if (strpos($formula, self::FORMULA_STRING_QUOTE) !== false) {
3301+
if (str_contains($formula, self::FORMULA_STRING_QUOTE)) {
33023302
// So instead we skip replacing in any quoted strings by only replacing in every other array element
33033303
// after we've exploded the formula
33043304
$temp = explode(self::FORMULA_STRING_QUOTE, $formula);
@@ -3992,9 +3992,9 @@ private function convertMatrixReferences(string $formula): false|string
39923992
static $matrixReplaceTo = ['MKMATRIX(MKMATRIX(', '),MKMATRIX(', '))'];
39933993

39943994
// Convert any Excel matrix references to the MKMATRIX() function
3995-
if (strpos($formula, self::FORMULA_OPEN_MATRIX_BRACE) !== false) {
3995+
if (str_contains($formula, self::FORMULA_OPEN_MATRIX_BRACE)) {
39963996
// If there is the possibility of braces within a quoted string, then we don't treat those as matrix indicators
3997-
if (strpos($formula, self::FORMULA_STRING_QUOTE) !== false) {
3997+
if (str_contains($formula, self::FORMULA_STRING_QUOTE)) {
39983998
// So instead we skip replacing in any quoted strings by only replacing in every other array element after we've exploded
39993999
// the formula
40004000
$temp = explode(self::FORMULA_STRING_QUOTE, $formula);
@@ -4354,7 +4354,7 @@ private function internalParseFormula($formula, ?Cell $cell = null): bool|array
43544354
return $this->raiseFormulaError('3D Range references are not yet supported');
43554355
}
43564356
}
4357-
} elseif (strpos($val, '!') === false && $pCellParent !== null) {
4357+
} elseif (!str_contains($val, '!') && $pCellParent !== null) {
43584358
$worksheet = $pCellParent->getTitle();
43594359
$val = "'{$worksheet}'!{$val}";
43604360
}
@@ -4398,7 +4398,7 @@ private function internalParseFormula($formula, ?Cell $cell = null): bool|array
43984398
$stackItemType = 'Defined Name';
43994399
$address = str_replace('$', '', $namedRange->getValue());
44004400
$stackItemReference = $val;
4401-
if (strpos($address, ':') !== false) {
4401+
if (str_contains($address, ':')) {
44024402
// We'll need to manipulate the stack for an actual named range rather than a named cell
44034403
$fromTo = explode(':', $address);
44044404
$to = array_pop($fromTo);
@@ -4492,7 +4492,7 @@ private function internalParseFormula($formula, ?Cell $cell = null): bool|array
44924492
$stackItemType = 'Defined Name';
44934493
$stackItemReference = $val;
44944494
} elseif (is_numeric($val)) {
4495-
if ((strpos((string) $val, '.') !== false) || (stripos((string) $val, 'e') !== false) || ($val > PHP_INT_MAX) || ($val < -PHP_INT_MAX)) {
4495+
if ((str_contains((string) $val, '.')) || (stripos((string) $val, 'e') !== false) || ($val > PHP_INT_MAX) || ($val < -PHP_INT_MAX)) {
44964496
$val = (float) $val;
44974497
} else {
44984498
$val = (int) $val;
@@ -4706,7 +4706,7 @@ private function processTokenStack($tokens, $cellID = null, ?Cell $cell = null)
47064706

47074707
try {
47084708
$cellRange = $token->parse($cell);
4709-
if (strpos($cellRange, ':') !== false) {
4709+
if (str_contains($cellRange, ':')) {
47104710
$this->debugLog->writeDebugLog('Evaluating Structured Reference %s as Cell Range %s', $token->value(), $cellRange);
47114711
$rangeValue = self::getInstance($cell->getWorksheet()->getParent())->_calculateFormulaValue("={$cellRange}", $cellRange, $cell);
47124712
$stack->push('Value', $rangeValue);
@@ -4770,7 +4770,7 @@ private function processTokenStack($tokens, $cellID = null, ?Cell $cell = null)
47704770
}
47714771
}
47724772
}
4773-
if (strpos($operand1Data['reference'] ?? '', '!') !== false) {
4773+
if (str_contains($operand1Data['reference'] ?? '', '!')) {
47744774
[$sheet1, $operand1Data['reference']] = Worksheet::extractSheetTitle($operand1Data['reference'], true);
47754775
} else {
47764776
$sheet1 = ($pCellWorksheet !== null) ? $pCellWorksheet->getTitle() : '';
@@ -4962,7 +4962,7 @@ private function processTokenStack($tokens, $cellID = null, ?Cell $cell = null)
49624962
$cellRef = $matches[6] . $matches[7] . ':' . $matches[9] . $matches[10];
49634963
if ($matches[2] > '') {
49644964
$matches[2] = trim($matches[2], "\"'");
4965-
if ((strpos($matches[2], '[') !== false) || (strpos($matches[2], ']') !== false)) {
4965+
if ((str_contains($matches[2], '[')) || (str_contains($matches[2], ']'))) {
49664966
// It's a Reference to an external spreadsheet (not currently supported)
49674967
return $this->raiseFormulaError('Unable to access External Workbook');
49684968
}
@@ -4992,7 +4992,7 @@ private function processTokenStack($tokens, $cellID = null, ?Cell $cell = null)
49924992
$cellRef = $matches[6] . $matches[7];
49934993
if ($matches[2] > '') {
49944994
$matches[2] = trim($matches[2], "\"'");
4995-
if ((strpos($matches[2], '[') !== false) || (strpos($matches[2], ']') !== false)) {
4995+
if ((str_contains($matches[2], '[')) || (str_contains($matches[2], ']'))) {
49964996
// It's a Reference to an external spreadsheet (not currently supported)
49974997
return $this->raiseFormulaError('Unable to access External Workbook');
49984998
}
@@ -5465,7 +5465,7 @@ public function extractCellRange(&$range = 'A1', ?Worksheet $worksheet = null, b
54655465
if ($worksheet !== null) {
54665466
$worksheetName = $worksheet->getTitle();
54675467

5468-
if (strpos($range, '!') !== false) {
5468+
if (str_contains($range, '!')) {
54695469
[$worksheetName, $range] = Worksheet::extractSheetTitle($range, true);
54705470
$worksheet = ($this->spreadsheet === null) ? null : $this->spreadsheet->getSheetByName($worksheetName);
54715471
}
@@ -5515,7 +5515,7 @@ public function extractNamedRange(string &$range = 'A1', ?Worksheet $worksheet =
55155515
$returnValue = [];
55165516

55175517
if ($worksheet !== null) {
5518-
if (strpos($range, '!') !== false) {
5518+
if (str_contains($range, '!')) {
55195519
[$worksheetName, $range] = Worksheet::extractSheetTitle($range, true);
55205520
$worksheet = ($this->spreadsheet === null) ? null : $this->spreadsheet->getSheetByName($worksheetName);
55215521
}
@@ -5636,7 +5636,7 @@ private function getArgumentDefaultValue(ReflectionParameter $methodArgument)
56365636
if ($methodArgument->isDefaultValueConstant()) {
56375637
$constantName = $methodArgument->getDefaultValueConstantName() ?? '';
56385638
// read constant value
5639-
if (strpos($constantName, '::') !== false) {
5639+
if (str_contains($constantName, '::')) {
56405640
[$className, $constantName] = explode('::', $constantName);
56415641
$constantReflector = new ReflectionClassConstant($className, $constantName);
56425642

src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ private static function processCondition(string $criterion, array $fields, array
181181
} elseif ($dataValues[$key] !== null) {
182182
$dataValue = $dataValues[$key];
183183
// escape quotes if we have a string containing quotes
184-
if (is_string($dataValue) && strpos($dataValue, '"') !== false) {
184+
if (is_string($dataValue) && str_contains($dataValue, '"')) {
185185
$dataValue = str_replace('"', '""', $dataValue);
186186
}
187187
$dataValue = (is_string($dataValue)) ? Calculation::wrapResult(strtoupper($dataValue)) : $dataValue;

src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static function fromString($dateValue)
7474
}
7575
if (count($t1) === 1) {
7676
// We've been fed a time value without any date
77-
return ((strpos((string) $t, ':') === false)) ? ExcelError::Value() : 0.0;
77+
return ((!str_contains((string) $t, ':'))) ? ExcelError::Value() : 0.0;
7878
}
7979
unset($t);
8080

src/PhpSpreadsheet/Calculation/Engine/Operands/StructuredReference.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static function fromParser(string $formula, int $index, array $matches):
6868
}
6969
$srStringRemainder = substr($srStringRemainder, 0, $closingPos + 1);
7070
--$srCount;
71-
if (strpos($srStringRemainder, self::OPEN_BRACE) !== false) {
71+
if (str_contains($srStringRemainder, self::OPEN_BRACE)) {
7272
++$srCount;
7373
}
7474
$val .= $srStringRemainder;
@@ -96,8 +96,8 @@ public function parse(Cell $cell): string
9696

9797
private function isRowReference(): bool
9898
{
99-
return strpos($this->value, '[@') !== false
100-
|| strpos($this->value, '[' . self::ITEM_SPECIFIER_THIS_ROW . ']') !== false;
99+
return str_contains($this->value, '[@')
100+
|| str_contains($this->value, '[' . self::ITEM_SPECIFIER_THIS_ROW . ']');
101101
}
102102

103103
/**

src/PhpSpreadsheet/Calculation/FormulaParser.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private function parseToTokens(): void
213213
}
214214

215215
// scientific notation check
216-
if (strpos(self::OPERATORS_SN, $this->formula[$index]) !== false) {
216+
if (str_contains(self::OPERATORS_SN, $this->formula[$index])) {
217217
if (strlen($value) > 1) {
218218
if (preg_match('/^[1-9]{1}(\\.\\d+)?E{1}$/', $this->formula[$index]) != 0) {
219219
$value .= $this->formula[$index];
@@ -367,7 +367,7 @@ private function parseToTokens(): void
367367
}
368368

369369
// standard infix operators
370-
if (strpos(self::OPERATORS_INFIX, $this->formula[$index]) !== false) {
370+
if (str_contains(self::OPERATORS_INFIX, $this->formula[$index])) {
371371
if (strlen($value) > 0) {
372372
$tokens1[] = new FormulaToken($value, FormulaToken::TOKEN_TYPE_OPERAND);
373373
$value = '';
@@ -379,7 +379,7 @@ private function parseToTokens(): void
379379
}
380380

381381
// standard postfix operators (only one)
382-
if (strpos(self::OPERATORS_POSTFIX, $this->formula[$index]) !== false) {
382+
if (str_contains(self::OPERATORS_POSTFIX, $this->formula[$index])) {
383383
if (strlen($value) > 0) {
384384
$tokens1[] = new FormulaToken($value, FormulaToken::TOKEN_TYPE_OPERAND);
385385
$value = '';
@@ -580,7 +580,7 @@ private function parseToTokens(): void
580580
$token->getTokenType() == FormulaToken::TOKEN_TYPE_OPERATORINFIX &&
581581
$token->getTokenSubType() == FormulaToken::TOKEN_SUBTYPE_NOTHING
582582
) {
583-
if (strpos('<>=', substr($token->getValue(), 0, 1)) !== false) {
583+
if (str_contains('<>=', substr($token->getValue(), 0, 1))) {
584584
$token->setTokenSubType(FormulaToken::TOKEN_SUBTYPE_LOGICAL);
585585
} elseif ($token->getValue() == '&') {
586586
$token->setTokenSubType(FormulaToken::TOKEN_SUBTYPE_CONCATENATION);
@@ -614,7 +614,7 @@ private function parseToTokens(): void
614614

615615
if ($token->getTokenType() == FormulaToken::TOKEN_TYPE_FUNCTION) {
616616
if (strlen($token->getValue()) > 0) {
617-
if (substr($token->getValue(), 0, 1) == '@') {
617+
if (str_starts_with($token->getValue(), '@')) {
618618
$token->setValue(substr($token->getValue(), 1));
619619
}
620620
}

src/PhpSpreadsheet/Calculation/Functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ public static function trimTrailingRange(string $coordinate): string
666666

667667
public static function trimSheetFromCellReference(string $coordinate): string
668668
{
669-
if (strpos($coordinate, '!') !== false) {
669+
if (str_contains($coordinate, '!')) {
670670
$coordinate = substr($coordinate, strrpos($coordinate, '!') + 1);
671671
}
672672

src/PhpSpreadsheet/Calculation/Information/Value.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public static function isFormula($cellReference = '', ?Cell $cell = null)
209209

210210
$fullCellReference = Functions::expandDefinedName((string) $cellReference, $cell);
211211

212-
if (strpos($cellReference, '!') !== false) {
212+
if (str_contains($cellReference, '!')) {
213213
$cellReference = Functions::trimSheetFromCellReference($cellReference);
214214
$cellReferences = Coordinate::extractAllCellReferencesInRange($cellReference);
215215
if (count($cellReferences) > 1) {

src/PhpSpreadsheet/Calculation/LookupRef/Address.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static function cell($row, $column, $relativity = 1, $referenceStyle = tr
8686
private static function sheetName(string $sheetName): string
8787
{
8888
if ($sheetName > '') {
89-
if (strpos($sheetName, ' ') !== false || strpos($sheetName, '[') !== false) {
89+
if (str_contains($sheetName, ' ') || str_contains($sheetName, '[')) {
9090
$sheetName = "'{$sheetName}'";
9191
}
9292
$sheetName .= '!';

src/PhpSpreadsheet/Calculation/LookupRef/Helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static function extractCellAddresses(string $cellAddress, bool $a1, Works
4949
$cellAddress = $cellAddress1;
5050
$a1 = self::CELLADDRESS_USE_A1;
5151
}
52-
if (strpos($cellAddress, ':') !== false) {
52+
if (str_contains($cellAddress, ':')) {
5353
[$cellAddress1, $cellAddress2] = explode(':', $cellAddress);
5454
}
5555
$cellAddress = self::convertR1C1($cellAddress1, $cellAddress2, $a1, $baseRow, $baseCol);
@@ -60,7 +60,7 @@ public static function extractCellAddresses(string $cellAddress, bool $a1, Works
6060
public static function extractWorksheet(string $cellAddress, Cell $cell): array
6161
{
6262
$sheetName = '';
63-
if (strpos($cellAddress, '!') !== false) {
63+
if (str_contains($cellAddress, '!')) {
6464
[$sheetName, $cellAddress] = Worksheet::extractSheetTitle($cellAddress, true);
6565
$sheetName = trim($sheetName, "'");
6666
}

src/PhpSpreadsheet/Calculation/LookupRef/Offset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private static function extractWorksheet(?string $cellAddress, Cell $cell): arra
102102
$cellAddress = self::assessCellAddress($cellAddress ?? '', $cell);
103103

104104
$sheetName = '';
105-
if (strpos($cellAddress, '!') !== false) {
105+
if (str_contains($cellAddress, '!')) {
106106
[$sheetName, $cellAddress] = Worksheet::extractSheetTitle($cellAddress, true);
107107
$sheetName = trim($sheetName, "'");
108108
}

0 commit comments

Comments
 (0)