| Total Complexity | 6 |
| Total Lines | 66 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | class HttpClient |
||
| 14 | { |
||
| 15 | protected const METHOD_GET = 'GET'; |
||
| 16 | |||
| 17 | protected const METHOD_POST = 'POST'; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var ContainerInterface $config |
||
| 21 | */ |
||
| 22 | protected $config; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var GuzzleClient |
||
| 26 | */ |
||
| 27 | protected $client; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @param ContainerInterface $config |
||
| 31 | */ |
||
| 32 | public function __construct(ContainerInterface $config) |
||
| 33 | { |
||
| 34 | $this->config = $config; |
||
| 35 | $this->client = new GuzzleClient([ |
||
| 36 | 'base_uri' => $this->getBaseUri(), |
||
| 37 | $this->config->get('timeout'), |
||
| 38 | ]); |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Returns base API url |
||
| 43 | * |
||
| 44 | * @return string |
||
| 45 | */ |
||
| 46 | protected function getBaseUri(): string |
||
| 53 | ); |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Performs the request and returns the Response contents |
||
| 58 | * |
||
| 59 | * @param string $apiMethodName |
||
| 60 | * @param array $requestOptions |
||
| 61 | * |
||
| 62 | * @return null|string |
||
| 63 | */ |
||
| 64 | public function request(string $apiMethodName, array $requestOptions = []): ?string |
||
| 79 | } |
||
| 80 | } |
||
| 81 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: