Completed
Push — master ( aab356...2cdc9d )
by
unknown
14:39 queued 08:27
created

handleYubikeyPossessionProvenAndVerifiedEvent()   A

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 1
1
<?php
2
3
/**
4
 * Copyright 2016 SURFnet B.V.
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\CommandHandlingBundle\Processor;
20
21
use Broadway\Processor\Processor;
22
use DateInterval;
23
use Surfnet\Stepup\Configuration\Value\Institution;
24
use Surfnet\Stepup\DateTime\DateTime;
25
use Surfnet\Stepup\Identity\Event\EmailVerifiedEvent;
26
use Surfnet\Stepup\Identity\Event\GssfPossessionProvenAndVerifiedEvent;
27
use Surfnet\Stepup\Identity\Event\PhonePossessionProvenAndVerifiedEvent;
28
use Surfnet\Stepup\Identity\Event\PossessionProvenAndVerified;
29
use Surfnet\Stepup\Identity\Event\U2fDevicePossessionProvenAndVerifiedEvent;
30
use Surfnet\Stepup\Identity\Event\YubikeyPossessionProvenAndVerifiedEvent;
31
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Service\InstitutionConfigurationOptionsService;
32
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Service\RaLocationService;
33
use Surfnet\StepupMiddleware\ApiBundle\Identity\Service\RaListingService;
34
use Surfnet\StepupMiddleware\ApiBundle\Identity\Value\RegistrationAuthorityCredentials;
35
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Service\RegistrationMailService;
36
37
/**
38
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
39
 */
40
final class RegistrationEmailProcessor extends Processor
41
{
42
    /**
43
     * @var RaLocationService
44
     */
45
    private $raLocationsService;
46
47
    /**
48
     * @var RegistrationMailService
49
     */
50
    private $registrationMailService;
51
52
    /**
53
     * @var InstitutionConfigurationOptionsService
54
     */
55
    private $institutionConfigurationOptionsService;
56
57
    /**
58
     * @var RaListingService
59
     */
60
    private $raListingService;
61
62
    public function __construct(
63
        RegistrationMailService $registrationMailService,
64
        RaListingService $raListingService,
65
        InstitutionConfigurationOptionsService $institutionConfigurationOptionsService,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $institutionConfigurationOptionsService exceeds the maximum configured length of 30.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
66
        RaLocationService $raLocationsService
67
    ) {
68
        $this->registrationMailService                = $registrationMailService;
69
        $this->raListingService                       = $raListingService;
70
        $this->institutionConfigurationOptionsService = $institutionConfigurationOptionsService;
71
        $this->raLocationsService                     = $raLocationsService;
72
    }
73
74
    public function handlePhonePossessionProvenAndVerifiedEvent(PhonePossessionProvenAndVerifiedEvent $event)
75
    {
76
        $this->handlePossessionProvenAndVerifiedEvent($event);
77
    }
78
79
    public function handleYubikeyPossessionProvenAndVerifiedEvent(YubikeyPossessionProvenAndVerifiedEvent $event)
80
    {
81
        $this->handlePossessionProvenAndVerifiedEvent($event);
82
    }
83
84
    public function handleU2fDevicePossessionProvenAndVerifiedEvent(U2fDevicePossessionProvenAndVerifiedEvent $event)
85
    {
86
        $this->handlePossessionProvenAndVerifiedEvent($event);
87
    }
88
89
    public function handleGssfPossessionProvenAndVerifiedEvent(GssfPossessionProvenAndVerifiedEvent $event)
90
    {
91
        $this->handlePossessionProvenAndVerifiedEvent($event);
92
    }
93
94
    public function handleEmailVerifiedEvent(EmailVerifiedEvent $event)
95
    {
96
        $this->handlePossessionProvenAndVerifiedEvent($event);
97
    }
98
99
    private function handlePossessionProvenAndVerifiedEvent(PossessionProvenAndVerified $event)
100
    {
101
        $institution = new Institution($event->identityInstitution->getInstitution());
0 ignored issues
show
Bug introduced by
Accessing identityInstitution on the interface Surfnet\Stepup\Identity\...essionProvenAndVerified suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
102
        $institutionConfigurationOptions = $this->institutionConfigurationOptionsService
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $institutionConfigurationOptions exceeds the maximum configured length of 30.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
103
            ->findInstitutionConfigurationOptionsFor($institution);
104
105
        if ($institutionConfigurationOptions->useRaLocationsOption->isEnabled()) {
106
            $this->sendRegistrationEmailWithRaLocations($event, $institution);
107
108
            return;
109
        }
110
111
        $ras = $this->raListingService->listRegistrationAuthoritiesFor($event->identityInstitution);
0 ignored issues
show
Bug introduced by
Accessing identityInstitution on the interface Surfnet\Stepup\Identity\...essionProvenAndVerified suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
112
113
        if ($institutionConfigurationOptions->showRaaContactInformationOption->isEnabled()) {
114
            $this->sendRegistrationEmailWithRas($event, $ras);
115
116
            return;
117
        }
118
119
        $rasWithoutRaas = array_filter($ras, function (RegistrationAuthorityCredentials $ra) {
120
            return !$ra->isRaa();
121
        });
122
123
        $this->sendRegistrationEmailWithRas($event, $rasWithoutRaas);
124
    }
125
126
    /**
127
     * @param EmailVerifiedEvent $event
0 ignored issues
show
Documentation introduced by
Should the type for parameter $event not be PossessionProvenAndVerified?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
128
     * @param Institution $institution
129
     */
130
    private function sendRegistrationEmailWithRaLocations(PossessionProvenAndVerified $event, Institution $institution)
131
    {
132
        $this->registrationMailService->sendRegistrationEmailWithRaLocations(
133
            (string)$event->preferredLocale,
0 ignored issues
show
Bug introduced by
Accessing preferredLocale on the interface Surfnet\Stepup\Identity\...essionProvenAndVerified suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
134
            (string)$event->commonName,
0 ignored issues
show
Bug introduced by
Accessing commonName on the interface Surfnet\Stepup\Identity\...essionProvenAndVerified suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
135
            (string)$event->email,
0 ignored issues
show
Bug introduced by
Accessing email on the interface Surfnet\Stepup\Identity\...essionProvenAndVerified suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
136
            $event->registrationCode,
0 ignored issues
show
Bug introduced by
Accessing registrationCode on the interface Surfnet\Stepup\Identity\...essionProvenAndVerified suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
137
            $this->getExpirationDateOfRegistration($event),
138
            $this->raLocationsService->listRaLocationsFor($institution)
139
        );
140
    }
141
142
    /**
143
     * @param PossessionProvenAndVerified $event
144
     * @param RegistrationAuthorityCredentials[] $ras
145
     */
146
    private function sendRegistrationEmailWithRas(PossessionProvenAndVerified $event, array $ras)
147
    {
148
        $this->registrationMailService->sendRegistrationEmailWithRas(
149
            (string)$event->preferredLocale,
0 ignored issues
show
Bug introduced by
Accessing preferredLocale on the interface Surfnet\Stepup\Identity\...essionProvenAndVerified suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
150
            (string)$event->commonName,
0 ignored issues
show
Bug introduced by
Accessing commonName on the interface Surfnet\Stepup\Identity\...essionProvenAndVerified suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
151
            (string)$event->email,
0 ignored issues
show
Bug introduced by
Accessing email on the interface Surfnet\Stepup\Identity\...essionProvenAndVerified suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
152
            $event->registrationCode,
0 ignored issues
show
Bug introduced by
Accessing registrationCode on the interface Surfnet\Stepup\Identity\...essionProvenAndVerified suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
153
            $this->getExpirationDateOfRegistration($event),
154
            $ras
155
        );
156
    }
157
158
    /**
159
     * @param EmailVerifiedEvent $event
0 ignored issues
show
Documentation introduced by
Should the type for parameter $event not be PossessionProvenAndVerified?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
160
     * @return DateTime
161
     */
162
    private function getExpirationDateOfRegistration(PossessionProvenAndVerified $event)
163
    {
164
        return $event->registrationRequestedAt->add(
0 ignored issues
show
Bug introduced by
Accessing registrationRequestedAt on the interface Surfnet\Stepup\Identity\...essionProvenAndVerified suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
165
            new DateInterval('P14D')
166
        )->endOfDay();
167
    }
168
}
169