Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
JavascriptCdnProxyController
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 __invoke
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2namespace Apie\JavascriptCdn\Controllers;
3
4use Apie\Core\ValueObjects\Exceptions\InvalidStringForValueObjectException;
5use Apie\JavascriptCdn\JavascriptCdnProxy;
6use Apie\JavascriptCdn\ValueObjects\JavascriptCdnPath;
7use Nyholm\Psr7\Response;
8use Psr\Http\Message\ResponseInterface;
9use Psr\Http\Message\ServerRequestInterface;
10
11class JavascriptCdnProxyController
12{
13    public function __construct(private readonly JavascriptCdnProxy $proxy)
14    {
15    }
16
17    public function __invoke(ServerRequestInterface $request): ResponseInterface
18    {
19        try {
20            $path = new JavascriptCdnPath($request->getAttribute('path'));
21        } catch (InvalidStringForValueObjectException $e) {
22            return new Response(400, ['Content-Type' => 'text/plain'], 'Invalid npm package path.');
23        }
24
25        return $this->proxy->getResponse($path);
26    }
27}