Passed
Push — master ( 82d9da...92dcc2 )
by Derek Stephen
03:51
created

OAuthPackage::addToContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 62
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 33
CRAP Score 1.0005

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 62
ccs 33
cts 36
cp 0.9167
rs 9.36
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1.0005

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace OAuth;
3
4
use Del\Common\Container\RegistrationInterface;
5
use Del\Service\UserService;
6
use Doctrine\ORM\EntityManager;
7
use OAuth\Service\ClientService;
8
use Pimple\Container;
9
10
class OAuthPackage implements RegistrationInterface
11
{
12
    /**
13
     * @param Container $c
14
     */
15 11
    public function addToContainer(Container $c)
16
    {
17
        // AccessToken
18
        $function = function ($c) {
19
            /** @var EntityManager $entityManager */
20 1
            $entityManager = $c['doctrine.entity_manager'];
21 1
            $repository = $entityManager->getRepository('OAuth\AccessToken');
22 1
            return $repository;
23 1
        };
24 11
        $c['repository.AccessToken'] = $c->factory($function);
25
26
        // AuthCode
27
        $function = function ($c) {
28
            /** @var EntityManager $entityManager */
29 1
            $entityManager = $c['doctrine.entity_manager'];
30 1
            $repository = $entityManager->getRepository('OAuth\AuthCode');
31 1
            return $repository;
32 11
        };
33 11
        $c['repository.AuthCode'] = $c->factory($function);
34
35
        // Client
36
        $function = function ($c) {
37
            /** @var EntityManager $entityManager */
38 1
            $entityManager = $c['doctrine.entity_manager'];
39 1
            $repository = $entityManager->getRepository('OAuth\Client');
40 1
            return $repository;
41 11
        };
42 11
        $c['repository.Client'] = $c->factory($function);
43
44
        $function = function ($c) {
45
            $repository = $c['repository.Client'];
46
            $svc = new ClientService($repository);
47
            return $svc;
48 11
        };
49 11
        $c['oauth.service.client'] = $c->factory($function);
50
51
        // RefreshToken
52
        $function = function ($c) {
53
            /** @var EntityManager $entityManager */
54 1
            $entityManager = $c['doctrine.entity_manager'];
55 1
            $repository = $entityManager->getRepository('OAuth\RefreshToken');
56 1
            return $repository;
57 11
        };
58 11
        $c['repository.RefreshToken'] = $c->factory($function);
59
60
        // Scope
61
        $function = function ($c) {
62
            /** @var EntityManager $entityManager */
63 1
            $entityManager = $c['doctrine.entity_manager'];
64 1
            $repository = $entityManager->getRepository('OAuth\Scope');
65 1
            return $repository;
66 11
        };
67 11
        $c['repository.Scope'] = $c->factory($function);
68
69
        // User
70
        $function = function ($c) {
71
            /** @var EntityManager $entityManager */
72 1
            $entityManager = $c['doctrine.entity_manager'];
73 1
            $repository = $entityManager->getRepository(OAuthUser::class);
74 1
            return $repository;
75 11
        };
76 11
        $c['repository.User'] = $c->factory($function);
77 11
    }
78
79 11
    public function getEntityPath()
80
    {
81 11
        return 'src/Entity/OAuth';
82
    }
83
84 11
    public function hasEntityPath()
85
    {
86 11
        return true;
87
    }
88
89
}