PingMethod::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 10
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Usox\HyperSonic\FeatureSet\V1161\Method;
6
7
use Usox\HyperSonic\Exception\ErrorCodeEnum;
8
use Usox\HyperSonic\Exception\MethodCallFailedException;
9
use Usox\HyperSonic\Exception\SubSonicApiException;
10
use Usox\HyperSonic\FeatureSet\V1161\Contract\PingDataProviderInterface;
11
use Usox\HyperSonic\FeatureSet\V1161\Responder\ResponderFactoryInterface;
12
use Usox\HyperSonic\Response\ResponderInterface;
13
14
/**
15
 * Retrieves and transforms data related to the servers state
16
 *
17
 * This class covers the `ping.view` method
18
 */
19
final class PingMethod implements V1161MethodInterface
20
{
21 3
    public function __construct(
22
        private readonly ResponderFactoryInterface $responderFactory,
23
    ) {
24 3
    }
25
26
    /**
27
     * @param array<string, scalar> $queryParams
28
     * @param array<string, scalar> $args
29
     *
30
     * @throws SubSonicApiException
31
     */
32 2
    public function __invoke(
33
        PingDataProviderInterface $dataProvider,
34
        array $queryParams,
35
        array $args
36
    ): ResponderInterface {
37 2
        if (!$dataProvider->isOk()) {
38 1
            throw new MethodCallFailedException(ErrorCodeEnum::GENERIC_ERROR);
39
        }
40
41 1
        return $this->responderFactory->createPingResponder();
42
    }
43
}
44