CanMessageRecipientManager::getErrorMessage()   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 0
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\Messaging\Manager;
12
13
use Miliooo\Messaging\User\ParticipantInterface;
14
use Miliooo\Messaging\Specifications\CanMessageRecipientInterface;
15
16
/**
17
 * This implementation uses the CanMessageRecipientSpecification to decide whether the current user can message a recipient
18
 *
19
 * @author Michiel Boeckaert <[email protected]>
20
 */
21
class CanMessageRecipientManager implements CanMessageRecipientManagerInterface
22
{
23
    /**
24
     * A can message recipient instance.
25
     *
26
     * @var CanMessageRecipientInterface
27
     */
28
    protected $specification;
29
30
    /**
31
     * Constructor.
32
     *
33
     * @param CanMessageRecipientInterface $specification
34
     */
35
    public function __construct(CanMessageRecipientInterface $specification)
36
    {
37
        $this->specification = $specification;
38
    }
39
40
    /**
41
     * Decides whether the logged in user can send a message to the recipient.
42
     *
43
     * @param ParticipantInterface $loggedInUser The logged in user
44
     * @param ParticipantInterface $recipient    The recipient we check
45
     *
46
     * @return boolean true if the loggedInUser can send a message to the recipient, false otherwise.
47
     */
48
    public function canMessageRecipient(ParticipantInterface $loggedInUser, ParticipantInterface $recipient)
49
    {
50
        return $this->specification->isSatisfiedBy($loggedInUser, $recipient);
51
    }
52
53
    /**
54
     * Check CanMessageRecipientInterface in the specifications for more information.
55
     *
56
     * @return null|string
57
     */
58
    public function getErrorMessage()
59
    {
60
        return $this->specification->getErrorMessage();
61
    }
62
}
63