diff --git a/.gitignore b/.gitignore index 35b1bd8b15..57d3631e96 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.php_cs .php_cs.cache composer.lock phpunit.xml diff --git a/.php_cs b/.php_cs deleted file mode 100644 index c116902ddb..0000000000 --- a/.php_cs +++ /dev/null @@ -1,35 +0,0 @@ - - -For the full copyright and license information, please view the LICENSE -file that was distributed with this source code. -EOF; - -Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header); - -$finder = Symfony\CS\Finder\DefaultFinder::create() - ->in(array(__DIR__)) -; - -return Symfony\CS\Config\Config::create() - ->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL) - ->fixers(array( - 'combine_consecutive_unsets', - 'header_comment', - 'long_array_syntax', - 'newline_after_open_tag', - 'no_php4_constructor', - 'no_useless_else', - 'ordered_class_elements', - 'ordered_use', - 'php_unit_construct', - 'php_unit_strict', - '-phpdoc_no_empty_return', - )) - ->setUsingCache(true) - ->finder($finder) -; diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000000..b073e7ccd4 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,33 @@ + + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. +EOF; + +return PhpCsFixer\Config::create() + ->setRules([ + '@Symfony' => true, + 'array_syntax' => ['syntax' => 'long'], + 'combine_consecutive_unsets' => true, + 'header_comment' => ['header' => $header], + 'linebreak_after_opening_tag' => true, + 'no_php4_constructor' => true, + 'no_useless_else' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'php_unit_construct' => true, + 'php_unit_strict' => true, + 'phpdoc_no_empty_return' => false, + ]) + ->setUsingCache(true) + ->setRiskyAllowed(true) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__) + ) +; diff --git a/Controller/ProfileController.php b/Controller/ProfileController.php index d7478b550b..ad25e3c0bd 100644 --- a/Controller/ProfileController.php +++ b/Controller/ProfileController.php @@ -27,7 +27,6 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Exception\AccessDeniedException; -use Symfony\Component\Translation\Translator; use Symfony\Component\Translation\TranslatorInterface; /** diff --git a/Controller/SecurityController.php b/Controller/SecurityController.php index d823068b53..869881821e 100644 --- a/Controller/SecurityController.php +++ b/Controller/SecurityController.php @@ -81,6 +81,16 @@ public function loginAction(Request $request) )); } + public function checkAction() + { + throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.'); + } + + public function logoutAction() + { + throw new \RuntimeException('You must activate the logout in your security firewall configuration.'); + } + /** * Renders the login template with the given parameters. Overwrite this function in * an extended controller to provide additional data for the login template. @@ -93,14 +103,4 @@ protected function renderLogin(array $data) { return $this->render('@FOSUser/Security/login.html.twig', $data); } - - public function checkAction() - { - throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.'); - } - - public function logoutAction() - { - throw new \RuntimeException('You must activate the logout in your security firewall configuration.'); - } } diff --git a/DependencyInjection/FOSUserExtension.php b/DependencyInjection/FOSUserExtension.php index 844b123dcd..86e9eb7fd7 100644 --- a/DependencyInjection/FOSUserExtension.php +++ b/DependencyInjection/FOSUserExtension.php @@ -133,6 +133,54 @@ public function load(array $configs, ContainerBuilder $container) } } + /** + * {@inheritdoc} + */ + public function getNamespace() + { + return 'http://friendsofsymfony.github.io/schema/dic/user'; + } + + /** + * @param array $config + * @param ContainerBuilder $container + * @param array $map + */ + protected function remapParameters(array $config, ContainerBuilder $container, array $map) + { + foreach ($map as $name => $paramName) { + if (array_key_exists($name, $config)) { + $container->setParameter($paramName, $config[$name]); + } + } + } + + /** + * @param array $config + * @param ContainerBuilder $container + * @param array $namespaces + */ + protected function remapParametersNamespaces(array $config, ContainerBuilder $container, array $namespaces) + { + foreach ($namespaces as $ns => $map) { + if ($ns) { + if (!array_key_exists($ns, $config)) { + continue; + } + $namespaceConfig = $config[$ns]; + } else { + $namespaceConfig = $config; + } + if (is_array($map)) { + $this->remapParameters($namespaceConfig, $container, $map); + } else { + foreach ($namespaceConfig as $name => $value) { + $container->setParameter(sprintf($map, $name), $value); + } + } + } + } + /** * @param array $config * @param ContainerBuilder $container @@ -254,52 +302,4 @@ private function loadGroups(array $config, ContainerBuilder $container, XmlFileL 'form' => 'fos_user.group.form.%s', )); } - - /** - * @param array $config - * @param ContainerBuilder $container - * @param array $map - */ - protected function remapParameters(array $config, ContainerBuilder $container, array $map) - { - foreach ($map as $name => $paramName) { - if (array_key_exists($name, $config)) { - $container->setParameter($paramName, $config[$name]); - } - } - } - - /** - * @param array $config - * @param ContainerBuilder $container - * @param array $namespaces - */ - protected function remapParametersNamespaces(array $config, ContainerBuilder $container, array $namespaces) - { - foreach ($namespaces as $ns => $map) { - if ($ns) { - if (!array_key_exists($ns, $config)) { - continue; - } - $namespaceConfig = $config[$ns]; - } else { - $namespaceConfig = $config; - } - if (is_array($map)) { - $this->remapParameters($namespaceConfig, $container, $map); - } else { - foreach ($namespaceConfig as $name => $value) { - $container->setParameter(sprintf($map, $name), $value); - } - } - } - } - - /** - * {@inheritdoc} - */ - public function getNamespace() - { - return 'http://friendsofsymfony.github.io/schema/dic/user'; - } } diff --git a/Doctrine/UserManager.php b/Doctrine/UserManager.php index c5b082f363..f11ff87c7c 100644 --- a/Doctrine/UserManager.php +++ b/Doctrine/UserManager.php @@ -46,14 +46,6 @@ public function __construct(PasswordUpdaterInterface $passwordUpdater, Canonical $this->class = $class; } - /** - * @return ObjectRepository - */ - protected function getRepository() - { - return $this->objectManager->getRepository($this->getClass()); - } - /** * {@inheritdoc} */ @@ -113,4 +105,12 @@ public function updateUser(UserInterface $user, $andFlush = true) $this->objectManager->flush(); } } + + /** + * @return ObjectRepository + */ + protected function getRepository() + { + return $this->objectManager->getRepository($this->getClass()); + } } diff --git a/Form/Type/ChangePasswordFormType.php b/Form/Type/ChangePasswordFormType.php index 35e4fe2e76..e0f08d4320 100644 --- a/Form/Type/ChangePasswordFormType.php +++ b/Form/Type/ChangePasswordFormType.php @@ -86,6 +86,7 @@ public function configureOptions(OptionsResolver $resolver) } // BC for SF < 3.0 + /** * {@inheritdoc} */ diff --git a/Form/Type/GroupFormType.php b/Form/Type/GroupFormType.php index 71372ceecc..151cc7e006 100644 --- a/Form/Type/GroupFormType.php +++ b/Form/Type/GroupFormType.php @@ -50,6 +50,7 @@ public function configureOptions(OptionsResolver $resolver) } // BC for SF < 3.0 + /** * {@inheritdoc} */ diff --git a/Form/Type/ProfileFormType.php b/Form/Type/ProfileFormType.php index b6c6f682f5..21e1c4e1b0 100644 --- a/Form/Type/ProfileFormType.php +++ b/Form/Type/ProfileFormType.php @@ -75,6 +75,7 @@ public function configureOptions(OptionsResolver $resolver) } // BC for SF < 3.0 + /** * {@inheritdoc} */ diff --git a/Form/Type/RegistrationFormType.php b/Form/Type/RegistrationFormType.php index 9793b1942e..4a269cfb31 100644 --- a/Form/Type/RegistrationFormType.php +++ b/Form/Type/RegistrationFormType.php @@ -68,6 +68,7 @@ public function configureOptions(OptionsResolver $resolver) } // BC for SF < 3.0 + /** * {@inheritdoc} */ diff --git a/Form/Type/ResettingFormType.php b/Form/Type/ResettingFormType.php index 6720d44be1..da2c5d8c5e 100644 --- a/Form/Type/ResettingFormType.php +++ b/Form/Type/ResettingFormType.php @@ -63,6 +63,7 @@ public function configureOptions(OptionsResolver $resolver) } // BC for SF < 3.0 + /** * {@inheritdoc} */ diff --git a/Form/Type/UsernameFormType.php b/Form/Type/UsernameFormType.php index 70cc215ce8..8e4ffa1913 100644 --- a/Form/Type/UsernameFormType.php +++ b/Form/Type/UsernameFormType.php @@ -55,6 +55,7 @@ public function getParent() } // BC for SF < 3.0 + /** * @return string */ diff --git a/Mailer/TwigSwiftMailer.php b/Mailer/TwigSwiftMailer.php index 070fb3124a..83f7ad25bc 100644 --- a/Mailer/TwigSwiftMailer.php +++ b/Mailer/TwigSwiftMailer.php @@ -87,6 +87,26 @@ public function sendResettingEmailMessage(UserInterface $user) $this->sendMessage($template, $context, $this->parameters['from_email']['resetting'], (string) $user->getEmail()); } + /** + * Send confirmation link to specified new user email. + * + * @param UserInterface $user + * @param $confirmationUrl + * @param $toEmail + * + * @return bool + */ + public function sendUpdateEmailConfirmation(UserInterface $user, $confirmationUrl, $toEmail) + { + $template = $this->parameters['template']['email_updating']; + $context = array( + 'user' => $user, + 'confirmationUrl' => $confirmationUrl, + ); + + $this->sendMessage($template, $context, $this->parameters['from_email']['confirmation'], $toEmail); + } + /** * @param string $templateName * @param array $context @@ -119,24 +139,4 @@ protected function sendMessage($templateName, $context, $fromEmail, $toEmail) $this->mailer->send($message); } - - /** - * Send confirmation link to specified new user email. - * - * @param UserInterface $user - * @param $confirmationUrl - * @param $toEmail - * - * @return bool - */ - public function sendUpdateEmailConfirmation(UserInterface $user, $confirmationUrl, $toEmail) - { - $template = $this->parameters['template']['email_updating']; - $context = array( - 'user' => $user, - 'confirmationUrl' => $confirmationUrl, - ); - - $this->sendMessage($template, $context, $this->parameters['from_email']['confirmation'], $toEmail); - } } diff --git a/Model/GroupManager.php b/Model/GroupManager.php index ea6e3c9b82..5c642de477 100644 --- a/Model/GroupManager.php +++ b/Model/GroupManager.php @@ -28,6 +28,7 @@ public function createGroup($name) return new $class($name); } + /** * {@inheritdoc} */ diff --git a/Model/User.php b/Model/User.php index 02bfad0cab..42ca1ad8d8 100644 --- a/Model/User.php +++ b/Model/User.php @@ -109,6 +109,14 @@ public function __construct() $this->roles = array(); } + /** + * @return string + */ + public function __toString() + { + return (string) $this->getUsername(); + } + /** * {@inheritdoc} */ @@ -546,12 +554,4 @@ public function removeGroup(GroupInterface $group) return $this; } - - /** - * @return string - */ - public function __toString() - { - return (string) $this->getUsername(); - } } diff --git a/Model/UserManager.php b/Model/UserManager.php index bf42ea6653..11cd2cff14 100644 --- a/Model/UserManager.php +++ b/Model/UserManager.php @@ -65,7 +65,7 @@ public function findUserByUsernameOrEmail($usernameOrEmail) { if (preg_match('/^.+\@\S+\.\S+$/', $usernameOrEmail)) { $user = $this->findUserByEmail($usernameOrEmail); - if ($user !== null) { + if (null !== $user) { return $user; } } diff --git a/Services/EmailConfirmation/EmailUpdateConfirmation.php b/Services/EmailConfirmation/EmailUpdateConfirmation.php index 3506c931d5..b3d98137f7 100644 --- a/Services/EmailConfirmation/EmailUpdateConfirmation.php +++ b/Services/EmailConfirmation/EmailUpdateConfirmation.php @@ -200,6 +200,16 @@ public function setConfirmationRoute($confirmationRoute) return $this; } + /** + * Get token which indicates that email was confirmed. + * + * @return string + */ + public function getEmailConfirmedToken() + { + return base64_encode(self::EMAIL_CONFIRMED); + } + /** * Get or create new user confirmation token. * @@ -216,14 +226,4 @@ protected function getUserConfirmationToken() return $this->user->getConfirmationToken(); } - - /** - * Get token which indicates that email was confirmed. - * - * @return string - */ - public function getEmailConfirmedToken() - { - return base64_encode(self::EMAIL_CONFIRMED); - } } diff --git a/Tests/DependencyInjection/FOSUserExtensionTest.php b/Tests/DependencyInjection/FOSUserExtensionTest.php index b10860eae8..31aef1cb8d 100644 --- a/Tests/DependencyInjection/FOSUserExtensionTest.php +++ b/Tests/DependencyInjection/FOSUserExtensionTest.php @@ -21,6 +21,11 @@ class FOSUserExtensionTest extends TestCase /** @var ContainerBuilder */ protected $configuration; + protected function tearDown() + { + unset($this->configuration); + } + /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException */ @@ -465,9 +470,4 @@ private function assertNotHasDefinition($id) { $this->assertFalse(($this->configuration->hasDefinition($id) ?: $this->configuration->hasAlias($id))); } - - protected function tearDown() - { - unset($this->configuration); - } } diff --git a/Tests/Mailer/MailerTest.php b/Tests/Mailer/MailerTest.php index a8e10e20ac..0950369248 100644 --- a/Tests/Mailer/MailerTest.php +++ b/Tests/Mailer/MailerTest.php @@ -61,6 +61,24 @@ public function testSendResettingEmailMessageWithBadEmails($emailAddress) $mailer->sendResettingEmailMessage($this->getUser($emailAddress)); } + public function goodEmailProvider() + { + return array( + array('foo@example.com'), + array('foo@example.co.uk'), + array($this->getEmailAddressValueObject('foo@example.com')), + array($this->getEmailAddressValueObject('foo@example.co.uk')), + ); + } + + public function badEmailProvider() + { + return array( + array('foo'), + array($this->getEmailAddressValueObject('foo')), + ); + } + private function getMailer() { return new Mailer( @@ -114,22 +132,4 @@ private function getEmailAddressValueObject($emailAddressAsString) return $emailAddress; } - - public function goodEmailProvider() - { - return array( - array('foo@example.com'), - array('foo@example.co.uk'), - array($this->getEmailAddressValueObject('foo@example.com')), - array($this->getEmailAddressValueObject('foo@example.co.uk')), - ); - } - - public function badEmailProvider() - { - return array( - array('foo'), - array($this->getEmailAddressValueObject('foo')), - ); - } } diff --git a/Tests/Mailer/TwigSwiftMailerTest.php b/Tests/Mailer/TwigSwiftMailerTest.php index e6d1ec047a..f56e02292b 100644 --- a/Tests/Mailer/TwigSwiftMailerTest.php +++ b/Tests/Mailer/TwigSwiftMailerTest.php @@ -60,6 +60,24 @@ public function testSendResettingEmailMessageWithBadEmails($emailAddress) $mailer->sendResettingEmailMessage($this->getUser($emailAddress)); } + public function goodEmailProvider() + { + return array( + array('foo@example.com'), + array('foo@example.co.uk'), + array($this->getEmailAddressValueObject('foo@example.com')), + array($this->getEmailAddressValueObject('foo@example.co.uk')), + ); + } + + public function badEmailProvider() + { + return array( + array('foo'), + array($this->getEmailAddressValueObject('foo')), + ); + } + private function getTwigSwiftMailer() { return new TwigSwiftMailer( @@ -116,22 +134,4 @@ private function getEmailAddressValueObject($emailAddressAsString) return $emailAddress; } - - public function goodEmailProvider() - { - return array( - array('foo@example.com'), - array('foo@example.co.uk'), - array($this->getEmailAddressValueObject('foo@example.com')), - array($this->getEmailAddressValueObject('foo@example.co.uk')), - ); - } - - public function badEmailProvider() - { - return array( - array('foo'), - array($this->getEmailAddressValueObject('foo')), - ); - } } diff --git a/Tests/Util/UserManipulatorTest.php b/Tests/Util/UserManipulatorTest.php index 570293e5c8..9eb50ea64a 100644 --- a/Tests/Util/UserManipulatorTest.php +++ b/Tests/Util/UserManipulatorTest.php @@ -79,7 +79,7 @@ public function testActivateWithValidUsername() $manipulator->activate($username); $this->assertSame($username, $user->getUsername()); - $this->assertSame(true, $user->isEnabled()); + $this->assertTrue($user->isEnabled()); } /** @@ -133,7 +133,7 @@ public function testDeactivateWithValidUsername() $manipulator->deactivate($username); $this->assertSame($username, $user->getUsername()); - $this->assertSame(false, $user->isEnabled()); + $this->assertFalse($user->isEnabled()); } /** @@ -187,7 +187,7 @@ public function testPromoteWithValidUsername() $manipulator->promote($username); $this->assertSame($username, $user->getUsername()); - $this->assertSame(true, $user->isSuperAdmin()); + $this->assertTrue($user->isSuperAdmin()); } /** @@ -241,7 +241,7 @@ public function testDemoteWithValidUsername() $manipulator->demote($username); $this->assertSame($username, $user->getUsername()); - $this->assertSame(false, $user->isSuperAdmin()); + $this->assertFalse($user->isSuperAdmin()); } /** diff --git a/composer.json b/composer.json index 161eb0bcd5..b4ca7720b8 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ }, "require-dev": { "doctrine/doctrine-bundle": "^1.3", - "friendsofphp/php-cs-fixer": "^1.11", + "friendsofphp/php-cs-fixer": "^2.2", "swiftmailer/swiftmailer": "^4.3 || ^5.0 || ^6.0", "symfony/console": "^2.8 || ^3.0 || ^4.0", "symfony/phpunit-bridge": "^2.8 || ^3.0 || ^4.0",