OptionsBasedSpec   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 86
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 5 1
A it_should_resolve_resource() 0 19 1
A it_should_throw_resolution_failure_when_resolved_resource_is_null() 0 13 1
A it_should_throw_exception_when_resouce_has_extra_options() 0 12 1
A it_should_throw_exception_when_resource_is_missing_service_option() 0 10 1
A it_should_throw_exception_when_resource_is_missing_method_option() 0 9 1
1
<?php
2
3
namespace spec\Knp\RadBundle\Resource\Resolver;
4
5
use PhpSpec\ObjectBehavior;
6
7
class OptionsBasedSpec extends ObjectBehavior
8
{
9
    /**
10
     * @param Symfony\Component\DependencyInjection\ContainerInterface $container
11
     * @param Knp\RadBundle\Resource\Resolver\OptionsBased\ArgumentResolver $argumentResolver
12
     * @param Symfony\Component\HttpFoundation\Request $request
0 ignored issues
show
Bug introduced by
There is no parameter named $request. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
13
     * @param spec\Knp\RadBundle\Resource\Resolver\CheeseRepository $cheeseRepository
14
     * @param stdClass $cheese
0 ignored issues
show
Documentation introduced by
There is no parameter named $cheese. Did you maybe mean $cheeseRepository?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
15
     */
16
    function let($container, $argumentResolver, $cheeseRepository)
17
    {
18
        $this->beConstructedWith($container, $argumentResolver);
19
        $container->get('orm.cheese_repository')->willReturn($cheeseRepository);
20
    }
21
22
    /**
23
     * @param stdClass $cheese
24
     */
25
    function it_should_resolve_resource($request, $argumentResolver, $container, $cheese, $cheeseRepository)
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Method name "OptionsBasedSpec::it_should_resolve_resource" is not in camel caps format
Loading history...
26
    {
27
        $argumentResolver->resolveArgument($request, array('value' => 'normandie'))->willReturn('normandie');
28
        $argumentResolver->resolveArgument($request, array('name' => 'slug'))->willReturn('neufchatel');
29
30
        $cheeseRepository->findByRegionAndSlug('normandie', 'neufchatel')->shouldBeCalled()->willReturn($cheese);
31
32
        $this
33
            ->resolveResource($request, array(
34
                'service'   => 'orm.cheese_repository',
35
                'method'    => 'findByRegionAndSlug',
36
                'arguments' => array(
37
                    array('value' => 'normandie'),
38
                    array('name' => 'slug'),
39
                )
40
            ))
41
            ->shouldReturn($cheese)
42
        ;
43
    }
44
45
    function it_should_throw_resolution_failure_when_resolved_resource_is_null($request, $argumentResolver, $cheeseRepository)
0 ignored issues
show
Coding Style introduced by
Method name "OptionsBasedSpec::it_should_throw_resolution_failure_when_resolved_resource_is_null" is not in camel caps format
Loading history...
46
    {
47
        $argumentResolver->resolveArgument($request, array('name' => 'slug'))->willReturn('neufchatel');
48
        $cheeseRepository->findBySlug('neufchatel')->willReturn(null);
49
50
        $this->shouldThrow()->duringResolveResource($request, array(
51
            'service'   => 'orm.cheese_repository',
52
            'method'    => 'findBySlug',
53
            'arguments' => array(
54
                array('name' => 'slug')
55
            )
56
        ));
57
    }
58
59
    function it_should_throw_exception_when_resouce_has_extra_options($request)
0 ignored issues
show
Coding Style introduced by
Method name "OptionsBasedSpec::it_should_throw_exception_when_resouce_has_extra_options" is not in camel caps format
Loading history...
60
    {
61
        $this->shouldThrow()->duringResolveResource($request, array(
62
                'extra'     => 'the extra value',
63
                'service'   => 'orm.cheese_repository',
64
                'method'    => 'findByRegionAndSlug',
65
                'arguments' => array(
66
                    array('value' => 'normandie'),
67
                    array('name' => 'slug'),
68
                ),
69
        ));
70
    }
71
72
    function it_should_throw_exception_when_resource_is_missing_service_option($request)
0 ignored issues
show
Coding Style introduced by
Method name "OptionsBasedSpec::it_should_throw_exception_when_resource_is_missing_service_option" is not in camel caps format
Loading history...
73
    {
74
        $this->shouldThrow()->duringResolveResource($request, array(
75
                'method'    => 'findByRegionAndSlug',
76
                'arguments' => array(
77
                    array('value' => 'normandie'),
78
                    array('name' => 'slug'),
79
                ),
80
        ));
81
    }
82
83
    function it_should_throw_exception_when_resource_is_missing_method_option($request)
0 ignored issues
show
Coding Style introduced by
Method name "OptionsBasedSpec::it_should_throw_exception_when_resource_is_missing_method_option" is not in camel caps format
Loading history...
84
    {
85
        $this->shouldThrow()->duringResolveResource($request, array(
86
            'service' => 'orm.cheese_repository',
87
            'arguments' => array(
88
                    array('name' => 'slug'),
89
            ),
90
        ));
91
    }
92
}
93
94
class CheeseRepository
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
95
{
96
    public function findBySlug($slug)
0 ignored issues
show
Unused Code introduced by
The parameter $slug is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
97
    {
98
    }
99
100
    public function findByRegionAndSlug($region, $slug)
0 ignored issues
show
Unused Code introduced by
The parameter $region is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $slug is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
101
    {
102
    }
103
}
104