Completed
Push — master ( 5467e4...183ea4 )
by Boy
05:06 queued 01:02
created

SecondFactorRevocationProjector   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 65 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 10
dl 26
loc 40
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A applyVettedSecondFactorRevokedEvent() 13 13 1
A applyCompliedWithVettedSecondFactorRevocationEvent() 13 13 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
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Projector;
20
21
use Broadway\Domain\DomainMessage;
22
use Broadway\ReadModel\Projector;
23
use DateTime as CoreDateTime;
24
use Rhumsaa\Uuid\Uuid;
25
use Surfnet\Stepup\DateTime\DateTime;
26
use Surfnet\Stepup\Identity\Event\CompliedWithVettedSecondFactorRevocationEvent;
27
use Surfnet\Stepup\Identity\Event\VettedSecondFactorRevokedEvent;
28
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\SecondFactorRevocation;
29
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\SecondFactorRevocationRepository;
30
31
class SecondFactorRevocationProjector extends Projector
32
{
33
    /**
34
     * @var \Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\SecondFactorRevocationRepository
35
     */
36
    private $repository;
37
38
    public function __construct(SecondFactorRevocationRepository $repository)
39
    {
40
        $this->repository = $repository;
41
    }
42
43 View Code Duplication
    protected function applyVettedSecondFactorRevokedEvent(
0 ignored issues
show
Duplication introduced by
This method 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...
44
        VettedSecondFactorRevokedEvent $event,
45
        DomainMessage $domainMessage
46
    ) {
47
        $revocation = new SecondFactorRevocation();
48
        $revocation->id = (string) Uuid::uuid4();
49
        $revocation->institution = $event->identityInstitution;
50
        $revocation->secondFactorType = $event->secondFactorType->getSecondFactorType();
51
        $revocation->revokedBy = 'self';
52
        $revocation->recordedOn = new DateTime(new CoreDateTime($domainMessage->getRecordedOn()->toString()));
53
54
        $this->repository->save($revocation);
55
    }
56
57 View Code Duplication
    protected function applyCompliedWithVettedSecondFactorRevocationEvent(
0 ignored issues
show
Duplication introduced by
This method 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...
58
        CompliedWithVettedSecondFactorRevocationEvent $event,
59
        DomainMessage $domainMessage
60
    ) {
61
        $revocation = new SecondFactorRevocation();
62
        $revocation->id = (string) Uuid::uuid4();
63
        $revocation->institution = $event->identityInstitution;
64
        $revocation->secondFactorType = $event->secondFactorType->getSecondFactorType();
65
        $revocation->revokedBy = 'ra';
66
        $revocation->recordedOn = new DateTime(new CoreDateTime($domainMessage->getRecordedOn()->toString()));
67
68
        $this->repository->save($revocation);
69
    }
70
}
71