| Conditions | 8 |
| Paths | 4 |
| Total Lines | 79 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 85 | public function configureFields(string $pageName): iterable |
||
| 86 | { |
||
| 87 | if (Crud::PAGE_DETAIL === $pageName) { |
||
| 88 | return [ |
||
| 89 | FormField::addPanel("Details")->addCssClass("col-12 col-xl-6"), |
||
| 90 | Field::new('name'), |
||
| 91 | Field::new('username'), |
||
| 92 | TextField::new('status')->setTemplatePath('@Oliverde8PhpEtl/fields/status.html.twig'), |
||
| 93 | FormField::addPanel()->addCssClass("col-12 col-xl-6"), |
||
| 94 | Field::new('createTime'), |
||
| 95 | Field::new('startTime'), |
||
| 96 | Field::new('endTime'), |
||
| 97 | Field::new('failTime'), |
||
| 98 | |||
| 99 | FormField::addPanel('Execution Inputs')->addCssClass('col-12'), |
||
| 100 | CodeEditorField::new('inputData')->setTemplatePath('@Oliverde8PhpEtl/fields/code_editor.html.twig')->addCssClass('etl-json-div'), |
||
| 101 | CodeEditorField::new('inputOptions')->setTemplatePath('@Oliverde8PhpEtl/fields/code_editor.html.twig')->addCssClass('etl-json-div'), |
||
| 102 | CodeEditorField::new('definition')->setTemplatePath('@Oliverde8PhpEtl/fields/code_editor.html.twig'), |
||
| 103 | |||
| 104 | FormField::addPanel('Execution outpus')->addCssClass("col-12"), |
||
| 105 | TextField::new('Files')->formatValue(function ($value, EtlExecution $entity) { |
||
| 106 | $urls = []; |
||
| 107 | if ($this->isGranted(EtlExecutionVoter::DOWNLOAD, EtlExecution::class)) { |
||
| 108 | $files = $this->chainWorkDirManager->listFiles($entity); |
||
| 109 | foreach ($files as $file) { |
||
| 110 | $url = $this->adminUrlGenerator |
||
| 111 | ->setRoute("etl_execution_download_file", ['execution' => $entity->getId(), 'filename' => $file]) |
||
| 112 | ->generateUrl(); |
||
| 113 | |||
| 114 | $urls[$url] = $file; |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | return $urls; |
||
| 119 | })->setTemplatePath('@Oliverde8PhpEtl/fields/files.html.twig'), |
||
| 120 | CodeEditorField::new('errorMessage')->setTemplatePath('@Oliverde8PhpEtl/fields/code_editor.html.twig'), |
||
| 121 | TextField::new('Logs')->formatValue(function ($value, EtlExecution $entity) { |
||
| 122 | $logs = $this->chainWorkDirManager->getFirstLogLines($entity, 100); |
||
| 123 | $url = ""; |
||
| 124 | $moreLogs = false; |
||
| 125 | if (!empty($logs)) { |
||
| 126 | $url = $this->adminUrlGenerator |
||
| 127 | ->setRoute("etl_execution_download_file", ['execution' => $entity->getId(), 'filename' => 'execution.log']) |
||
| 128 | ->generateUrl(); |
||
| 129 | } |
||
| 130 | if (count($logs) > 100) { |
||
| 131 | $moreLogs = true; |
||
| 132 | } |
||
| 133 | |||
| 134 | return [ |
||
| 135 | "lines" => $logs, |
||
| 136 | 'downloadUrl' => $url, |
||
| 137 | 'moreLogs' => $moreLogs, |
||
| 138 | ]; |
||
| 139 | })->setTemplatePath('@Oliverde8PhpEtl/fields/logs.html.twig'), |
||
| 140 | |||
| 141 | ]; |
||
| 142 | } |
||
| 143 | if (Crud::PAGE_INDEX === $pageName) { |
||
| 144 | return [ |
||
| 145 | Field::new('id'), |
||
| 146 | Field::new('name'), |
||
| 147 | Field::new('username'), |
||
| 148 | TextField::new('status')->setTemplatePath('@Oliverde8PhpEtl/fields/status.html.twig'), |
||
| 149 | Field::new('createTime'), |
||
| 150 | Field::new('startTime'), |
||
| 151 | Field::new('endTime'), |
||
| 152 | ]; |
||
| 153 | } |
||
| 154 | if (Crud::PAGE_NEW === $pageName) { |
||
| 155 | return [ |
||
| 156 | ChoiceField::new('name', 'Chain Name') |
||
| 157 | ->setChoices($this->getChainOptions()), |
||
| 158 | CodeEditorField::new('inputData')->setCssClass("etl-json-input"), |
||
| 159 | CodeEditorField::new('inputOptions')->setCssClass("etl-json-input"), |
||
| 160 | ]; |
||
| 161 | } |
||
| 162 | |||
| 163 | return parent::configureFields($pageName); |
||
| 164 | } |
||
| 220 |