Issues (324)

src/Manager/ActivationLinkManager.php (2 issues)

Labels
Severity
1
<?php
2
namespace App\Manager;
3
4
use Doctrine\ORM\EntityManagerInterface;
5
use App\Entity\User\{User, ActivationLink};
6
use App\Utils\Mailer;
7
8
class ActivationLinkManager
9
{
10
    /** @var EntityManagerInterface **/
11
    protected $em;
12
    /** @var Mailer **/
13
    protected $mailer;
14
15
    /**
16
     * @param EntityManagerInterface $em
17
     * @param Mailer $mailer
18
     */
19 19
    public function __construct(EntityManagerInterface $em, Mailer $mailer)
20
    {
21 19
        $this->em = $em;
22 19
        $this->mailer = $mailer;
23 19
    }
24
25
    /**
26
     * @param \User $user
0 ignored issues
show
The type User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
     */
28 4
    public function createActivationLink(User $user)
29
    {
30
        $activationLink =
31 4
            (new ActivationLink())
32 4
            ->setHash(md5(uniqid(null, true)))
33
        ;
34 4
        $user->setActivationLink($activationLink);
35 4
        $this->em->persist($activationLink);
36 4
        $this->em->persist($user);
37 4
        $this->em->flush();
38 4
    }
39
40
    /**
41
     * @param User $user
42
     * @return bool
43
     */
44 3
    public function sendValidationMail(User $user): bool
45
    {
46 3
        $nbRecipients = $this->mailer->sendTo($user->getEmail(), 'users.registration.mails.confirmation', [
47 3
            '%username%' => $user->getUsername(),
48 3
            '%activation_link%' => $user->getActivationLink()->getHash()
49 3
        ], 'Personal');
50 3
        return $nbRecipients > 0;
51
    }
52
53
    /**
54
     * @param string $hash
55
     * @return ActivationLink
56
     */
57 1
    public function findOneByHash(string $hash)
58
    {
59 1
        return $this->em->getRepository(ActivationLink::class)->findOneByHash($hash);
0 ignored issues
show
The method findOneByHash() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findOneBy()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
        return $this->em->getRepository(ActivationLink::class)->/** @scrutinizer ignore-call */ findOneByHash($hash);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
    }
61
}
62