SelfRecipientValidator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the MilioooMessageBundle package.
5
 *
6
 * (c) Michiel boeckaert <[email protected]>
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Miliooo\MessagingBundle\Validator\Constraint;
12
13
use Symfony\Component\Validator\Constraint;
14
use Symfony\Component\Validator\ConstraintValidator;
15
use Miliooo\Messaging\User\ParticipantInterface;
16
use Miliooo\Messaging\User\ParticipantProviderInterface;
17
18
/**
19
 * Class SelfRecipientValidator
20
 *
21
 * @author Michiel Boeckaert <[email protected]>
22
 */
23
class SelfRecipientValidator extends ConstraintValidator
24
{
25
    /**
26
     * A participant provider instance.
27
     *
28
     * @var ParticipantProviderInterface
29
     */
30
    private $participantProvider;
31
32
    /**
33
     * Constructor.
34
     *
35
     * @param ParticipantProviderInterface $participantProvider
36
     */
37
    public function __construct(ParticipantProviderInterface $participantProvider)
38
    {
39
        $this->participantProvider = $participantProvider;
40
    }
41
42
    /**
43
     * @param ParticipantInterface $recipient
44
     * @param Constraint           $constraint
45
     */
46
    public function validate($recipient, Constraint $constraint)
47
    {
48
        if ($recipient === $this->participantProvider->getAuthenticatedParticipant()) {
49
            $this->context->addViolation($constraint->message);
50
        }
51
    }
52
}
53