RefreshTokenRepositorySpec   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 33
loc 33
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 4 4 1
A it_is_initializable() 4 4 1
A it_is_a_repository() 4 4 1
A it_finds_invalid_tokens() 15 15 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace spec\Gesdinet\JWTRefreshTokenBundle\Entity;
4
5
use Doctrine\MongoDB\Query\Builder;
6
use Doctrine\MongoDB\Query\Query;
7
use Doctrine\ODM\MongoDB\DocumentManager;
8
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
9
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;
10
use PhpSpec\ObjectBehavior;
11
use Prophecy\Argument;
12
13 View Code Duplication
class RefreshTokenRepositorySpec extends ObjectBehavior
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    public function let(DocumentManager $dm, ClassMetadata $classMetadata)
16
    {
17
        $this->beConstructedWith($dm, $classMetadata);
18
    }
19
20
    public function it_is_initializable()
21
    {
22
        $this->shouldHaveType('Gesdinet\JWTRefreshTokenBundle\Document\RefreshTokenRepository');
23
    }
24
25
    public function it_is_a_repository()
26
    {
27
        $this->shouldHaveType('Doctrine\ODM\MongoDB\DocumentRepository');
28
    }
29
30
    public function it_finds_invalid_tokens($em, Builder $builder, Query $query, RefreshTokenInterface $token)
31
    {
32
        $date = new \DateTime();
33
        $em->createQueryBuilder()->shouldBeCalled()->willReturn($builder);
34
35
        $builder->select('u')->shouldBeCalled()->willReturn($builder);
36
        $builder->from(Argument::any(), 'u', Argument::cetera())->shouldBeCalled()->willReturn($builder);
37
        $builder->where('u.valid < :datetime')->shouldBeCalled()->willReturn($builder);
38
        $builder->setParameter(':datetime', $date)->shouldBeCalled()->willReturn($builder);
39
40
        $builder->getQuery()->shouldBeCalled()->willReturn($query);
41
        $query->getResult()->shouldBeCalled()->willReturn(array($token));
42
43
        $this->findInvalid($date)->shouldReturn(array($token));
44
    }
45
}
46