Completed
Push — master ( affb41...f007be )
by Rafał
09:54
created

LoadUsersData::load()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 60

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 60
ccs 9
cts 9
cp 1
rs 8.8727
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1

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
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Fixtures Bundle.
7
 *
8
 * Copyright 2016 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2016 Sourcefabric z.ú.
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\FixturesBundle\DataFixtures\ORM;
18
19
use Doctrine\Common\DataFixtures\FixtureInterface;
20
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
21
use Doctrine\Common\Persistence\ObjectManager;
22
use SWP\Bundle\CoreBundle\Model\UserInterface;
23
use SWP\Bundle\FixturesBundle\AbstractFixture;
24
25
class LoadUsersData extends AbstractFixture implements FixtureInterface, OrderedFixtureInterface
26
{
27 102
    /**
28
     * {@inheritdoc}
29 102
     */
30
    public function load(ObjectManager $manager): void
31 102
    {
32 102
        $userManager = $this->container->get('swp_user.user_manager');
33 102
34 102
        /** @var UserInterface $user */
35 102
        $user = $userManager->createUser();
36
        $user->setUsername('test.user');
37 102
        $user->setEmail('[email protected]');
38
        
39 102
        $passwordEncoder = $this->container->get('security.password_encoder');          
40 102
41 102
        $user->setPassword(
42
            $passwordEncoder->encodePassword(
43
                $user,
44
                'testPassword'
45
            )
46
        );
47
        $user->addRole('ROLE_INTERNAL_API');
48
49
        $userManager->updateUser($user);
50
51
        $apiKey = $this->container->get('swp.factory.api_key')->create($user, base64_encode('test_token:'));
52
        $this->container->get('swp.repository.api_key')->add($apiKey);
53
54
        /** @var UserInterface $user */
55
        $user = $userManager->createUser();
56
        $user->setUsername('test.client1');
57
        $user->setEmail('[email protected]');
58
        $user->setPassword(
59
            $passwordEncoder->encodePassword(
60
                $user,
61
                'testPassword'
62
            )
63
        );
64
        $user->addRole('ROLE_INTERNAL_API');
65
        $user->setOrganization($this->container->get('swp.repository.organization')->findOneByCode('654321'));
66
67
        $userManager->updateUser($user);
68
69
        $apiKey = $this->container->get('swp.factory.api_key')->create($user, base64_encode('client1_token'));
70
        $this->container->get('swp.repository.api_key')->add($apiKey);
71
72
        /** @var UserInterface $user */
73
        $user = $userManager->createUser();
74
        $user->setUsername('test.client2');
75
        $user->setEmail('[email protected]');
76
        $user->setPassword(
77
            $passwordEncoder->encodePassword(
78
                $user,
79
                'testPassword'
80
            )
81
        );
82
        $user->addRole('ROLE_INTERNAL_API');
83
        $user->setOrganization($this->container->get('swp.repository.organization')->findOneByCode('123456'));
84
85
        $userManager->updateUser($user);
86
87
        $apiKey = $this->container->get('swp.factory.api_key')->create($user, base64_encode('client2_token'));
88
        $this->container->get('swp.repository.api_key')->add($apiKey);
89
    }
90
91
    public function getOrder(): int
92
    {
93
        return 0;
94
    }
95
}
96