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