Passed
Push — master ( 62083f...ad8d4a )
by Julito
10:31
created

TicketFixtures::load()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 84
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 54
nc 8
nop 1
dl 0
loc 84
rs 9.0036
c 1
b 0
f 0

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
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\DataFixtures;
8
9
use Chamilo\CoreBundle\Entity\TicketCategory;
10
use Chamilo\CoreBundle\Entity\TicketPriority;
11
use Chamilo\CoreBundle\Entity\TicketProject;
12
use Chamilo\CoreBundle\Entity\TicketStatus;
13
use Doctrine\Persistence\ObjectManager;
14
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
15
use TicketManager;
16
17
/**
18
 * @internal
19
 * @coversNothing
20
 */
21
class TicketFixtures extends KernelTestCase
22
{
23
    public function load(ObjectManager $manager): void
24
    {
25
        self::bootKernel();
26
27
        $container = $this->getContainer();
28
        $trans = $container->get('translator');
29
30
        $adminId = 1;
31
32
        $ticketProject = new TicketProject();
33
        $ticketProject
34
            ->setName('Ticket System')
35
            ->setInsertUserId($adminId)
36
        ;
37
38
        $manager->persist($ticketProject);
39
        $manager->flush();
40
41
        $categories = [
42
            $trans->trans('Enrollment') => $trans->trans('Tickets about enrollment'),
43
            $trans->trans('General information') => $trans->trans('Tickets about general information'),
44
            $trans->trans('Requests and paperwork') => $trans->trans('Tickets about requests and paperwork'),
45
            $trans->trans('Academic Incidents') => $trans->trans('Tickets about academic incidents, like exams, practices, tasks, etc.'),
46
            $trans->trans('Virtual campus') => $trans->trans('Tickets about virtual campus'),
47
            $trans->trans('Online evaluation') => $trans->trans('Tickets about online evaluation'),
48
        ];
49
50
        $i = 1;
51
        foreach ($categories as $category => $description) {
52
            // Online evaluation requires a course
53
            $ticketCategory = new TicketCategory();
54
            $ticketCategory
55
                ->setName($category)
56
                ->setDescription($description)
57
                ->setProject($ticketProject)
58
                ->setInsertUserId($adminId)
59
            ;
60
61
            $isRequired = 6 === $i;
62
            $ticketCategory->setCourseRequired($isRequired);
63
64
            $manager->persist($ticketCategory);
65
            $i++;
66
        }
67
68
        // Default Priorities
69
        $defaultPriorities = [
70
            TicketManager::PRIORITY_NORMAL => $trans->trans('Normal'),
71
            TicketManager::PRIORITY_HIGH => $trans->trans('High'),
72
            TicketManager::PRIORITY_LOW => $trans->trans('Low'),
73
        ];
74
75
        foreach ($defaultPriorities as $code => $priority) {
76
            $ticketPriority = new TicketPriority();
77
            $ticketPriority
78
                ->setName($priority)
79
                ->setCode($code)
80
                ->setInsertUserId($adminId)
81
            ;
82
83
            $manager->persist($ticketPriority);
84
        }
85
86
        $manager->flush();
87
88
        // Default status
89
        $defaultStatus = [
90
            TicketManager::STATUS_NEW => $trans->trans('New'),
91
            TicketManager::STATUS_PENDING => $trans->trans('Pending'),
92
            TicketManager::STATUS_UNCONFIRMED => $trans->trans('Unconfirmed'),
93
            TicketManager::STATUS_CLOSE => $trans->trans('Close'),
94
            TicketManager::STATUS_FORWARDED => $trans->trans('Forwarded'),
95
        ];
96
97
        foreach ($defaultStatus as $code => $status) {
98
            $ticketStatus = new TicketStatus();
99
            $ticketStatus
100
                ->setName($status)
101
                ->setCode($code)
102
            ;
103
            $manager->persist($ticketStatus);
104
        }
105
106
        $manager->flush();
107
    }
108
}
109