Skip to content

Commit d508398

Browse files
committed
used native PHP 8 functions
1 parent 7308721 commit d508398

File tree

13 files changed

+22
-22
lines changed

13 files changed

+22
-22
lines changed

src/DI/Autowiring.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function getByType(string $type, bool $throw = false): ?string
6161
} else {
6262
$list = $types[$type];
6363
natsort($list);
64-
$hint = count($list) === 2 && ($tmp = strpos($list[0], '.') xor strpos($list[1], '.'))
64+
$hint = count($list) === 2 && ($tmp = str_contains($list[0], '.') xor str_contains($list[1], '.'))
6565
? '. If you want to overwrite service ' . $list[$tmp ? 0 : 1] . ', give it proper name.'
6666
: '';
6767
throw new ServiceCreationException(sprintf(

src/DI/CompilerExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function getInitialization(): Nette\PhpGenerator\Closure
137137
*/
138138
public function prefix(string $id): string
139139
{
140-
return substr_replace($id, $this->name . '.', substr($id, 0, 1) === '@' ? 1 : 0, 0);
140+
return substr_replace($id, $this->name . '.', str_starts_with($id, '@') ? 1 : 0, 0);
141141
}
142142

143143

src/DI/Config/Adapters/NeonAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function process(array $arr): array
4040
{
4141
$res = [];
4242
foreach ($arr as $key => $val) {
43-
if (is_string($key) && substr($key, -1) === self::PREVENT_MERGING_SUFFIX) {
43+
if (is_string($key) && str_ends_with($key, self::PREVENT_MERGING_SUFFIX)) {
4444
if (!is_array($val) && $val !== null) {
4545
throw new Nette\DI\InvalidConfigurationException(sprintf(
4646
"Replacing operator is available only for arrays, item '%s' is not array.",
@@ -66,7 +66,7 @@ public function process(array $arr): array
6666
$val = $tmp;
6767
} else {
6868
$tmp = $this->process([$val->value]);
69-
if (is_string($tmp[0]) && strpos($tmp[0], '?') !== false) {
69+
if (is_string($tmp[0]) && str_contains($tmp[0], '?')) {
7070
trigger_error('Operator ? is deprecated in config files.', E_USER_DEPRECATED);
7171
}
7272
$val = new Statement($tmp[0], $this->process($val->attributes));

src/DI/Definitions/AccessorDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function setReference(string|Reference $reference): static
6969
if ($reference instanceof Reference) {
7070
$this->reference = $reference;
7171
} else {
72-
$this->reference = substr($reference, 0, 1) === '@'
72+
$this->reference = str_starts_with($reference, '@')
7373
? new Reference(substr($reference, 1))
7474
: Reference::fromType($reference);
7575
}

src/DI/Definitions/LocatorDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function setReferences(array $references): static
6161
{
6262
$this->references = [];
6363
foreach ($references as $name => $ref) {
64-
$this->references[$name] = substr($ref, 0, 1) === '@'
64+
$this->references[$name] = str_starts_with($ref, '@')
6565
? new Reference(substr($ref, 1))
6666
: Reference::fromType($ref);
6767
}

src/DI/Definitions/Reference.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class Reference
2626

2727
public static function fromType(string $value): static
2828
{
29-
if (strpos($value, '\\') === false) {
29+
if (!str_contains($value, '\\')) {
3030
$value = '\\' . $value;
3131
}
3232
return new static($value);
@@ -47,13 +47,13 @@ public function getValue(): string
4747

4848
public function isName(): bool
4949
{
50-
return strpos($this->value, '\\') === false && $this->value !== self::SELF;
50+
return !str_contains($this->value, '\\') && $this->value !== self::SELF;
5151
}
5252

5353

5454
public function isType(): bool
5555
{
56-
return strpos($this->value, '\\') !== false;
56+
return str_contains($this->value, '\\');
5757
}
5858

5959

src/DI/Definitions/Statement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public function __construct(string|array|Definition|Reference|null $entity, arra
4848
if (is_string($entity) && Strings::contains($entity, '::') && !Strings::contains($entity, '?')) {
4949
$entity = explode('::', $entity, 2);
5050
}
51-
if (is_string($entity) && substr($entity, 0, 1) === '@') { // normalize @service to Reference
51+
if (is_string($entity) && str_starts_with($entity, '@')) { // normalize @service to Reference
5252
$entity = new Reference(substr($entity, 1));
53-
} elseif (is_array($entity) && is_string($entity[0]) && substr($entity[0], 0, 1) === '@') {
53+
} elseif (is_array($entity) && is_string($entity[0]) && str_starts_with($entity[0], '@')) {
5454
$entity[0] = new Reference(substr($entity[0], 1));
5555
}
5656

src/DI/DependencyChecker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class_uses($name),
140140

141141
$flip = array_flip($classes);
142142
foreach ($functions as $name) {
143-
if (strpos($name, '::')) {
143+
if (str_contains($name, '::')) {
144144
$method = new ReflectionMethod($name);
145145
$class = $method->getDeclaringClass();
146146
if (isset($flip[$class->name])) {

src/DI/Extensions/InjectExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static function getInjectMethods(string $class): array
8989
{
9090
$classes = [];
9191
foreach (get_class_methods($class) as $name) {
92-
if (substr($name, 0, 6) === 'inject') {
92+
if (str_starts_with($name, 'inject')) {
9393
$classes[$name] = (new \ReflectionMethod($class, $name))->getDeclaringClass()->name;
9494
}
9595
}
@@ -114,7 +114,7 @@ public static function getInjectProperties(string $class): array
114114
if ($hasAttr || DI\Helpers::parseAnnotation($rp, 'inject') !== null) {
115115
if ($type = Reflection::getPropertyType($rp)) {
116116
} elseif (!$hasAttr && ($type = DI\Helpers::parseAnnotation($rp, 'var'))) {
117-
if (strpos($type, '|') !== false) {
117+
if (str_contains($type, '|')) {
118118
throw new Nette\InvalidStateException(sprintf(
119119
'The %s is not expected to have a union type.',
120120
Reflection::toString($rp),

src/DI/Extensions/SearchExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private static function buildNameRegexp(array $masks): ?string
139139
{
140140
$res = [];
141141
foreach ((array) $masks as $mask) {
142-
$mask = (strpos($mask, '\\') === false ? '**\\' : '') . $mask;
142+
$mask = (str_contains($mask, '\\') ? '' : '**\\') . $mask;
143143
$mask = preg_quote($mask, '#');
144144
$mask = str_replace('\*\*\\\\', '(.*\\\\)?', $mask);
145145
$mask = str_replace('\\\\\*\*', '(\\\\.*)?', $mask);

0 commit comments

Comments
 (0)