| Total Complexity | 6 |
| Total Lines | 74 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | abstract class OsnovaResource |
||
| 9 | { |
||
| 10 | /** @var ApiProvider */ |
||
| 11 | protected $apiProvider; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * OsnovaResource constructor. |
||
| 15 | * |
||
| 16 | * @param ApiProvider $apiProvider |
||
| 17 | */ |
||
| 18 | public function __construct(ApiProvider $apiProvider) |
||
| 19 | { |
||
| 20 | $this->apiProvider = $apiProvider; |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Get the resource domain. |
||
| 25 | * |
||
| 26 | * @return string |
||
| 27 | */ |
||
| 28 | abstract public static function domain(); |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Get the original API Provider instance. |
||
| 32 | * |
||
| 33 | * @return ApiProvider |
||
| 34 | */ |
||
| 35 | public function getApiProvider() |
||
| 36 | { |
||
| 37 | return $this->apiProvider; |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Generate URL for the current resource. |
||
| 42 | * |
||
| 43 | * @param string $path = '' URL path. |
||
| 44 | * |
||
| 45 | * @return string |
||
| 46 | */ |
||
| 47 | public function generateUrl(string $path = '') |
||
| 48 | { |
||
| 49 | return 'https://'.static::domain().($path ? '/'.ltrim($path, '/') : ''); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Make new resource instance. |
||
| 54 | * |
||
| 55 | * @param string $version |
||
| 56 | * |
||
| 57 | * @return static |
||
| 58 | */ |
||
| 59 | public static function make(string $version) |
||
| 64 | ) |
||
| 65 | ); |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Make new HTTP client instance. |
||
| 70 | * |
||
| 71 | * @param string $version |
||
| 72 | * |
||
| 73 | * @return Client |
||
| 74 | */ |
||
| 75 | protected static function makeClient(string $version) |
||
| 86 |