• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlocati / nexi / 8571051831

05 Apr 2024 02:05PM UTC coverage: 5.917% (+0.8%) from 5.079%
8571051831

push

github

mlocati
Document some of the features

111 of 1876 relevant lines covered (5.92%)

0.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.75
/src/Configuration/FromArray.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace MLocati\Nexi\Configuration;
6

7
use MLocati\Nexi\Configuration;
8

9
use RuntimeException;
10

11
class FromArray implements Configuration
12
{
13
    /**
14
     * @var string
15
     */
16
    private $baseUrl;
17

18
    /**
19
     * @var string
20
     */
21
    private $apiKey;
22

23
    /**
24
     * @param array $data {
25
     *                    environment?: string, // 'test' for test environment, empty/missing for production
26
     *                    baseUrl?: string, // if missing or empty: we'll use the default base URL for test or production
27
     *                    apiKey?: string, // if missing or empty: for test we'll use the default API key, for production it's required
28
     *                    }
29
     *
30
     * @throws \RuntimeException in case of missing/wrong parameters
31
     */
32
    public function __construct(array $data)
33
    {
34
        $test = ($data['environment'] ?? '') === 'test';
9✔
35
        $this->baseUrl = (string) ($data['baseUrl'] ?? '');
9✔
36
        if ($this->baseUrl === '') {
9✔
37
            $this->baseUrl = $test ? static::DEFAULT_BASEURL_TEST : static::DEFAULT_BASEURL_PRODUCTION;
6✔
38
            if ($this->baseUrl === '') {
6✔
39
                throw new RuntimeException('Missing baseUrl in configuration');
×
40
            }
41
        }
42
        if (!filter_var($this->baseUrl, FILTER_VALIDATE_URL)) {
9✔
43
            throw new RuntimeException('Wrong baseUrl in configuration');
1✔
44
        }
45
        $this->apiKey = (string) ($data['apiKey'] ?? '');
8✔
46
        if ($this->apiKey === '') {
8✔
47
            $this->apiKey = $test ? static::DEFAULT_APIKEY_TEST : '';
2✔
48
            if ($this->apiKey === '') {
2✔
49
                throw new RuntimeException('Missing apiKey in configuration');
1✔
50
            }
51
        }
52
    }
7✔
53

54
    /**
55
     * {@inheritdoc}
56
     *
57
     * @see \MLocati\Nexi\Configuration::getBaseUrl()
58
     */
59
    public function getBaseUrl(): string
60
    {
61
        return $this->baseUrl;
7✔
62
    }
63

64
    /**
65
     * {@inheritdoc}
66
     *
67
     * @see \MLocati\Nexi\Configuration::getApiKey()
68
     */
69
    public function getApiKey(): string
70
    {
71
        return $this->apiKey;
7✔
72
    }
73
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc