| Conditions | 15 |
| Paths | 88 |
| Total Lines | 86 |
| 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 | ->setType($object->type) |
||
| 71 | ->setTenant($object->tenant); |
||
| 72 | |||
| 73 | switch ($object->type) { |
||
| 74 | case FormEntity::TYPE_FORMIO: |
||
| 75 | $config = $object->config; |
||
| 76 | |||
| 77 | if (property_exists($config, 'components')) { |
||
| 78 | if (is_string($config->components)) { |
||
| 79 | $config->components = json_decode(file_get_contents(dirname(str_replace('{fixtures}', $fixtures, $this->path)).'/'.$config->components)); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | if (property_exists($config, 'submissionAccess')) { |
||
| 84 | if (is_string($config->submissionAccess)) { |
||
| 85 | $config->submissionAccess = json_decode(file_get_contents(dirname(str_replace('{fixtures}', $fixtures, $this->path)).'/'.$config->submissionAccess)); |
||
| 86 | $submissionAccess = []; |
||
| 87 | |||
| 88 | foreach ($config->submissionAccess as $access) { |
||
| 89 | foreach ($access->roles as $key => $value) { |
||
| 90 | foreach ($roles as $role) { |
||
| 91 | if ($role->getMachineName() === $value) { |
||
| 92 | $access->roles[$key] = $role->getId(); |
||
| 93 | break; |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | $submissionAccess[] = $access; |
||
| 99 | } |
||
| 100 | |||
| 101 | $config->submissionAccess = $submissionAccess; |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | $form->setConfig((array) $config); |
||
| 106 | break; |
||
| 107 | } |
||
| 108 | |||
| 109 | $manager->persist($form); |
||
| 110 | } |
||
| 111 | |||
| 112 | $manager->flush(); |
||
| 113 | } |
||
| 114 | } |
||
| 115 |