PaymentServiceValidator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
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