DeleteThreadManagerSpecificationAware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A deleteThread() 0 8 2
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\Model\ThreadInterface;
14
use Miliooo\Messaging\Specifications\CanDeleteThreadSpecification;
15
use Miliooo\Messaging\User\ParticipantInterface;
16
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
17
18
/**
19
 * A delete thread manager which uses the can delete thread specification to decide whether to allow the deletion of
20
 * a thread.
21
 *
22
 * @author Michiel Boeckaert <[email protected]>
23
 */
24
class DeleteThreadManagerSpecificationAware implements DeleteThreadManagerSecureInterface
25
{
26
    /**
27
     * A delete thread manager instance.
28
     *
29
     * @var DeleteThreadManagerInterface
30
     */
31
    protected $deleteThreadManager;
32
33
    /**
34
     * A can delete thread specification instance.
35
     *
36
     * @var CanDeleteThreadSpecification
37
     */
38
    protected $canDeleteThread;
39
40
    /**
41
     * Constructor.
42
     *
43
     * @param DeleteThreadManagerInterface $deleteThreadManager
44
     * @param CanDeleteThreadSpecification $canDeleteThread
45
     */
46
    public function __construct(
47
        DeleteThreadManagerInterface $deleteThreadManager,
48
        CanDeleteThreadSpecification $canDeleteThread
49
    ) {
50
        $this->deleteThreadManager = $deleteThreadManager;
51
        $this->canDeleteThread = $canDeleteThread;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function deleteThread(ParticipantInterface $participant, ThreadInterface $thread)
58
    {
59
        if (!$this->canDeleteThread->isSatisfiedBy($participant, $thread)) {
60
            throw new AccessDeniedException('not authorised to delete this thread');
61
        }
62
63
        $this->deleteThreadManager->deleteThread($thread);
64
    }
65
}
66