Transifex   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 0 Features 1
Metric Value
eloc 10
c 7
b 0
f 1
dl 0
loc 69
ccs 12
cts 12
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getOption() 0 3 1
A get() 0 3 1
A __construct() 0 8 2
A setOption() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace BabDev\Transifex;
4
5
/**
6
 * Base class for interacting with the Transifex API.
7
 */
8
final class Transifex implements TransifexInterface
9
{
10
    /**
11
     * The API factory.
12
     *
13
     * @var FactoryInterface
14
     */
15
    private $apiFactory;
16
17
    /**
18
     * Options for the API client.
19
     *
20
     * @var array
21
     */
22
    private $options;
23
24
    /**
25
     * @param FactoryInterface $apiFactory The API factory
26
     * @param array            $options    Transifex options array
27
     */
28 2
    public function __construct(FactoryInterface $apiFactory, array $options = [])
29
    {
30 2
        $this->apiFactory = $apiFactory;
31 2
        $this->options    = $options;
32
33
        // Setup the default API url if not already set.
34 2
        if (!$this->getOption('base_uri')) {
35 2
            $this->setOption('base_uri', 'https://www.transifex.com');
36
        }
37 2
    }
38
39
    /**
40
     * Factory method to fetch API objects.
41
     *
42
     * @param string $name Name of the API object to retrieve
43
     *
44
     * @return ApiConnector
45
     *
46
     * @throws Exception\UnknownApiConnectorException
47
     */
48 1
    public function get(string $name): ApiConnector
49
    {
50 1
        return $this->apiFactory->createApiConnector($name, $this->options);
51
    }
52
53
    /**
54
     * Get an option from the API client.
55
     *
56
     * @param string $key     The name of the option to get
57
     * @param mixed  $default The default value if the option is not set
58
     *
59
     * @return mixed The option value
60
     */
61 2
    public function getOption(string $key, $default = null)
62
    {
63 2
        return $this->options[$key] ?? $default;
64
    }
65
66
    /**
67
     * Set an option for the API client.
68
     *
69
     * @param string $key   The name of the option to set
70
     * @param mixed  $value The option value to set
71
     *
72
     * @return void
73
     */
74 2
    public function setOption(string $key, $value): void
75
    {
76 2
        $this->options[$key] = $value;
77 2
    }
78
}
79