Passed
Push — master ( d0defb...6219a1 )
by
unknown
07:54
created

ApiKeysTestCreator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 1
b 0
f 0
dl 0
loc 30
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A create() 0 12 4
A testApiKey() 0 5 1
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * You can find more information about us on https://bitbag.io and write us
7
 * an email on [email protected].
8
 */
9
10
declare(strict_types=1);
11
12
namespace BitBag\SyliusMolliePlugin\Creator;
13
14
use BitBag\SyliusMolliePlugin\Client\MollieApiClient;
15
use BitBag\SyliusMolliePlugin\DTO\ApiKeyTest;
16
use Mollie\Api\Resources\MethodCollection;
17
18
final class ApiKeysTestCreator implements ApiKeysTestCreatorInterface
19
{
20
    /** @var MollieApiClient */
21
    private $mollieApiClient;
22
23
    public function __construct(MollieApiClient $mollieApiClient)
24
    {
25
        $this->mollieApiClient = $mollieApiClient;
26
    }
27
28
    public function create(string $keyType, string $key = null): ApiKeyTest
29
    {
30
        if (null !== $key && !empty(trim($key))) {
31
            return new ApiKeyTest(
32
                $keyType,
33
                $key ? true : false,
34
                $this->testApiKey($key)
35
            );
36
        }
37
38
        return new ApiKeyTest(
39
            $keyType,
40
        );
41
    }
42
43
    private function testApiKey(string $apiKey): MethodCollection
44
    {
45
        $client = $this->mollieApiClient->setApiKey($apiKey);
46
47
        return $client->methods->allActive(MollieMethodsCreatorInterface::PARAMETERS);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $client->methods-...rInterface::PARAMETERS) returns the type Mollie\Api\Resources\BaseCollection which includes types incompatible with the type-hinted return Mollie\Api\Resources\MethodCollection.
Loading history...
48
    }
49
}
50