Completed
Push — master ( dbe8ee...cfcdbf )
by Michael
02:09
created

Organizations::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 12
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 5
crap 3
1
<?php declare(strict_types=1);
2
3
namespace BabDev\Transifex;
4
5
use Psr\Http\Client\ClientInterface;
6
use Psr\Http\Message\RequestFactoryInterface;
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\StreamFactoryInterface;
9
use Psr\Http\Message\UriFactoryInterface;
10
11
/**
12
 * Transifex API Organizations class.
13
 *
14
 * @link https://docs.transifex.com/api/organizations
15
 */
16
class Organizations extends TransifexObject
17
{
18
    /**
19
     * @param ClientInterface         $client         The HTTP client
20
     * @param RequestFactoryInterface $requestFactory The request factory
21
     * @param StreamFactoryInterface  $streamFactory  The stream factory
22
     * @param UriFactoryInterface     $uriFactory     The URI factory
23
     * @param array                   $options        Transifex options array
24
     */
25 2
    public function __construct(
26
        ClientInterface $client,
27
        RequestFactoryInterface $requestFactory,
28
        StreamFactoryInterface $streamFactory,
29
        UriFactoryInterface $uriFactory,
30
        array $options = []
31
    ) {
32 2
        parent::__construct($client, $requestFactory, $streamFactory, $uriFactory, $options);
33
34
        // This API group uses the newer `api.transifex.com` subdomain, only change if the default www was given
35 2
        if (!$this->getOption('base_uri') || $this->getOption('base_uri') === 'https://www.transifex.com') {
36 2
            $this->setOption('base_uri', 'https://api.transifex.com');
37
        }
38 2
    }
39
40
    /**
41
     * Get the organizations the authenticated user belongs to.
42
     *
43
     * @return ResponseInterface
44
     */
45 2
    public function getOrganizations(): ResponseInterface
46
    {
47 2
        return $this->client->sendRequest($this->createRequest('GET', $this->createUri('/organizations/')));
48
    }
49
}
50