RequestResolver   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 40
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A resolveResource() 0 8 1
A hasResourceOptions() 0 10 2
A getResourceOptions() 0 6 1
A setResource() 0 4 1
1
<?php
2
3
namespace Knp\RadBundle\Resource\Resolver;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Knp\RadBundle\HttpFoundation\RequestManipulator;
7
8
class RequestResolver
9
{
10
    public function __construct(ResourceResolver $resourceResolver, RequestManipulator $requestManipulator = null)
11
    {
12
        $this->resourceResolver = $resourceResolver;
0 ignored issues
show
Bug introduced by
The property resourceResolver does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
13
        $this->requestManipulator = $requestManipulator ?: new RequestManipulator();
0 ignored issues
show
Bug introduced by
The property requestManipulator does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
14
    }
15
16
    public function resolveResource(Request $request, $name)
17
    {
18
        $options = $this->getResourceOptions($request, $name);
19
        $resource = $this->resourceResolver->resolveResource($request, $options);
20
        $this->setResource($request, $name, $resource);
21
22
        return $resource;
23
    }
24
25
    public function hasResourceOptions(Request $request, $name)
26
    {
27
        if (false === $this->requestManipulator->hasAttribute($request, '_resources')) {
28
            return false;
29
        }
30
31
        $resources = $this->requestManipulator->getAttribute($request, '_resources');
32
33
        return array_key_exists($name, $resources);
34
    }
35
36
    public function getResourceOptions(Request $request, $name)
37
    {
38
        $resources = $this->requestManipulator->getAttribute($request, '_resources');
39
40
        return $resources[$name];
41
    }
42
43
    public function setResource(Request $request, $name, $resource)
44
    {
45
        $this->requestManipulator->setAttribute($request, $name, $resource);
46
    }
47
}
48