Completed
Push — feature/168109427-remove-u2f-s... ( 0a8d64 )
by
unknown
02:09
created

RegistrationEmailProcessor   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 9
dl 0
loc 124
rs 10
c 0
b 0
f 0

9 Methods

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