| Conditions | 7 |
| Paths | 14 |
| Total Lines | 61 |
| Code Lines | 43 |
| 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 |
||
| 57 | public function buildForm(array $form, FormStateInterface $form_state) { |
||
| 58 | $packages = Exportable::getClasses(__DIR__ . "/../..", BasePackage::class); |
||
| 59 | ksort($packages); |
||
| 60 | |||
| 61 | $session = $this->getRequest()->getSession(); |
||
| 62 | foreach ($packages as $package_name => $package) { |
||
| 63 | $open = FALSE; |
||
| 64 | $form[$package_name] = array( |
||
| 65 | '#type' => 'details', |
||
| 66 | '#title' => Xss::filterAdmin($package->title), |
||
| 67 | '#description' => Xss::filterAdmin($package->description), |
||
| 68 | '#collapsible' => TRUE, |
||
| 69 | ); |
||
| 70 | $controls = $package->getClasses($package->dir, BaseControl::class); |
||
| 71 | foreach ($controls as $control_name => $control) { |
||
| 72 | $default_value = $session->get($control_name); |
||
| 73 | if ($default_value) { |
||
| 74 | $open = TRUE; |
||
| 75 | } |
||
| 76 | $deps = array(); |
||
| 77 | $met = TRUE; |
||
| 78 | foreach ($control->getDependencies() as $dep_name) { |
||
| 79 | if ($this->moduleHandler->moduleExists($dep_name)) { |
||
| 80 | $deps[] = $this->t('@module (<span class="admin-enabled">available</span>)', [ |
||
| 81 | '@module' => $dep_name, |
||
| 82 | ]); |
||
| 83 | } |
||
| 84 | else { |
||
| 85 | $deps[] = $this->t('@module (<span class="admin-disabled">unavailable</span>)', [ |
||
| 86 | '@module' => $dep_name, |
||
| 87 | ]); |
||
| 88 | $met = FALSE; |
||
| 89 | } |
||
| 90 | } |
||
| 91 | $form[$package_name][$control_name] = [ |
||
| 92 | '#type' => 'checkbox', |
||
| 93 | '#default_value' => $met ? $default_value : 0, |
||
| 94 | '#title' => Xss::filterAdmin($control->title), |
||
| 95 | '#description' => Xss::filterAdmin($control->description), |
||
| 96 | '#disabled' => !$met, |
||
| 97 | ]; |
||
| 98 | $form[$package_name][$control_name .'-dependencies'] = [ |
||
| 99 | '#value' => $this->t('Depends on: !dependencies', [ |
||
| 100 | '!dependencies' => implode(', ', $deps), |
||
| 101 | ]), |
||
| 102 | '#prefix' => '<div class="admin-dependencies">', |
||
| 103 | '#suffix' => '</div>', |
||
| 104 | ]; |
||
| 105 | } |
||
| 106 | $form[$package_name]['#open'] = $open; |
||
| 107 | } |
||
| 108 | |||
| 109 | $form['actions'] = [ |
||
| 110 | '#type' => 'actions', |
||
| 111 | ]; |
||
| 112 | $form['actions']['submit'] = [ |
||
| 113 | '#type' => 'submit', |
||
| 114 | '#value' => $this->t('Run checked controls'), |
||
| 115 | ]; |
||
| 116 | |||
| 117 | return $form; |
||
| 118 | } |
||
| 232 |