Skip to content

Commit 66d97ed

Browse files
committed
Merge branch 'develop'
* develop: - Fix `OrderedUseStatements` when `use function` is used (#2029) Add testcase
2 parents f360377 + 71ce4ca commit 66d97ed

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/Rule/OrderedUseStatements.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ private function extractClass(string $useStatement): string
9999
->trim()
100100
->replace('\\', 'A') // the "A" here helps to sort !!
101101
->lower()
102+
->replace('function ', 'zzzfunction') // prefix with "zzz" to sort functions at the end
102103
->toString();
103104
}
104105
}

tests/Rule/OrderedUseStatementsTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,62 @@ public function doSomething()
267267
}
268268
RST;
269269

270+
$valid_with_function = <<<'RST'
271+
for that::
272+
273+
use Symfony\Component\Form\AbstractType;
274+
use function Symfony\foo;
275+
RST;
276+
277+
$valid3 = <<<'RST'
278+
and storage::
279+
280+
// src/Security/NormalizedUserBadge.php
281+
namespace App\Security;
282+
283+
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
284+
use function Symfony\Component\String\u;
285+
286+
final class NormalizedUserBadge extends UserBadge
287+
{
288+
public function __construct(string $identifier)
289+
{
290+
$callback = static fn (string $identifier): string => u($identifier)->normalize(UnicodeString::NFKC)->ascii()->lower()->toString();
291+
292+
parent::__construct($identifier, null, $callback);
293+
}
294+
}
295+
296+
::
297+
298+
// src/Security/PasswordAuthenticator.php
299+
namespace App\Security;
300+
301+
final class PasswordAuthenticator extends AbstractLoginFormAuthenticator
302+
{
303+
// simplified for brevity
304+
public function authenticate(Request $request): Passport
305+
{
306+
$username = (string) $request->request->get('username', '');
307+
$password = (string) $request->request->get('password', '');
308+
309+
$request->getSession()
310+
->set(SecurityRequestAttributes::LAST_USERNAME, $username);
311+
312+
return new Passport(
313+
new NormalizedUserBadge($username),
314+
new PasswordCredentials($password),
315+
[
316+
// all other useful badges
317+
]
318+
);
319+
}
320+
}
321+
322+
User Credential
323+
~~~~~~~~~~~~~~~
324+
RST;
325+
270326
yield 'valid with trait' => [
271327
NullViolation::create(),
272328
new RstSample($valid_with_trait, 1),
@@ -299,5 +355,13 @@ public function doSomething()
299355
NullViolation::create(),
300356
new RstSample($valid_in_trait_definition, 1),
301357
];
358+
yield 'valid with function' => [
359+
NullViolation::create(),
360+
new RstSample($valid_with_function, 1),
361+
];
362+
yield 'valid 3' => [
363+
NullViolation::create(),
364+
new RstSample($valid3),
365+
];
302366
}
303367
}

0 commit comments

Comments
 (0)