| Total Complexity | 8 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Coverage | 89.47% |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class AdapterFactory |
||
| 13 | { |
||
| 14 | protected $adapters = []; |
||
| 15 | |||
| 16 | 85 | public function __construct() |
|
| 17 | { |
||
| 18 | 85 | $this->register('guzzle5', Guzzle5Adapter::class) |
|
| 19 | 85 | ->register('guzzle6', Guzzle6Adapter::class); |
|
| 20 | 85 | } |
|
| 21 | |||
| 22 | /** |
||
| 23 | * @param string $name |
||
| 24 | * @param string $adapterClass |
||
| 25 | * @return $this |
||
| 26 | */ |
||
| 27 | 85 | public function register($name, $adapterClass) |
|
| 28 | { |
||
| 29 | 85 | $this->adapters[$name] = $adapterClass; |
|
| 30 | |||
| 31 | 85 | return $this; |
|
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @internal |
||
| 36 | * @param string $name |
||
| 37 | * @return string |
||
| 38 | */ |
||
| 39 | 85 | public function getClass($name = null) |
|
| 40 | { |
||
| 41 | 85 | if (is_null($name)) { |
|
| 42 | 81 | $name = "guzzle6"; |
|
| 43 | 81 | if (defined('\GuzzleHttp\Client::VERSION') && version_compare(constant('\GuzzleHttp\Client::VERSION'), '6.0.0', '<')) { |
|
| 44 | $name = 'guzzle5'; |
||
| 45 | } |
||
| 46 | } |
||
| 47 | 85 | if (isset($this->adapters[$name])) { |
|
| 48 | 85 | return $this->adapters[$name]; |
|
| 49 | } |
||
| 50 | |||
| 51 | throw new InvalidArgumentException(); |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param $name |
||
| 56 | * @param $options |
||
| 57 | * @return AdapterInterface |
||
| 58 | */ |
||
| 59 | 81 | public function getAdapter($name, $options) |
|
| 65 | } |
||
| 66 | } |
||
| 67 |