Completed
Pull Request — master (#2737)
by Jeroen
10:25
created

EventListener/PasswordResettingListener.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\AdminBundle\EventListener;
4
5
use FOS\UserBundle\Event\FilterUserResponseEvent;
6
use FOS\UserBundle\Model\UserManager as FOSUserManager;
7
use Kunstmaan\AdminBundle\Event\ChangePasswordSuccessEvent;
8
use Kunstmaan\AdminBundle\Service\UserManager;
9
10
/**
11
 * Set password_changed property to 1 after changing the password
12
 */
13
class PasswordResettingListener
14
{
15
    /**
16
     * @var UserManager
17
     */
18
    private $userManager;
19
20
    /**
21
     * @param UserManager $userManager
22
     */
23 1 View Code Duplication
    public function __construct(/* UserManager */ $userManager)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25 1
        if (!$userManager instanceof UserManager && !$userManager instanceof FOSUserManager) {
26
            throw new \InvalidArgumentException(sprintf('The "$userManager" argument must be of type "%s" or type "%s"', UserManager::class, FOSUserManager::class));
27
        }
28 1
        if ($userManager instanceof FOSUserManager) {
29
            // NEXT_MAJOR set the usermanaged typehint to the kunstmaan usermanager.
30 1
            @trigger_error(sprintf('Passing the usermanager from FOSUserBundle as the first argument of "%s" is deprecated since KunstmaanAdminBundle 5.8 and will be removed in KunstmaanAdminBundle 6.0. Use the "%s" class instead.', __METHOD__, UserManager::class), E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
31
        }
32 1
        $this->userManager = $userManager;
33 1
    }
34
35
    /**
36
     * @param FilterUserResponseEvent $event
37
     *
38
     * @deprecated Using the Fos FilterUserResponseEvent is deprecated in KunstmaanNodeBundle 5.8 and will be removed in KunstmaanNodeBundle 6.0. Use the "Kunstmaan\AdminBundle\Event\ ChangePasswordSuccessEvent" instead.
39
     */
40 1
    public function onPasswordResettingSuccess(FilterUserResponseEvent $event)
41
    {
42 1
        $user = $event->getUser();
43 1
        $user->setPasswordChanged(true);
44 1
        $this->userManager->updateUser($user);
0 ignored issues
show
$user of type object<FOS\UserBundle\Model\UserInterface> is not a sub-type of object<Kunstmaan\AdminBu...e\Entity\UserInterface>. It seems like you assume a child interface of the interface FOS\UserBundle\Model\UserInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
45 1
    }
46
47
    public function onPasswordResettingSuccessCMS(ChangePasswordSuccessEvent $event)
48
    {
49
        $user = $event->getUser();
50
        $user->setPasswordChanged(true);
0 ignored issues
show
The method setPasswordChanged() does not exist on Kunstmaan\AdminBundle\Entity\UserInterface. Did you maybe mean setPassword()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
51
        $this->userManager->updateUser($user);
52
    }
53
}
54