Completed
Push — master ( 8af693...a60473 )
by Enrico
03:36
created

GetResourceController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Resourceful\Controller;
4
5
use Silex\Application;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
8
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
9
10
class GetResourceController extends AbstractResourceController
11
{
12 3
    public function __invoke(Application $app, Request $request)
13
    {
14 3
		$store = $this->getStore($app);
15
		
16 3
        if (!$store->contains($request->getRequestUri())) {
17 1
            throw new NotFoundHttpException("Not Found");
18
        }
19
20 2
        $resource = $store->fetch($request->getRequestUri());
21 2
        if ($resource === false) {
22 1
            throw new ServiceUnavailableHttpException(null, "Failed to retrieve resource");
23
        }
24
		
25 1
        return $app->json($resource);
26
    }
27
}
28