Completed
Push — master ( d14457...da0e1e )
by Derek Stephen
25:25 queued 19:55
created

OAuthPackage::addToContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 62
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1.216

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 62
ccs 14
cts 35
cp 0.4
rs 9.36
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1.216

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 7
    public function addToContainer(Container $c)
16
    {
17
        // AccessToken
18
        $function = function ($c) {
19
            /** @var EntityManager $entityManager */
20
            $entityManager = $c['doctrine.entity_manager'];
21
            $repository = $entityManager->getRepository('OAuth\AccessToken');
22
            return $repository;
23
        };
24 7
        $c['repository.AccessToken'] = $c->factory($function);
25
26
        // AuthCode
27
        $function = function ($c) {
28
            /** @var EntityManager $entityManager */
29
            $entityManager = $c['doctrine.entity_manager'];
30
            $repository = $entityManager->getRepository('OAuth\AuthCode');
31
            return $repository;
32 7
        };
33 7
        $c['repository.AuthCode'] = $c->factory($function);
34
35
        // Client
36
        $function = function ($c) {
37
            /** @var EntityManager $entityManager */
38
            $entityManager = $c['doctrine.entity_manager'];
39
            $repository = $entityManager->getRepository('OAuth\Client');
40
            return $repository;
41 7
        };
42 7
        $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 7
        };
49 7
        $c['oauth.service.client'] = $c->factory($function);
50
51
        // RefreshToken
52
        $function = function ($c) {
53
            /** @var EntityManager $entityManager */
54
            $entityManager = $c['doctrine.entity_manager'];
55
            $repository = $entityManager->getRepository('OAuth\RefreshToken');
56
            return $repository;
57 7
        };
58 7
        $c['repository.RefreshToken'] = $c->factory($function);
59
60
        // Scope
61
        $function = function ($c) {
62
            /** @var EntityManager $entityManager */
63
            $entityManager = $c['doctrine.entity_manager'];
64
            $repository = $entityManager->getRepository('OAuth\Scope');
65
            return $repository;
66 7
        };
67 7
        $c['repository.Scope'] = $c->factory($function);
68
69
        // User
70
        $function = function ($c) {
71
            /** @var EntityManager $entityManager */
72
            $entityManager = $c['doctrine.entity_manager'];
73
            $repository = $entityManager->getRepository(OAuthUser::class);
74
            return $repository;
75 7
        };
76 7
        $c['repository.User'] = $c->factory($function);
77 7
    }
78
79 7
    public function getEntityPath()
80
    {
81 7
        return 'src/Entity/OAuth';
82
    }
83
84 7
    public function hasEntityPath()
85
    {
86 7
        return true;
87
    }
88
89
}