PaymentServiceValidator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 21
ccs 0
cts 6
cp 0
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 11 1
A __construct() 0 3 1
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/money-interop project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Money\Validator;
10
11
use Daikon\Interop\Assert;
12
use Daikon\Money\Service\PaymentServiceInterface;
13
use Daikon\Money\Service\PaymentServiceMap;
14
use Daikon\Validize\Validator\Validator;
15
16
final class PaymentServiceValidator extends Validator
17
{
18
    private PaymentServiceMap $paymentServiceMap;
19
20
    public function __construct(PaymentServiceMap $paymentServiceMap)
21
    {
22
        $this->paymentServiceMap = $paymentServiceMap;
23
    }
24
25
    /** @param mixed $input */
26
    protected function validate($input): PaymentServiceInterface
27
    {
28
        Assert::that($input)
29
            ->string('Must be a string.')
30
            ->notBlank('Must not be empty.')
31
            ->satisfy([$this->paymentServiceMap, 'has'], 'Unknown service.');
32
33
        /** @var PaymentServiceInterface $service  */
34
        $service = $this->paymentServiceMap->get($input);
35
36
        return $service;
37
    }
38
}
39