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

mlocati / nexi / 8551769251

04 Apr 2024 08:40AM UTC coverage: 2.179% (+2.2%) from 0.0%
8551769251

push

github

mlocati
Improve JSON generation, add ways to enable insecure HTTPS connections

14 of 153 new or added lines in 7 files covered. (9.15%)

2 existing lines in 2 files now uncovered.

37 of 1698 relevant lines covered (2.18%)

0.02 hits per line

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

0.0
/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
     * @var bool
25
     */
26
    private $unsafeHttps;
27

28
    /**
29
     * @param array $data {
30
     *                    environment?: string, // 'test' for test environment, empty/missing for production
31
     *                    baseUrl?: string, // if missing or empty: we'll use the default base URL for test or production
32
     *                    apiKey?: string, // if missing or empty: for test we'll use the default API key, for production it's required
33
     *                    unsafeHttps?: bool, // allow using self-signed/expired/wrong HTTPS certificates: USE WITH CARE!
34
     *                    }
35
     *
36
     * @throws \RuntimeException in case of missing/wrong parameters
37
     */
38
    public function __construct(array $data)
39
    {
NEW
40
        $test = ($data['environment'] ?? '') === 'test';
×
NEW
41
        $this->baseUrl = (string) ($data['baseUrl'] ?? '');
×
NEW
42
        if ($this->baseUrl === '') {
×
NEW
43
            $this->baseUrl = $test ? static::DEFAULT_BASEURL_TEST : static::DEFAULT_BASEURL_PRODUCTION;
×
NEW
44
            if ($this->baseUrl === '') {
×
NEW
45
                throw new RuntimeException('Missing baseUrl in configuration');
×
46
            }
47
        }
NEW
48
        if (!filter_var($this->baseUrl, FILTER_VALIDATE_URL)) {
×
NEW
49
            throw new RuntimeException('Wrong baseUrl in configuration');
×
50
        }
NEW
51
        $this->apiKey = (string) ($data['apiKey'] ?? '');
×
NEW
52
        if ($this->apiKey === '') {
×
NEW
53
            $this->apiKey = $test ? static::DEFAULT_APIKEY_TEST : '';
×
NEW
54
            if ($this->apiKey === '') {
×
NEW
55
                throw new RuntimeException('Missing apiKey in configuration');
×
56
            }
57
        }
NEW
58
        $this->unsafeHttps = ($data['unsafeHttps'] ?? false) === true;
×
NEW
59
    }
×
60

61
    /**
62
     * {@inheritdoc}
63
     *
64
     * @see \MLocati\Nexi\Configuration::getBaseUrl()
65
     */
66
    public function getBaseUrl(): string
67
    {
NEW
68
        return $this->baseUrl;
×
69
    }
70

71
    /**
72
     * {@inheritdoc}
73
     *
74
     * @see \MLocati\Nexi\Configuration::getApiKey()
75
     */
76
    public function getApiKey(): string
77
    {
NEW
78
        return $this->apiKey;
×
79
    }
80

81
    /**
82
     * {@inheritdoc}
83
     *
84
     * @see \MLocati\Nexi\Configuration::allowUnsafeHttps()
85
     */
86
    public function allowUnsafeHttps(): bool
87
    {
NEW
88
        return $this->unsafeHttps;
×
89
    }
90
}
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