Skip to content

Commit f7da6ce

Browse files
committed
Apply rector ForeachToArrayAllRector and ForeachToArrayAnyRector #12152
1 parent ff0ba47 commit f7da6ce

6 files changed

Lines changed: 6 additions & 43 deletions

File tree

src/Acl/Acl.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,7 @@ public function isAllowed($role = null, $resource = null, $privilege = null): bo
9292
$roles = [$role];
9393
}
9494

95-
// If at least one role is allowed, then return early
96-
foreach ($roles as $role) {
97-
if (parent::isAllowed($role, $resource, $privilege)) {
98-
return true;
99-
}
100-
}
101-
102-
return false;
95+
return array_any($roles, fn (null|RoleInterface|string $role) => parent::isAllowed($role, $resource, $privilege));
10396
}
10497

10598
/**

src/Acl/Assertion/All.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,7 @@ public function __construct(NamedAssertion ...$asserts)
3131
*/
3232
public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null): bool
3333
{
34-
foreach ($this->asserts as $assert) {
35-
if (!$assert->assert($acl, $role, $resource, $privilege)) {
36-
return false;
37-
}
38-
}
39-
40-
return true;
34+
return array_all($this->asserts, fn (NamedAssertion $assert) => $assert->assert($acl, $role, $resource, $privilege));
4135
}
4236

4337
public function getName(): string

src/Acl/Assertion/One.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,7 @@ public function __construct(NamedAssertion ...$asserts)
3131
*/
3232
public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null): bool
3333
{
34-
foreach ($this->asserts as $assert) {
35-
if ($assert->assert($acl, $role, $resource, $privilege)) {
36-
return true;
37-
}
38-
}
39-
40-
return false;
34+
return array_any($this->asserts, fn (NamedAssertion $assert) => $assert->assert($acl, $role, $resource, $privilege));
4135
}
4236

4337
public function getName(): string

src/Acl/DebugAcl.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,7 @@ public function isAllowed($role = null, $resource = null, $privilege = null): bo
172172
$roles = [$role];
173173
}
174174

175-
// If at least one role is allowed, then return early
176-
foreach ($roles as $role) {
177-
if (parent::isAllowed($role, $resource, $privilege)) {
178-
return true;
179-
}
180-
}
181-
182-
return false;
175+
return array_any($roles, fn (null|RoleInterface|string $role) => parent::isAllowed($role, $resource, $privilege));
183176
}
184177

185178
/**

src/DBAL/Types/SetType.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,8 @@ private function isValid(mixed $values): bool
6464
}
6565

6666
$possibleValues = $this->getPossibleValues();
67-
foreach ($values as $value) {
68-
if (!in_array($value, $possibleValues, true)) {
69-
return false;
70-
}
71-
}
7267

73-
return true;
68+
return array_all($values, fn (mixed $value) => in_array($value, $possibleValues, true));
7469
}
7570

7671
/**

src/Validator/IPRange.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ abstract class IPRange
1313
*/
1414
final public static function matches(string $ip, array $cidrs): bool
1515
{
16-
foreach ($cidrs as $cidr) {
17-
if (self::matchesOne($ip, $cidr)) {
18-
return true;
19-
}
20-
}
21-
22-
return false;
16+
return array_any($cidrs, fn (string $cidr) => self::matchesOne($ip, $cidr));
2317
}
2418

2519
private static function matchesOne(string $ip, string $cidr): bool

0 commit comments

Comments
 (0)