Completed
Push — feature/registraion-mail-witho... ( 08a1fe )
by
unknown
05:03
created

handleEmailVerifiedEvent()   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
final class RegistrationEmailProcessor extends Processor
38
{
39
    /**
40
     * @var RaLocationService
41
     */
42
    private $raLocationsService;
43
44
    /**
45
     * @var RegistrationMailService
46
     */
47
    private $registrationMailService;
48
49
    /**
50
     * @var InstitutionConfigurationOptionsService
51
     */
52
    private $institutionConfigurationOptionsService;
53
54
    /**
55
     * @var RaListingService
56
     */
57
    private $raListingService;
58
59
    public function __construct(
60
        RegistrationMailService $registrationMailService,
61
        RaListingService $raListingService,
62
        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...
63
        RaLocationService $raLocationsService
64
    ) {
65
        $this->registrationMailService                = $registrationMailService;
66
        $this->raListingService                       = $raListingService;
67
        $this->institutionConfigurationOptionsService = $institutionConfigurationOptionsService;
68
        $this->raLocationsService                     = $raLocationsService;
69
    }
70
71
    public function handlePhonePossessionProvenAndVerifiedEvent(PhonePossessionProvenAndVerifiedEvent $event)
72
    {
73
        $this->handlePossessionProvenAndVerifiedEvent($event);
74
    }
75
76
    public function handleYubikeyPossessionProvenAndVerifiedEvent(YubikeyPossessionProvenAndVerifiedEvent $event)
77
    {
78
        $this->handlePossessionProvenAndVerifiedEvent($event);
79
    }
80
81
    public function handleU2fDevicePossessionProvenAndVerifiedEvent(U2fDevicePossessionProvenAndVerifiedEvent $event)
82
    {
83
        $this->handlePossessionProvenAndVerifiedEvent($event);
84
    }
85
86
    public function handleGssfPossessionProvenAndVerifiedEvent(GssfPossessionProvenAndVerifiedEvent $event)
87
    {
88
        $this->handlePossessionProvenAndVerifiedEvent($event);
89
    }
90
91
    public function handleEmailVerifiedEvent(EmailVerifiedEvent $event)
92
    {
93
        $this->handlePossessionProvenAndVerifiedEvent($event);
94
    }
95
96
    private function handlePossessionProvenAndVerifiedEvent(PossessionProvenAndVerified $event)
97
    {
98
        $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...
99
        $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...
100
            ->findInstitutionConfigurationOptionsFor($institution);
101
102
        if ($institutionConfigurationOptions->useRaLocationsOption->isEnabled()) {
103
            $this->sendRegistrationEmailWithRaLocations($event, $institution);
104
105
            return;
106
        }
107
108
        $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...
109
110
        if ($institutionConfigurationOptions->showRaaContactInformationOption->isEnabled()) {
111
            $this->sendRegistrationEmailWithRas($event, $ras);
112
113
            return;
114
        }
115
116
        $rasWithoutRaas = array_filter($ras, function (RegistrationAuthorityCredentials $ra) {
117
            return !$ra->isRaa();
118
        });
119
120
        $this->sendRegistrationEmailWithRas($event, $rasWithoutRaas);
121
    }
122
123
    /**
124
     * @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...
125
     * @param Institution $institution
126
     */
127
    private function sendRegistrationEmailWithRaLocations(PossessionProvenAndVerified $event, Institution $institution)
128
    {
129
        $this->registrationMailService->sendRegistrationEmailWithRaLocations(
130
            (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...
131
            (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...
132
            (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...
133
            $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...
134
            $this->getExpirationDateOfRegistration($event),
135
            $this->raLocationsService->listRaLocationsFor($institution)
136
        );
137
    }
138
139
    /**
140
     * @param PossessionProvenAndVerified $event
141
     * @param RegistrationAuthorityCredentials[] $ras
142
     */
143
    private function sendRegistrationEmailWithRas(PossessionProvenAndVerified $event, array $ras)
144
    {
145
        $this->registrationMailService->sendRegistrationEmailWithRas(
146
            (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...
147
            (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...
148
            (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...
149
            $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...
150
            $this->getExpirationDateOfRegistration($event),
151
            $ras
152
        );
153
    }
154
155
    /**
156
     * @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...
157
     * @return DateTime
158
     */
159
    private function getExpirationDateOfRegistration(PossessionProvenAndVerified $event)
160
    {
161
        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...
162
            new DateInterval('P14D')
163
        )->endOfDay();
164
    }
165
}
166