Skip to content

Commit

Permalink
Symfony 5.4 deprecation warnings free
Browse files Browse the repository at this point in the history
Symfony 5.4 force the use of native return type declarations
  • Loading branch information
Klapaudius committed Jan 13, 2022
1 parent e0d06ba commit 1c4691c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 52 deletions.
2 changes: 1 addition & 1 deletion DependencyInjection/FOSOAuthServerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function load(array $configs, ContainerBuilder $container)
/**
* {@inheritdoc}
*/
public function getAlias()
public function getAlias(): string
{
return 'fos_oauth_server';
}
Expand Down
39 changes: 5 additions & 34 deletions DependencyInjection/Security/Factory/OAuthFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace FOS\OAuthServerBundle\DependencyInjection\Security\Factory;

use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\ChildDefinition;
Expand All @@ -26,9 +25,9 @@
*
* @author Arnaud Le Blanc <[email protected]>
*/
class OAuthFactory implements SecurityFactoryInterface, AuthenticatorFactoryInterface
class OAuthFactory implements AuthenticatorFactoryInterface
{
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId)
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string
{
$authenticatorId = 'security.authenticator.oauth2.'.$firewallName;
$firewallEventDispatcherId = 'security.event_dispatcher.'.$firewallName;
Expand Down Expand Up @@ -70,43 +69,15 @@ public function createAuthenticator(ContainerBuilder $container, string $firewal
return $authenticatorId;
}

/**
* {@inheritdoc}
*/
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
{
// NOTE: done like this to avoid PHPStan complaining about a missing class for both Symfony v3 and Symfony v4
$definitionDecorator = 'Symfony\\Component\\DependencyInjection\\DefinitionDecorator';
$childDefinition = 'Symfony\\Component\\DependencyInjection\\ChildDefinition';
$definitionClass = $childDefinition;
if (class_exists($definitionDecorator)) {
$definitionClass = $definitionDecorator;
}

$providerId = 'security.authentication.provider.fos_oauth_server.'.$id;
$container
->setDefinition($providerId, new $definitionClass('fos_oauth_server.security.authentication.provider'))
->replaceArgument(0, new Reference($userProvider))
;

$listenerId = 'security.authentication.listener.fos_oauth_server.'.$id;
$container->setDefinition($listenerId, new $definitionClass('fos_oauth_server.security.authentication.listener'));

return [$providerId, $listenerId, 'fos_oauth_server.security.entry_point'];
}

/**
* {@inheritdoc}
*/
public function getPosition()
public function getPriority(): int
{
return 'pre_auth';
return 0;
}

/**
* {@inheritdoc}
*/
public function getKey()
public function getKey(): string
{
return 'fos_oauth';
}
Expand Down
2 changes: 1 addition & 1 deletion FOSOAuthServerBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function build(ContainerBuilder $container)

/** @var SecurityExtension $extension */
$extension = $container->getExtension('security');
$extension->addSecurityListenerFactory(new OAuthFactory());
$extension->addAuthenticatorFactory(new OAuthFactory());

$container->addCompilerPass(new GrantExtensionsCompilerPass());
$container->addCompilerPass(new TokenStorageCompilerPass());
Expand Down
20 changes: 10 additions & 10 deletions Model/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ class Client implements ClientInterface
/**
* @var string
*/
protected $randomId;
protected string $randomId;

/**
* @var string
*/
protected $secret;
protected string $secret;

/**
* @var array
*/
protected $redirectUris = [];
protected array $redirectUris = [];

/**
* @var array
*/
protected $allowedGrantTypes = [];
protected array $allowedGrantTypes = [];

public function __construct()
{
Expand Down Expand Up @@ -75,7 +75,7 @@ public function getRandomId(): string
/**
* {@inheritdoc}
*/
public function getPublicId()
public function getPublicId(): string
{
return sprintf('%s_%s', $this->getId(), $this->getRandomId());
}
Expand Down Expand Up @@ -115,7 +115,7 @@ public function setRedirectUris(array $redirectUris)
/**
* {@inheritdoc}
*/
public function getRedirectUris()
public function getRedirectUris(): array
{
return $this->redirectUris;
}
Expand All @@ -136,17 +136,17 @@ public function getAllowedGrantTypes(): array
return $this->allowedGrantTypes;
}

public function getRoles()
public function getRoles(): array
{
return [ 'ROLE_USER' ];
}

public function getPassword()
public function getPassword(): string
{
return $this->getSecret();
}

public function getSalt()
public function getSalt(): ?string
{
// Will use auto salt system
}
Expand All @@ -156,7 +156,7 @@ public function eraseCredentials()
// nothind to erase
}

public function getUsername()
public function getUsername(): string
{
return $this->getRandomId();
}
Expand Down
13 changes: 7 additions & 6 deletions Model/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Token implements TokenInterface
/**
* @var string
*/
protected $token;
protected string $token;

/**
* @var int
Expand All @@ -55,7 +55,7 @@ public function getId()
/**
* {@inheritdoc}
*/
public function getClientId()
public function getClientId(): string
{
return $this->getClient()->getPublicId();
}
Expand All @@ -79,7 +79,7 @@ public function getExpiresAt(): int
/**
* {@inheritdoc}
*/
public function getExpiresIn()
public function getExpiresIn(): int
{
if ($this->expiresAt) {
return $this->expiresAt - time();
Expand All @@ -91,7 +91,7 @@ public function getExpiresIn()
/**
* {@inheritdoc}
*/
public function hasExpired()
public function hasExpired(): bool
{
if ($this->expiresAt) {
return time() > $this->expiresAt;
Expand All @@ -111,7 +111,7 @@ public function setToken($token)
/**
* {@inheritdoc}
*/
public function getToken()
public function getToken(): string
{
return $this->token;
}
Expand All @@ -127,7 +127,7 @@ public function setScope($scope)
/**
* {@inheritdoc}
*/
public function getScope()
public function getScope(): ?string
{
return $this->scope;
}
Expand All @@ -150,6 +150,7 @@ public function getUser(): ?UserInterface

/**
* {@inheritdoc}
* @return mixed
*/
public function getData()
{
Expand Down

0 comments on commit 1c4691c

Please sign in to comment.