Completed
Push — master ( 2e0cd6...c623e8 )
by Pavel
12:31
created

CrudsExtension   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 80%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
c 2
b 0
f 0
lcom 1
cbo 5
dl 0
loc 49
ccs 24
cts 30
cp 0.8
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 20 3
A registerSymfonyFormsCompatibility() 0 6 2
A registerJmsSerializerCompatibility() 0 3 1
A registerSymfonySerializerCompatibility() 0 6 2
A registerDoctrineOrmCompatibility() 0 6 2
1
<?php
2
3
namespace ScayTrase\Api\Cruds\DependencyInjection;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Extension\Extension;
8
use Symfony\Component\DependencyInjection\Loader;
9
10
final class CrudsExtension extends Extension
11
{
12
    /** {@inheritdoc} */
13 2
    public function load(array $configs, ContainerBuilder $container)
14
    {
15 2
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
16 2
        $loader->load('cruds.yml');
17
18 2
        $this->registerSymfonyFormsCompatibility($container);
19 2
        $this->registerJmsSerializerCompatibility($container);
0 ignored issues
show
Unused Code introduced by
The call to the method ScayTrase\Api\Cruds\Depe...rializerCompatibility() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
20 2
        $this->registerSymfonySerializerCompatibility($container);
21
22 2
        $config = $this->processConfiguration($this->getConfiguration([], $container), $configs);
0 ignored issues
show
Documentation introduced by
$this->getConfiguration(array(), $container) is of type object|null, but the function expects a object<Symfony\Component...ConfigurationInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
23
24 2
        $configurator = new CrudsEntitiesConfigurator($container);
25 2
        $container->addObjectResource($configurator);
26 2
        $prefix = $config['prefix'];
27 2
        foreach ($config['entities'] as $name => $entityConfig) {
28 2
            $entityConfig['prefix'] = $entityConfig['prefix'] ?: '/'.$name;
29 2
            $entityConfig['prefix'] = $prefix.$entityConfig['prefix'];
30 2
            $configurator->processEntityConfiguration($name, $entityConfig);
31 2
        }
32 2
    }
33
34 2
    private function registerSymfonyFormsCompatibility(ContainerBuilder $container)
35
    {
36 2
        if (!$container->has('form.registry')) {
37 2
            return;
38
        }
39
    }
40
41 2
    private function registerJmsSerializerCompatibility(ContainerBuilder $container)
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...
42
    {
43 2
    }
44
45 2
    private function registerSymfonySerializerCompatibility(ContainerBuilder $container)
46
    {
47 2
        if (!$container->has('serializer')) {
48 2
            return;
49
        }
50
    }
51
52
    private function registerDoctrineOrmCompatibility(ContainerBuilder $container)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
53
    {
54
        if (!$container->has('doctrine')) {
55
            return;
56
        }
57
    }
58
}
59