Failed Conditions
Push — master ( 88a375...460296 )
by Florent
04:20
created

ContactsParametersRule   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 17
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Component\Server\Model\Client\Rule;
15
16
use Assert\Assertion;
17
use OAuth2Framework\Component\Server\Model\DataBag\DataBag;
18
use OAuth2Framework\Component\Server\Model\UserAccount\UserAccountId;
19
20
final class ContactsParametersRule implements RuleInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function handle(DataBag $commandParameters, DataBag $validatedParameters, ? UserAccountId $userAccountId, callable $next): DataBag
26
    {
27
        if ($commandParameters->has('contacts')) {
28
            $contacts = $commandParameters->get('contacts');
29
            Assertion::isArray($contacts, 'The parameter \'contacts\' must be a list of e-mail addresses.');
30
            Assertion::allEmail($contacts, 'The parameter \'contacts\' must be a list of e-mail addresses.');
31
            $validatedParameters = $validatedParameters->with('contacts', $contacts);
32
        }
33
34
        return $next($commandParameters, $validatedParameters, $userAccountId);
35
    }
36
}
37