ReadResourceController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 40
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getSchemaId() 0 4 1
A getDatastore() 0 5 2
A read() 0 14 3
1
<?php
2
3
namespace Resourceful;
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
use Doctrine\Common\Cache\Cache;
10
11
class ReadResourceController
12
{
13
	private $schemaId;
14
15 17
    public function __construct($schemaId)
16
    {
17 17
    	assert (!empty($schemaId));
18
		
19 17
    	$this->schemaId = $schemaId;
20 17
    }
21
22
23 16
	public function getSchemaId()
24
	{
25 16
		return $this->schemaId;
26
	}
27
28
	
29 15
	public function getDatastore($app)
30
	{
31 15
		$schemaId= $this->getSchemaId();
32 15
		return isset($app["$schemaId.store"])?$app["$schemaId.store"]:$app['data.store'];
33
	}
34
35
36 3
    public function read(Application $app, Request $request)
37
    {
38 3
    	$datastore = $this->getDatastore($app);
39 3
        if (!$datastore->contains($request->getRequestUri())) {
40 1
            throw new NotFoundHttpException("Not Found");
41
        }
42
43 2
        $resource = $datastore->fetch($request->getRequestUri());
44 2
        if ($resource === false) {
45 1
            throw new ServiceUnavailableHttpException(null, "Failed to retrieve resource");
46
        }
47
		
48 1
        return $app->json($resource);
49
    }
50
}
51