Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cd8664c

Browse filesBrowse files
author
Erwin Dirks
committed
str_contains and str_starts_with are only available from PHP 8.0, since this version requires >=7.1.3 this function will fail on older PHP versions.
1 parent 75bf7fa commit cd8664c
Copy full SHA for cd8664c

File tree

5 files changed

+15
-15
lines changed
Filter options

5 files changed

+15
-15
lines changed

‎src/Symfony/Component/Serializer/Encoder/CsvEncoder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Encoder/CsvEncoder.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function decode($data, $format, array $context = [])
149149
fwrite($handle, $data);
150150
rewind($handle);
151151

152-
if (str_starts_with($data, self::UTF8_BOM)) {
152+
if (0 === strpos($data, self::UTF8_BOM)) {
153153
fseek($handle, \strlen(self::UTF8_BOM));
154154
}
155155

‎src/Symfony/Component/Serializer/Encoder/XmlEncoder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ final protected function appendComment(\DOMNode $node, string $data): bool
287287
final protected function isElementNameValid(string $name): bool
288288
{
289289
return $name &&
290-
!str_contains($name, ' ') &&
290+
false === strpos($name, ' ') &&
291291
preg_match('#^[\pL_][\pL0-9._:-]*$#ui', $name);
292292
}
293293

@@ -413,7 +413,7 @@ private function buildXml(\DOMNode $parentNode, $data, string $format, array $co
413413
if (\is_array($data) || ($data instanceof \Traversable && (null === $this->serializer || !$this->serializer->supportsNormalization($data, $format)))) {
414414
foreach ($data as $key => $data) {
415415
//Ah this is the magic @ attribute types.
416-
if (str_starts_with($key, '@') && $this->isElementNameValid($attributeName = substr($key, 1))) {
416+
if (0 === strpos($key, '@') && $this->isElementNameValid($attributeName = substr($key, 1))) {
417417
if (!is_scalar($data)) {
418418
$data = $this->serializer->normalize($data, $format, $context);
419419
}

‎src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ private function validateAndDenormalize(string $currentClass, string $attribute,
472472
// PHP's json_decode automatically converts Numbers without a decimal part to integers.
473473
// To circumvent this behavior, integers are converted to floats when denormalizing JSON based formats and when
474474
// a float is expected.
475-
if (Type::BUILTIN_TYPE_FLOAT === $builtinType && \is_int($data) && str_contains($format, JsonEncoder::FORMAT)) {
475+
if (Type::BUILTIN_TYPE_FLOAT === $builtinType && \is_int($data) && false !== strpos($format, JsonEncoder::FORMAT)) {
476476
return (float) $data;
477477
}
478478

@@ -652,7 +652,7 @@ private function getCacheKey(?string $format, array $context)
652652
private function isUninitializedValueError(\Error $e): bool
653653
{
654654
return \PHP_VERSION_ID >= 70400
655-
&& str_starts_with($e->getMessage(), 'Typed property')
656-
&& str_ends_with($e->getMessage(), 'must not be accessed before initialization');
655+
&& 0 === strpos($e->getMessage(), 'Typed property')
656+
&& 0 === strpos($e->getMessage(), 'must not be accessed before initialization');
657657
}
658658
}

‎src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ private function isGetMethod(\ReflectionMethod $method): bool
8686
return
8787
!$method->isStatic() &&
8888
(
89-
((str_starts_with($method->name, 'get') && 3 < $methodLength) ||
90-
(str_starts_with($method->name, 'is') && 2 < $methodLength) ||
91-
(str_starts_with($method->name, 'has') && 3 < $methodLength)) &&
89+
((0 === strpos($method->name, 'get') && 3 < $methodLength) ||
90+
(0 === strpos($method->name, 'is') && 2 < $methodLength) ||
91+
(0 === strpos($method->name, 'has') && 3 < $methodLength)) &&
9292
0 === $method->getNumberOfRequiredParameters()
9393
)
94-
;
94+
;
9595
}
9696

9797
/**
@@ -108,7 +108,7 @@ protected function extractAttributes($object, $format = null, array $context = [
108108
continue;
109109
}
110110

111-
$attributeName = lcfirst(substr($method->name, str_starts_with($method->name, 'is') ? 2 : 3));
111+
$attributeName = lcfirst(substr($method->name, 0 === strpos($method->name, 'is') ? 2 : 3));
112112

113113
if ($this->isAllowedAttribute($object, $attributeName, $format, $context)) {
114114
$attributes[] = $attributeName;

‎src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
4545
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
4646

4747
$this->objectClassResolver = $objectClassResolver ?? function ($class) {
48-
return \is_object($class) ? \get_class($class) : $class;
49-
};
48+
return \is_object($class) ? \get_class($class) : $class;
49+
};
5050
}
5151

5252
/**
@@ -82,14 +82,14 @@ protected function extractAttributes($object, $format = null, array $context = [
8282
$name = $reflMethod->name;
8383
$attributeName = null;
8484

85-
if (str_starts_with($name, 'get') || str_starts_with($name, 'has')) {
85+
if (0 === strpos($name, 'get') || 0 === strpos($name, 'has')) {
8686
// getters and hassers
8787
$attributeName = substr($name, 3);
8888

8989
if (!$reflClass->hasProperty($attributeName)) {
9090
$attributeName = lcfirst($attributeName);
9191
}
92-
} elseif (str_starts_with($name, 'is')) {
92+
} elseif (0 === strpos($name, 'is')) {
9393
// issers
9494
$attributeName = substr($name, 2);
9595

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.