| Conditions | 4 |
| Paths | 4 |
| Total Lines | 26 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | public function __invoke(ContainerInterface $container): HtmlMinifierMiddleware |
||
| 13 | { |
||
| 14 | $config = []; |
||
| 15 | if ($container->has('config')) { |
||
| 16 | $config = $container->get('config'); |
||
| 17 | assert(is_array($config)); |
||
| 18 | $config = $config[HtmlMinifierMiddleware::class] ?? []; |
||
| 19 | } |
||
| 20 | |||
| 21 | if (1 !== (is_countable($config) ? count($config) : 0)) { |
||
| 22 | $format = 'The config key for "%s" must be an array with one element'; |
||
| 23 | $message = sprintf($format, HtmlMinifierMiddleware::class); |
||
| 24 | throw new Exception($message); |
||
| 25 | } |
||
| 26 | |||
| 27 | $className = array_key_first($config); |
||
| 28 | assert(is_string($className)); |
||
| 29 | |||
| 30 | $adapter = $container->get($className); |
||
| 31 | assert($adapter instanceof AdapterInterface); |
||
| 32 | |||
| 33 | $middleware = new HtmlMinifierMiddleware(); |
||
| 34 | |||
| 35 | $middleware->setAdapter($adapter); |
||
| 36 | |||
| 37 | return $middleware; |
||
| 38 | } |
||
| 40 |