ThreadProviderSpecificationAware   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A findThreadForParticipant() 0 13 3
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\ThreadProvider;
12
13
use Miliooo\Messaging\Specifications\CanSeeThreadSpecification;
14
use Miliooo\Messaging\User\ParticipantInterface;
15
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
16
17
/**
18
 * A thread provider which uses the can see thread specification to decide whether to allow access to a thread.
19
 *
20
 * @author Michiel Boeckaert <[email protected]>
21
 */
22
class ThreadProviderSpecificationAware implements SecureThreadProviderInterface
23
{
24
    protected $threadProvider;
25
    protected $canSeeThread;
26
27
    /**
28
     * Constructor.
29
     *
30
     * @param ThreadProviderInterface   $threadProvider A thread provider instance
31
     * @param CanSeeThreadSpecification $canSeeThread   A canseethreadspecification
32
     */
33
    public function __construct(ThreadProviderInterface $threadProvider, CanSeeThreadSpecification $canSeeThread)
34
    {
35
        $this->threadProvider = $threadProvider;
36
        $this->canSeeThread = $canSeeThread;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function findThreadForParticipant(ParticipantInterface $participant, $threadId)
43
    {
44
        $thread = $this->threadProvider->findThreadForParticipant($threadId, $participant);
45
        if (!$thread) {
46
            return null;
47
        }
48
49
        if (!$this->canSeeThread->isSatisfiedBy($participant, $thread)) {
50
            throw new AccessDeniedException('Not allowed to see this thread');
51
        }
52
53
        return $thread;
54
    }
55
}
56