Skip to content
This repository was archived by the owner on Dec 2, 2021. It is now read-only.

Commit d85ddf7

Browse files
committed
Code optimizations from Psalm
1 parent 11651dd commit d85ddf7

File tree

40 files changed

+343
-72
lines changed

40 files changed

+343
-72
lines changed

Controller/FormController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public function form(Request $request): Response
6464
$this->setPreferredProvider($request, $token);
6565

6666
$providerName = $token->getCurrentTwoFactorProvider();
67+
if (null === $providerName) {
68+
throw new AccessDeniedException('User is not in a two-factor authentication process.');
69+
}
70+
6771
$renderer = $this->providerRegistry->getProvider($providerName)->getFormRenderer();
6872
$templateVars = $this->getTemplateVars($request, $token);
6973

DependencyInjection/Compiler/AuthenticationProviderDecoratorCompilerPass.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
class AuthenticationProviderDecoratorCompilerPass implements CompilerPassInterface
1717
{
18+
/**
19+
* @return void
20+
*/
1821
public function process(ContainerBuilder $container)
1922
{
2023
$authenticationManager = $container->getDefinition('security.authentication.manager');

DependencyInjection/Compiler/RememberMeServicesDecoratorCompilerPass.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class RememberMeServicesDecoratorCompilerPass implements CompilerPassInterface
1818
{
1919
private const REMEMBER_ME_LISTENER_ID_PREFIX = 'security.authentication.listener.rememberme.';
2020

21+
/**
22+
* @return void
23+
*/
2124
public function process(ContainerBuilder $container)
2225
{
2326
// Find all remember-me listener definitions

DependencyInjection/Compiler/TwoFactorFirewallConfigCompilerPass.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
*/
1515
class TwoFactorFirewallConfigCompilerPass implements CompilerPassInterface
1616
{
17+
/**
18+
* @return void
19+
*/
1720
public function process(ContainerBuilder $container)
1821
{
1922
if (!$container->hasDefinition('scheb_two_factor.firewall_context')) {

DependencyInjection/Compiler/TwoFactorProviderCompilerPass.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
class TwoFactorProviderCompilerPass implements CompilerPassInterface
1717
{
18+
/**
19+
* @return void
20+
*/
1821
public function process(ContainerBuilder $container)
1922
{
2023
if (!$container->hasDefinition('scheb_two_factor.provider_registry')) {

DependencyInjection/Configuration.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ public function getConfigTreeBuilder()
1717
$rootNode = $treeBuilder->getRootNode();
1818
} else {
1919
// BC layer for symfony/config 4.1 and older
20+
/** @psalm-suppress UndefinedMethod */
2021
$rootNode = $treeBuilder->root('scheb_two_factor');
2122
}
2223

24+
/**
25+
* @psalm-suppress PossiblyNullReference
26+
* @psalm-suppress PossiblyUndefinedMethod
27+
*/
2328
$rootNode
2429
->children()
2530
->scalarNode('persister')->defaultNull()->end()

DependencyInjection/Factory/Security/TwoFactorFactory.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,18 @@ class TwoFactorFactory implements SecurityFactoryInterface
5050
public const PROVIDER_PREPARATION_LISTENER_DEFINITION_ID = 'scheb_two_factor.security.provider_preparation_listener';
5151
public const AUTHENTICATION_SUCCESS_EVENT_SUPPRESSOR_ID = 'scheb_two_factor.security.authentication_success_event_suppressor';
5252

53+
/**
54+
* @return void
55+
*/
5356
public function addConfiguration(NodeDefinition $node)
5457
{
5558
/** @var ArrayNodeDefinition $node */
5659
$builder = $node->children();
60+
61+
/**
62+
* @psalm-suppress PossiblyNullReference
63+
* @psalm-suppress PossiblyUndefinedMethod
64+
*/
5765
$builder
5866
->scalarNode('check_path')->defaultValue(self::DEFAULT_CHECK_PATH)->end()
5967
->scalarNode('auth_form_path')->defaultValue(self::DEFAULT_AUTH_FORM_PATH)->end()
@@ -75,13 +83,21 @@ public function addConfiguration(NodeDefinition $node)
7583
;
7684
}
7785

78-
public function create(ContainerBuilder $container, $firewallName, $config, $userProvider, $defaultEntryPoint)
86+
/**
87+
* @param string $id
88+
* @param array $config
89+
* @param string $userProvider
90+
* @param string|null $defaultEntryPoint
91+
*
92+
* @return array
93+
*/
94+
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
7995
{
80-
$providerId = $this->createAuthenticationProvider($container, $firewallName, $config);
81-
$listenerId = $this->createAuthenticationListener($container, $firewallName, $config);
82-
$this->createProviderPreparationListener($container, $firewallName, $config);
83-
$this->createAuthenticationSuccessEventSuppressor($container, $firewallName, $config);
84-
$this->createTwoFactorFirewallConfig($container, $firewallName, $config);
96+
$providerId = $this->createAuthenticationProvider($container, $id, $config);
97+
$listenerId = $this->createAuthenticationListener($container, $id, $config);
98+
$this->createProviderPreparationListener($container, $id, $config);
99+
$this->createAuthenticationSuccessEventSuppressor($container, $id);
100+
$this->createTwoFactorFirewallConfig($container, $id, $config);
85101

86102
return [$providerId, $listenerId, $defaultEntryPoint];
87103
}
@@ -213,7 +229,7 @@ private function createProviderPreparationListener(ContainerBuilder $container,
213229
->addTag('kernel.event_listener', ['event' => 'kernel.finish_request', 'method' => 'onKernelFinishRequest']);
214230
}
215231

216-
private function createAuthenticationSuccessEventSuppressor(ContainerBuilder $container, string $firewallName, array $config): void
232+
private function createAuthenticationSuccessEventSuppressor(ContainerBuilder $container, string $firewallName): void
217233
{
218234
$firewallConfigId = self::AUTHENTICATION_SUCCESS_EVENT_SUPPRESSOR_ID_PREFIX.$firewallName;
219235
$container

DependencyInjection/SchebTwoFactorExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class SchebTwoFactorExtension extends Extension
1414
const DEFAULT_TRUSTED_DEVICE_MANAGER = 'scheb_two_factor.default_trusted_device_manager';
1515
const DEFAULT_BACKUP_CODE_MANAGER = 'scheb_two_factor.default_backup_code_manager';
1616

17+
/**
18+
* @return void
19+
*/
1720
public function load(array $configs, ContainerBuilder $container)
1821
{
1922
$configuration = new Configuration();

Model/Persister/DoctrinePersisterFactory.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DoctrinePersisterFactory
1515
private $managerRegistry;
1616

1717
/**
18-
* @var string
18+
* @var string|null
1919
*/
2020
private $objectManagerName;
2121

@@ -33,6 +33,10 @@ public function __construct(?ManagerRegistry $managerRegistry, ?string $objectMa
3333

3434
public function getPersister(): PersisterInterface
3535
{
36-
return new DoctrinePersister($this->managerRegistry->getManager($this->objectManagerName));
36+
$objectManager = $this->managerRegistry->getManager($this->objectManagerName);
37+
/** @psalm-suppress ArgumentTypeCoercion */
38+
$persister = new DoctrinePersister($objectManager);
39+
40+
return $persister;
3741
}
3842
}

Model/Totp/TotpConfiguration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ private static function isValidAlgorithm(string $algorithm): bool
5858
self::ALGORITHM_SHA1,
5959
self::ALGORITHM_SHA256,
6060
self::ALGORITHM_SHA512,
61-
]
61+
],
62+
true
6263
);
6364
}
6465

0 commit comments

Comments
 (0)