Passed
Pull Request — master (#3)
by Sergey
02:10
created

UsesConnectionTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 14
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConnection() 0 10 3
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