Skip to content

Commit 18bbe2d

Browse files
derrabusnicolas-grekas
authored andcommitted
Leverage str_contains/str_starts_with
Signed-off-by: Alexander M. Turek <[email protected]>
1 parent 667a6e5 commit 18bbe2d

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

Command/DebugCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private function displayGeneralText(SymfonyStyle $io, string $filter = null)
225225
foreach ($types as $index => $type) {
226226
$items = [];
227227
foreach ($this->twig->{'get'.ucfirst($type)}() as $name => $entity) {
228-
if (!$filter || false !== strpos($name, $filter)) {
228+
if (!$filter || str_contains($name, $filter)) {
229229
$items[$name] = $name.$this->getPrettyMetadata($type, $entity, $decorated);
230230
}
231231
}
@@ -259,7 +259,7 @@ private function displayGeneralJson(SymfonyStyle $io, ?string $filter)
259259
$data = [];
260260
foreach ($types as $type) {
261261
foreach ($this->twig->{'get'.ucfirst($type)}() as $name => $entity) {
262-
if (!$filter || false !== strpos($name, $filter)) {
262+
if (!$filter || str_contains($name, $filter)) {
263263
$data[$type][$name] = $this->getMetadata($type, $entity);
264264
}
265265
}
@@ -409,7 +409,7 @@ private function findWrongBundleOverrides(): array
409409
$folders = glob($this->rootDir.'/Resources/*/views', \GLOB_ONLYDIR);
410410
$relativePath = ltrim(substr($this->rootDir.\DIRECTORY_SEPARATOR.'Resources/', \strlen($this->projectDir)), \DIRECTORY_SEPARATOR);
411411
$bundleNames = array_reduce($folders, function ($carry, $absolutePath) use ($relativePath) {
412-
if (0 === strpos($absolutePath, $this->projectDir)) {
412+
if (str_starts_with($absolutePath, $this->projectDir)) {
413413
$name = basename(\dirname($absolutePath));
414414
$path = ltrim($relativePath.$name, \DIRECTORY_SEPARATOR);
415415
$carry[$name] = $path;
@@ -425,7 +425,7 @@ private function findWrongBundleOverrides(): array
425425
$folders = glob($this->twigDefaultPath.'/bundles/*', \GLOB_ONLYDIR);
426426
$relativePath = ltrim(substr($this->twigDefaultPath.'/bundles/', \strlen($this->projectDir)), \DIRECTORY_SEPARATOR);
427427
$bundleNames = array_reduce($folders, function ($carry, $absolutePath) use ($relativePath) {
428-
if (0 === strpos($absolutePath, $this->projectDir)) {
428+
if (str_starts_with($absolutePath, $this->projectDir)) {
429429
$name = basename($absolutePath);
430430
$path = ltrim($relativePath.$name, \DIRECTORY_SEPARATOR);
431431
$carry[$name] = $path;
@@ -555,7 +555,7 @@ private function findAlternatives(string $name, array $collection): array
555555
$alternatives = [];
556556
foreach ($collection as $item) {
557557
$lev = levenshtein($name, $item);
558-
if ($lev <= \strlen($name) / 3 || false !== strpos($item, $name)) {
558+
if ($lev <= \strlen($name) / 3 || str_contains($item, $name)) {
559559
$alternatives[$item] = isset($alternatives[$item]) ? $alternatives[$item] - $lev : $lev;
560560
}
561561
}
@@ -569,7 +569,7 @@ private function findAlternatives(string $name, array $collection): array
569569

570570
private function getRelativePath(string $path): string
571571
{
572-
if (null !== $this->projectDir && 0 === strpos($path, $this->projectDir)) {
572+
if (null !== $this->projectDir && str_starts_with($path, $this->projectDir)) {
573573
return ltrim(substr($path, \strlen($this->projectDir)), \DIRECTORY_SEPARATOR);
574574
}
575575

Extension/CodeExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function abbrClass($class)
7171

7272
public function abbrMethod($method)
7373
{
74-
if (false !== strpos($method, '::')) {
74+
if (str_contains($method, '::')) {
7575
[$class, $method] = explode('::', $method, 2);
7676
$result = sprintf('%s::%s()', $this->abbrClass($class), $method);
7777
} elseif ('Closure' === $method) {
@@ -219,7 +219,7 @@ public function getFileRelative(string $file): ?string
219219
{
220220
$file = str_replace('\\', '/', $file);
221221

222-
if (null !== $this->projectDir && 0 === strpos($file, $this->projectDir)) {
222+
if (null !== $this->projectDir && str_starts_with($file, $this->projectDir)) {
223223
return ltrim(substr($file, \strlen($this->projectDir)), '/');
224224
}
225225

@@ -238,7 +238,7 @@ public function formatFileFromText($text)
238238
*/
239239
public function formatLogMessage(string $message, array $context): string
240240
{
241-
if ($context && false !== strpos($message, '{')) {
241+
if ($context && str_contains($message, '{')) {
242242
$replacements = [];
243243
foreach ($context as $key => $val) {
244244
if (is_scalar($val)) {

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=7.1.3",
20+
"symfony/polyfill-php80": "^1.16",
2021
"symfony/translation-contracts": "^1.1|^2",
2122
"twig/twig": "^1.43|^2.13|^3.0.4"
2223
},

0 commit comments

Comments
 (0)