Conditions | 3 |
Paths | 3 |
Total Lines | 22 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 6 |
CRAP Score | 3.1406 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
25 | public function createPlugin(array $config = []): Plugin |
||
26 | { |
||
27 | if (! class_exists(CachePlugin::class)) { |
||
28 | throw new \LogicException('To use the cache plugin you need to install the "php-http/cache-plugin" package.'); |
||
29 | 2 | } |
|
30 | |||
31 | 2 | $options = $config['options'] ?? []; |
|
32 | |||
33 | if ($options['cache_key_generator'] ?? null) { |
||
34 | $options['cache_key_generator'] = $this->container->get($options['cache_key_generator']); |
||
35 | 2 | } |
|
36 | |||
37 | 2 | /** @var CacheItemPoolInterface $cachePool */ |
|
38 | $cachePool = $this->container->get($config['cache_pool']); |
||
39 | |||
40 | /** @var StreamFactoryInterface $streamFactory */ |
||
41 | $streamFactory = $this->container->get($config['stream_factory'] ?? 'httplug.stream_factory'); |
||
42 | 2 | ||
43 | return new CachePlugin( |
||
44 | $cachePool, |
||
45 | 2 | $streamFactory, |
|
46 | $options |
||
47 | 2 | ); |
|
50 |