Test Failed
Push — master ( 4a2444...e6139c )
by P.R.
02:32
created

CompanyEndpoint::createResourceObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace SetBased\ClubCollect\Endpoint;
5
6
use SetBased\ClubCollect\Exception\ClubCollectApiException;
7
use SetBased\ClubCollect\Resource\BaseResource;
8
use SetBased\ClubCollect\Resource\Company;
9
10
/**
11
 * Endpoint for companies.
12
 */
13
class CompanyEndpoint extends Endpoint
14
{
15
  //--------------------------------------------------------------------------------------------------------------------
16
  /**
17
   * Fetches the company from ClubCollect.
18
   *
19
   * @return Company
20
   *
21
   * @throws ClubCollectApiException
22
   */
23
  public function fetch(): Company
24
  {
25
    /** @var Company $resource */
26
    $resource = parent::restGet(['companies', $this->client->getCompanyId()],
27
                                ['api_key' => $this->client->getApiKey()]);
28
    if (!is_a($resource, Company::class))
29
    {
30
      throw new ClubCollectApiException('Expected a Company object, got a %s', get_class($resource));
31
    }
32
33
    return $resource;
34
  }
35
36
  //--------------------------------------------------------------------------------------------------------------------
37
  /**
38
   * Returns an instance of this class.
39
   *
40
   * @param array $response The API response.
41
   *
42
   * @return Company
43
   *
44
   * @throws ClubCollectApiException
45
   */
46
  protected function createResourceObject(array $response): BaseResource
47
  {
48
    return new Company($this->client, $response);
49
  }
50
51
  //--------------------------------------------------------------------------------------------------------------------
52
}
53
54
//----------------------------------------------------------------------------------------------------------------------
55