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

ContactsParametersRule::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 4
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