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