Conditions | 15 |
Paths | 88 |
Total Lines | 87 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
28 | public function load(ObjectManager $manager) |
||
29 | { |
||
30 | $fixtures = array_key_exists('FIXTURES', $_ENV) ? $_ENV['FIXTURES'] : 'dev'; |
||
31 | $configService = $this->container->get(ConfigService::class); |
||
32 | |||
33 | $service = $this->container->get(Api::class)->get('formio.authentication'); |
||
34 | $user = new FormioUser; |
||
35 | $user |
||
36 | ->setEmail($configService->get('ds_api.user.username')) |
||
37 | ->setPassword($configService->get('ds_api.user.password')); |
||
38 | $token = $service->login($user); |
||
39 | |||
40 | $service = $this->container->get(Api::class)->get('formio.form'); |
||
41 | $service->setHeader('x-jwt-token', $token); |
||
42 | $forms = $service->getList(); |
||
43 | |||
44 | foreach ($forms as $form) { |
||
45 | if (in_array($form->getName(), ['user', 'admin', 'userLogin', 'userRegister'])) { |
||
46 | // Skip base formio forms |
||
47 | continue; |
||
48 | } |
||
49 | |||
50 | try { |
||
51 | $service->delete($form->getPath()); |
||
52 | } catch (ValidationException $exception) { |
||
53 | // @todo this is so first time fixtures dont cause an error, handle "Invalid alias" better |
||
54 | } |
||
55 | } |
||
56 | |||
57 | $api = $this->container->get(Api::class)->get('formio.role'); |
||
58 | $api->setHeader('x-jwt-token', $token); |
||
59 | $roles = $api->getList(); |
||
60 | $objects = $this->parse($this->path); |
||
61 | |||
62 | foreach ($objects as $object) { |
||
63 | $form = new FormEntity; |
||
64 | $form |
||
65 | ->setUuid($object->uuid) |
||
66 | ->setOwner($object->owner) |
||
67 | ->setOwnerUuid($object->owner_uuid) |
||
68 | ->setTitle((array) $object->title) |
||
69 | ->setDescription((array) $object->description) |
||
70 | ->setData((array) $object->data) |
||
71 | ->setType($object->type) |
||
72 | ->setTenant($object->tenant); |
||
73 | |||
74 | switch ($object->type) { |
||
75 | case FormEntity::TYPE_FORMIO: |
||
76 | $config = $object->config; |
||
77 | |||
78 | if (property_exists($config, 'components')) { |
||
79 | if (is_string($config->components)) { |
||
80 | $config->components = json_decode(file_get_contents(dirname(str_replace('{fixtures}', $fixtures, $this->path)).'/'.$config->components)); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | if (property_exists($config, 'submissionAccess')) { |
||
85 | if (is_string($config->submissionAccess)) { |
||
86 | $config->submissionAccess = json_decode(file_get_contents(dirname(str_replace('{fixtures}', $fixtures, $this->path)).'/'.$config->submissionAccess)); |
||
87 | $submissionAccess = []; |
||
88 | |||
89 | foreach ($config->submissionAccess as $access) { |
||
90 | foreach ($access->roles as $key => $value) { |
||
91 | foreach ($roles as $role) { |
||
92 | if ($role->getMachineName() === $value) { |
||
93 | $access->roles[$key] = $role->getId(); |
||
94 | break; |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | |||
99 | $submissionAccess[] = $access; |
||
100 | } |
||
101 | |||
102 | $config->submissionAccess = $submissionAccess; |
||
103 | } |
||
104 | } |
||
105 | |||
106 | $form->setConfig((array) $config); |
||
107 | break; |
||
108 | } |
||
109 | |||
110 | $manager->persist($form); |
||
111 | } |
||
112 | |||
113 | $manager->flush(); |
||
114 | } |
||
115 | } |
||
116 |