Failed Conditions
Pull Request — master (#3)
by Sergey
02:12
created

UsesConnectionTrait::getConnection()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SergeyNezbritskiy\NovaPoshta\Tests;
6
7
use GuzzleHttp\Client;
8
use RuntimeException;
9
use SergeyNezbritskiy\NovaPoshta\Connection;
10
11
trait UsesConnectionTrait
12
{
13
    private Connection $client;
14
15
    public function getConnection(): Connection
16
    {
17
        if (empty($this->client)) {
18
            $apiKey = getenv('API_KEY');
19
            if (empty($apiKey)) {
20
                throw new RuntimeException('API_KEY not provided. Please pass it through phpunit.xml or env variables');
21
            }
22
            $this->client = new Connection($apiKey, new Client());
23
        }
24
        return $this->client;
25
    }
26
}
27