Skip to content
This repository has been archived by the owner on Dec 17, 2022. It is now read-only.

Commit

Permalink
PHP 8.1 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpapst committed Nov 19, 2022
1 parent c618bf9 commit 0da3d1a
Show file tree
Hide file tree
Showing 21 changed files with 77 additions and 54 deletions.
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

### 3.0

Cleanup and support for PHP 8.1

- Added phpstan level 5 (`vendor/bin/phpstan analyse -c phpstan.neon .`)
- Removed profile section from Configuration
- Some changes that might lead to tiny BC breaks ... who knows (this bundle should NOT BE USED ANYWAYS!)

### 2.0

Bump required PHP version to >= 7.3
Expand Down
6 changes: 5 additions & 1 deletion Command/ActivateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use FOS\UserBundle\Util\UserManipulator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -81,7 +82,10 @@ protected function interact(InputInterface $input, OutputInterface $output)

return $username;
});
$answer = $this->getHelper('question')->ask($input, $output, $question);

/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
$answer = $helper->ask($input, $output, $question);

$input->setArgument('username', $answer);
}
Expand Down
5 changes: 4 additions & 1 deletion Command/ChangePasswordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use FOS\UserBundle\Util\UserManipulator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -105,8 +106,10 @@ protected function interact(InputInterface $input, OutputInterface $output)
$questions['password'] = $question;
}

/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
foreach ($questions as $name => $question) {
$answer = $this->getHelper('question')->ask($input, $output, $question);
$answer = $helper->ask($input, $output, $question);
$input->setArgument($name, $answer);
}
}
Expand Down
5 changes: 4 additions & 1 deletion Command/CreateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use FOS\UserBundle\Util\UserManipulator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -137,8 +138,10 @@ protected function interact(InputInterface $input, OutputInterface $output)
$questions['password'] = $question;
}

/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
foreach ($questions as $name => $question) {
$answer = $this->getHelper('question')->ask($input, $output, $question);
$answer = $helper->ask($input, $output, $question);
$input->setArgument($name, $answer);
}
}
Expand Down
5 changes: 4 additions & 1 deletion Command/DeactivateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use FOS\UserBundle\Util\UserManipulator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -81,7 +82,9 @@ protected function interact(InputInterface $input, OutputInterface $output)

return $username;
});
$answer = $this->getHelper('question')->ask($input, $output, $question);
/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
$answer = $helper->ask($input, $output, $question);

$input->setArgument('username', $answer);
}
Expand Down
5 changes: 4 additions & 1 deletion Command/RoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use FOS\UserBundle\Util\UserManipulator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -109,8 +110,10 @@ protected function interact(InputInterface $input, OutputInterface $output)
$questions['role'] = $question;
}

/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
foreach ($questions as $name => $question) {
$answer = $this->getHelper('question')->ask($input, $output, $question);
$answer = $helper->ask($input, $output, $question);
$input->setArgument($name, $answer);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(CsrfTokenManagerInterface $tokenManager = null)
*/
public function loginAction(Request $request)
{
/** @var $session Session */
/** @var Session $session */
$session = $request->getSession();

$authErrorKey = Security::AUTHENTICATION_ERROR;
Expand Down
36 changes: 3 additions & 33 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('fos_user');

if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
$rootNode = $treeBuilder->root('fos_user');
}
/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();

$supportedDrivers = ['orm', 'custom'];

Expand All @@ -46,7 +42,7 @@ public function getConfigTreeBuilder()
->scalarNode('db_driver')
->validate()
->ifNotInArray($supportedDrivers)
->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($supportedDrivers))
->thenInvalid('The driver %s is not supported. Please choose one of: '.implode(', ', $supportedDrivers))
->end()
->cannotBeOverwritten()
->isRequired()
Expand Down Expand Up @@ -75,39 +71,13 @@ public function getConfigTreeBuilder()
->end()
;

$this->addProfileSection($rootNode);
$this->addRegistrationSection($rootNode);
$this->addResettingSection($rootNode);
$this->addServiceSection($rootNode);

return $treeBuilder;
}

private function addProfileSection(ArrayNodeDefinition $node)
{
$node
->children()
->arrayNode('profile')
->addDefaultsIfNotSet()
->canBeUnset()
->children()
->arrayNode('form')
->addDefaultsIfNotSet()
->fixXmlConfig('validation_group')
->children()
->scalarNode('type')->defaultValue(Type\ProfileFormType::class)->end()
->scalarNode('name')->defaultValue('fos_user_profile_form')->end()
->arrayNode('validation_groups')
->prototype('scalar')->end()
->defaultValue(['Profile', 'Default'])
->end()
->end()
->end()
->end()
->end()
->end();
}

private function addRegistrationSection(ArrayNodeDefinition $node)
{
$node
Expand Down
1 change: 1 addition & 0 deletions Doctrine/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace FOS\UserBundle\Doctrine;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectRepository;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManager as BaseUserManager;
Expand Down
4 changes: 2 additions & 2 deletions Event/GetResponseNullableUserEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace FOS\UserBundle\Event;

use FOS\UserBundle\Model\UserInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\User\UserInterface;

/**
* Response user event that allows null user.
Expand All @@ -24,7 +24,7 @@ class GetResponseNullableUserEvent extends GetResponseUserEvent
/**
* GetResponseNullableUserEvent constructor.
*/
public function __construct(UserInterface $user = null, Request $request)
public function __construct(?UserInterface $user, Request $request)
{
$this->user = $user;
$this->request = $request;
Expand Down
2 changes: 1 addition & 1 deletion Event/UserEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class UserEvent extends Event
protected $request;

/**
* @var UserInterface
* @var UserInterface|null
*/
protected $user;

Expand Down
2 changes: 1 addition & 1 deletion EventListener/EmailConfirmationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static function getSubscribedEvents()

public function onRegistrationSuccess(FormEvent $event)
{
/** @var $user \FOS\UserBundle\Model\UserInterface */
/** @var \FOS\UserBundle\Model\UserInterface $user */
$user = $event->getForm()->getData();

$user->setEnabled(false);
Expand Down
5 changes: 4 additions & 1 deletion EventListener/FlashListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

Expand Down Expand Up @@ -65,7 +66,9 @@ public function addSuccessFlash($event, $eventName)
throw new \InvalidArgumentException('This event does not correspond to a known flash message');
}

$this->session->getFlashBag()->add('success', $this->trans(self::$successMessages[$eventName]));
if ($this->session instanceof Session) {
$this->session->getFlashBag()->add('success', $this->trans(self::$successMessages[$eventName]));
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion EventListener/ResettingListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function onResettingResetInitialize(GetResponseUserEvent $event)

public function onResettingResetSuccess(FormEvent $event)
{
/** @var $user \FOS\UserBundle\Model\UserInterface */
/** @var \FOS\UserBundle\Model\UserInterface $user */
$user = $event->getForm()->getData();

$user->setConfirmationToken(null);
Expand Down
6 changes: 3 additions & 3 deletions Form/DataTransformer/UserToUsernameTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(UserManagerInterface $userManager)
public function transform($value)
{
if (null === $value) {
return;
return null;
}

if (!$value instanceof UserInterface) {
Expand All @@ -63,14 +63,14 @@ public function transform($value)
*
* @param string $value Username
*
* @return UserInterface the corresponding UserInterface instance
* @return UserInterface|null the corresponding UserInterface instance
*
* @throws UnexpectedTypeException if the given value is not a string
*/
public function reverseTransform($value)
{
if (null === $value || '' === $value) {
return;
return null;
}

if (!is_string($value)) {
Expand Down
2 changes: 1 addition & 1 deletion Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ abstract class User implements UserInterface
/**
* Plain password. Used for model validation. Must not be persisted.
*
* @var string
* @var string|null
*/
protected $plainPassword;

Expand Down
2 changes: 1 addition & 1 deletion Model/UserManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function findUserByConfirmationToken($token);
/**
* Returns a collection with all user instances.
*
* @return \Traversable
* @return array
*/
public function findUsers();

Expand Down
7 changes: 5 additions & 2 deletions Security/UserChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FOS\UserBundle\Security;

use FOS\UserBundle\Model\UserInterface;
use Symfony\Component\Security\Core\Exception\AccountExpiredException;
use Symfony\Component\Security\Core\Exception\CredentialsExpiredException;
use Symfony\Component\Security\Core\Exception\DisabledException;
Expand All @@ -26,7 +27,8 @@
class UserChecker extends BaseUserChecker
{
/**
* {@inheritdoc}
* @param UserInterface $user
* @return void
*/
public function checkPreAuth(BaseUserInterface $user)
{
Expand All @@ -50,7 +52,8 @@ public function checkPreAuth(BaseUserInterface $user)
}

/**
* {@inheritdoc}
* @param UserInterface $user
* @return void
*/
public function checkPostAuth(BaseUserInterface $user)
{
Expand Down
2 changes: 1 addition & 1 deletion Util/Canonicalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Canonicalizer implements CanonicalizerInterface
public function canonicalize($string)
{
if (null === $string) {
return;
throw new \InvalidArgumentException('Null given for canonicalize()');
}

$encoding = mb_detect_encoding($string);
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}
],
"require": {
"php": ">=7.3",
"php": ">=7.3 || 8.1.*",
"paragonie/random_compat": "^1 || ^2 || ^9",
"symfony/form": "^4.4",
"symfony/framework-bundle": "^4.4",
Expand All @@ -33,6 +33,11 @@
},
"require-dev": {
"doctrine/doctrine-bundle": "^2.0",
"doctrine/orm": "^2.7",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-doctrine": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-symfony": "^1.0",
"phpunit/phpunit": "^4.8.35 || ^5.7.11 || ^6.5 || ^8.0 || ^9.0",
"swiftmailer/swiftmailer": "^4.3 || ^5.0 || ^6.0",
"symfony/console": "^4.0",
Expand Down
17 changes: 17 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
includes:
- %rootDir%/../phpstan-symfony/extension.neon
- %rootDir%/../phpstan-symfony/rules.neon
- %rootDir%/../phpstan-doctrine/extension.neon
- %rootDir%/../phpstan-doctrine/rules.neon
- %rootDir%/../phpstan/conf/bleedingEdge.neon

parameters:
level: 5
treatPhpDocTypesAsCertain: false
inferPrivatePropertyTypeFromConstructor: true
checkGenericClassInNonGenericObjectType: false
excludePaths:
- %rootDir%/../../../Tests/
- %rootDir%/../../../vendor/
ignoreErrors:
- '#Method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\) invoked with 2 parameters, 1 required.#'

0 comments on commit 0da3d1a

Please sign in to comment.