| Conditions | 14 |
| Paths | 44 |
| Total Lines | 81 |
| 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 |
||
| 19 | public function load(ObjectManager $manager) |
||
| 20 | { |
||
| 21 | $env = $this->container->get('kernel')->getEnvironment(); |
||
| 22 | $configService = $this->container->get('ds_config.service.config'); |
||
| 23 | $service = $this->container->get('ds_api.api')->get('formio.authentication'); |
||
| 24 | $user = new FormioUser; |
||
| 25 | $user |
||
| 26 | ->setEmail($configService->get('ds_api.user.username')) |
||
| 27 | ->setPassword($configService->get('ds_api.user.password')); |
||
| 28 | $token = $service->login($user); |
||
| 29 | $service = $this->container->get('ds_api.api')->get('formio.form'); |
||
| 30 | $service->setHeader('x-jwt-token', $token); |
||
| 31 | $forms = $service->getList(); |
||
| 32 | |||
| 33 | foreach ($forms as $form) { |
||
| 34 | if (in_array($form->getName(), ['user', 'admin', 'userLogin', 'userRegister'])) { |
||
| 35 | // Skip base formio forms. |
||
| 36 | continue; |
||
| 37 | } |
||
| 38 | |||
| 39 | try { |
||
| 40 | $service->delete($form->getPath()); |
||
| 41 | } catch (ValidationException $exception) { |
||
| 42 | // @todo this is so first time fixtures dont cause an error, handle "Invalid alias" better |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | $api = $this->container->get('ds_api.api')->get('formio.role'); |
||
| 47 | $api->setHeader('x-jwt-token', $token); |
||
| 48 | $roles = $api->getList(); |
||
| 49 | $objects = $this->parse($this->getResource()); |
||
| 50 | |||
| 51 | foreach ($objects as $object) { |
||
| 52 | $form = new Form; |
||
| 53 | $form |
||
| 54 | ->setUuid($object->uuid) |
||
| 55 | ->setOwner($object->owner) |
||
| 56 | ->setOwnerUuid($object->owner_uuid) |
||
| 57 | ->setType($object->type) |
||
| 58 | ->setTenant($object->tenant); |
||
| 59 | |||
| 60 | switch ($object->type) { |
||
| 61 | case Form::TYPE_FORMIO: |
||
| 62 | $config = $object->config; |
||
| 63 | |||
| 64 | if (property_exists($config, 'components')) { |
||
| 65 | if (is_string($config->components)) { |
||
| 66 | $config->components = json_decode(file_get_contents(dirname(str_replace('{env}', $env, $this->getResource())).'/'.$config->components)); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | if (property_exists($config, 'submission_access')) { |
||
| 71 | if (is_string($config->submission_access)) { |
||
| 72 | $config->submission_access = json_decode(file_get_contents(dirname(str_replace('{env}', $env, $this->getResource())).'/'.$config->submission_access)); |
||
| 73 | $submissionAccess = []; |
||
| 74 | |||
| 75 | foreach ($config->submission_access as $access) { |
||
| 76 | foreach ($access->roles as $key => $value) { |
||
| 77 | foreach ($roles as $role) { |
||
| 78 | if ($role->getMachineName() === $value) { |
||
| 79 | $access->roles[$key] = $role->getId(); |
||
| 80 | break; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | $submissionAccess[] = $access; |
||
| 86 | } |
||
| 87 | |||
| 88 | $config->submission_access = $submissionAccess; |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | $form->setConfig($config); |
||
| 93 | break; |
||
| 94 | } |
||
| 95 | |||
| 96 | $manager->persist($form); |
||
| 97 | $manager->flush(); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | } |
||
| 101 |