Completed
Push — master ( a551e2...7bb49b )
by Derek Stephen
04:03
created

OAuthPackage::addToContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 63
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 27
CRAP Score 1.0515

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 63
ccs 27
cts 43
cp 0.6279
rs 9.4347
cc 1
eloc 36
nc 1
nop 1
crap 1.0515

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