From e825ffcbdd46020cb4201b4f14fdd9af9cfaecad Mon Sep 17 00:00:00 2001
From: Nejc <nejc.koporec@agiledrop.com>
Date: Tue, 24 Apr 2018 10:54:17 +0200
Subject: [PATCH] Initial code cleanup

---
 fpa.form_alter.inc               |  66 ----
 fpa.module                       |  16 +-
 src/Controller/FPAController.php |   6 +
 src/FPAFormBuilder.php           | 662 +++++++++++++++++++++------------------
 src/Routing/RouteSubscriber.php  |   4 +-
 5 files changed, 376 insertions(+), 378 deletions(-)
 delete mode 100644 fpa.form_alter.inc

diff --git a/fpa.form_alter.inc b/fpa.form_alter.inc
deleted file mode 100644
index 7a76c6e..0000000
--- a/fpa.form_alter.inc
+++ /dev/null
@@ -1,66 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains form alter hooks to inject FPA functionality.
- */
-
-
-/**
- * Implements hook_form_FORM_ID_alter().
- */
-function fpa_form_node_type_form_alter(&$form, &$form_state) {
-  if (!empty($form['type']['#default_value']) && user_access('administer permissions')) {
-    fpa_fieldset($form['#node_type']->type . ' content', $form, array('#group' => 'additional_settings'));
-  }
-}
-
-/**
- * Implements hook_form_FORM_ID_alter().
- */
-function fpa_form_user_admin_permissions_alter(&$form, &$form_state) {
-  
-  // Prevent duplication of memory limit warning.
-  if (module_exists('filter_perms') && empty($form_state['input'])) {
-    
-    $memory_limit = ini_get('memory_limit');
-    
-    if (!drupal_check_memory_limit(_fpa_memory_required() . 'b', $memory_limit)) {
-      drupal_set_message(t('If you attempt to display all roles and permissions on this page at the same time, you will most likely exceed your PHP memory limit of %memory_limit.', array('%memory_limit' => $memory_limit)), 'warning');
-    }
-  }
-    
-  $form['#theme'] = array('fpa_user_admin_permissions');
-  
-  $fpa_module_path = drupal_get_path('module', 'fpa');
-  
-  $form['#attached']['library'][] = array('system', 'jquery.cookie');
-
-  $form['#attached']['css'][] = $fpa_module_path . '/css/fpa.css';
-  $form['#attached']['js'][] = $fpa_module_path . '/js/fpa.min.js';
-  $form['#attached']['js'][] = array(
-    'type' => 'setting',
-    'data' => array(
-      'fpa' => array(
-        'attr' => array(
-          'permission' =>  FPA_ATTR_PERMISSION,
-          'module' =>      FPA_ATTR_MODULE,
-          'role' =>        FPA_ATTR_ROLE,
-          
-          'checked' =>     FPA_ATTR_CHECKED,
-          'not_checked' => FPA_ATTR_NOT_CHECKED,
-
-          'system_name' => FPA_ATTR_SYSTEM_NAME,
-        ),
-      ),
-    ),
-  );
-}
-
-/**
- * Implements hook_form_FORM_ID_alter().
- */
-function fpa_form_filter_perms_admin_perm_filter_alter(&$form, &$form_state) {
-  
-  $form['#submit'][] = '_fpa_reset_filter_defaults';
-}
diff --git a/fpa.module b/fpa.module
index acb9efd..96f4ccb 100644
--- a/fpa.module
+++ b/fpa.module
@@ -8,12 +8,11 @@
 use Drupal\Core\Routing\RouteMatchInterface;
 use Drupal\fpa\FPAFormBuilder;
 
+define('FPA_ATTR_PERMISSION', 'fpa-permission');
+define('FPA_ATTR_MODULE', 'fpa-module');
+define('FPA_ATTR_ROLE', 'fpa-role');
 
-define('FPA_ATTR_PERMISSION',  'fpa-permission');
-define('FPA_ATTR_MODULE',      'fpa-module');
-define('FPA_ATTR_ROLE',        'fpa-role');
-
-define('FPA_ATTR_CHECKED',     'fpa-checked');
+define('FPA_ATTR_CHECKED', 'fpa-checked');
 define('FPA_ATTR_NOT_CHECKED', 'fpa-not-checked');
 
 define('FPA_ATTR_SYSTEM_NAME', 'fpa-system-name');
@@ -46,3 +45,10 @@ function fpa_form_user_admin_permissions_alter(&$form, &$form_state) {
     }
   }
 }
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ */
+function fpa_form_filter_perms_admin_perm_filter_alter(&$form, &$form_state) {
+  $form['#submit'][] = '_fpa_reset_filter_defaults';
+}
diff --git a/src/Controller/FPAController.php b/src/Controller/FPAController.php
index 8018e5d..793f25d 100644
--- a/src/Controller/FPAController.php
+++ b/src/Controller/FPAController.php
@@ -17,6 +17,12 @@ use Drupal\fpa\FPAFormBuilder;
  */
 class FPAController extends ControllerBase {
 
+  /**
+   * Builds a permissions page.
+   *
+   * @return mixed
+   *   Returns a render array.
+   */
   public function permissionsList() {
     $render = FPAFormBuilder::buildFPAPage();
 
diff --git a/src/FPAFormBuilder.php b/src/FPAFormBuilder.php
index 33c2abc..cdcee65 100644
--- a/src/FPAFormBuilder.php
+++ b/src/FPAFormBuilder.php
@@ -20,10 +20,13 @@ use Drupal\Core\Link;
  *
  * @package Drupal\fpa
  */
-class FPAFormBuilder{
+class FPAFormBuilder {
 
   /**
-   * @return int Approximate number of bytes of ram required to render the permissions form.
+   * Gets required memory.
+   *
+   * @return int
+   *   Number of bytes of ram required to render the permissions form.
    */
   public static function getRequiredMemory($suffix = '') {
     $permission = \Drupal::service('user.permissions');
@@ -33,116 +36,139 @@ class FPAFormBuilder{
     // Takes ~26kb per row without any checkboxes.
     $permission_row_overhead = 27261.028783658;
     $permissions_ram_required = $permissions_count * $permission_row_overhead;
-    // Determined by checking peak ram on permissions page, over several different number of visible roles.
+    // Determined by checking peak ram on permissions page,
+    // over several different number of visible roles.
     $bytes_per_checkbox = 18924.508820799;
     $checkboxes_ram_required = $permissions_count * $user_roles_count * $bytes_per_checkbox;
     $output = (int) ($page_ram_required + $permissions_ram_required + $checkboxes_ram_required);
-    if (!empty($suffix)) return $output . $suffix;
+    if (!empty($suffix)) {
+      return $output . $suffix;
+    }
     return $output;
   }
 
+  /**
+   * Checks memory limit.
+   *
+   * @return bool
+   *   Returns true of false.
+   */
   public static function checkMemoryLimit() {
     $permissions_memory_required = static::getRequiredMemory('b');
     $memory_limit = ini_get('memory_limit');
     return ((!$memory_limit) || ($memory_limit == -1) || (Bytes::toInt($memory_limit) >= Bytes::toInt($permissions_memory_required)));
   }
 
+  /**
+   * Builds the FPA pages.
+   *
+   * @return mixed
+   *   Returns render array.
+   */
   public static function buildFPAPage() {
     $form = \Drupal::service('form_builder')->getForm('\Drupal\user\Form\UserPermissionsForm');
 
     $render = static::buildTable($form);
     $render['#attached']['library'][] = 'fpa/fpa.permissions';
-    $render['#attached']['drupalSettings'] = array(
-      'fpa' => array(
-        'attr' => array(
-          'permission' =>  FPA_ATTR_PERMISSION,
-          'module' =>      FPA_ATTR_MODULE,
-          'role' =>        FPA_ATTR_ROLE,
-
-          'checked' =>     FPA_ATTR_CHECKED,
+    $render['#attached']['drupalSettings'] = [
+      'fpa' => [
+        'attr' => [
+          'permission' => FPA_ATTR_PERMISSION,
+          'module' => FPA_ATTR_MODULE,
+          'role' => FPA_ATTR_ROLE,
+
+          'checked' => FPA_ATTR_CHECKED,
           'not_checked' => FPA_ATTR_NOT_CHECKED,
 
           'system_name' => FPA_ATTR_SYSTEM_NAME,
-        )
-      )
-    );
+        ],
+      ],
+    ];
 
     return $render;
   }
 
+  /**
+   * Builds the permissions table.
+   *
+   * @param array $form
+   *   Form element.
+   *
+   * @return mixed
+   *   Returns render array.
+   */
   protected static function buildTable($form) {
     $renderer = \Drupal::service('renderer');
 
-    $nameless_checkbox = array(
+    $nameless_checkbox = [
       '#type' => 'html_tag',
       '#tag' => 'input',
-      '#attributes' => array(
+      '#attributes' => [
         'type' => 'checkbox',
-        'class' => array(
-          'rid-anonymous', // Prevents Drupal core Drupal.behaviors.permissions.toggle from applying.
+        'class' => [
+          'rid-anonymous', // Prevents core Drupal.behaviors.permissions.toggle from applying.
           'form-checkbox',
           'fpa-checkboxes-toggle',
-        ),
-      ),
-    );
+        ],
+      ],
+    ];
 
-    $dummy_checkbox = array(
+    $dummy_checkbox = [
       '#type' => 'html_tag',
       '#tag' => 'input',
-      '#attributes' => array(
+      '#attributes' => [
         'type' => 'checkbox',
         'disabled' => 'disabled',
         'checked' => 'checked',
         'title' => t('This permission is inherited from the authenticated user role.'),
-        'class' => array(
+        'class' => [
           'dummy-checkbox',
-        ),
-      ),
-    );
+        ],
+      ],
+    ];
 
     $dummy_checkbox_output = $renderer->render($dummy_checkbox);
 
-    $permission_col_template = array(
+    $permission_col_template = [
       '#type' => 'container',
-      '#attributes' => array(
-        'class' => array(
+      '#attributes' => [
+        'class' => [
           'fpa-permission-container',
-        ),
-      ),
-      'description' => array(),
-      'checkbox_cell' => array(
+        ],
+      ],
+      'description' => [],
+      'checkbox_cell' => [
         '#type' => 'container',
-        '#attributes' => array(
-          'class' => array(
+        '#attributes' => [
+          'class' => [
             'fpa-row-toggle-container',
-          ),
-        ),
-        'checkbox_form_item' => array(
+          ],
+        ],
+        'checkbox_form_item' => [
           '#type' => 'container',
-          '#attributes' => array(
+          '#attributes' => [
             'title' => t('Toggle visible checkboxes in this row.'),
-            'class' => array(
+            'class' => [
               'form-item',
               'form-type-checkbox',
-            ),
-          ),
-          'label' => array(
+            ],
+          ],
+          'label' => [
             '#type' => 'html_tag',
             '#tag' => 'label',
-            '#attributes' => array(
-              'class' => array(
+            '#attributes' => [
+              'class' => [
                 'visually-hidden',
-              ),
-            ),
+              ],
+            ],
             '#value' => 'test',
-          ),
-          'checkbox' => $nameless_checkbox
-        ),
-      ),
-    );
+          ],
+          'checkbox' => $nameless_checkbox,
+        ],
+      ],
+    ];
 
     $roles = \Drupal::service('entity.manager')->getStorage('user_role')->loadMultiple();
-//    $site_modules = array_keys(\Drupal::service('module_handler')->getModuleList());
 
     // Prepare role names processed by Html::getClass() ahead of time.
     $roles_attr_values = array();
@@ -151,9 +177,8 @@ class FPAFormBuilder{
       $roles_attr_values[$role->get('id')] = Html::getClass($role->get('label'));
     }
 
-//    reset($array);
-//    $first_role_index = key($array);
-
+    // reset($array);
+    // $first_role_index = key($array);
     // Lists for wrapper.
     $modules = array();
     $user_roles = array();
@@ -169,14 +194,18 @@ class FPAFormBuilder{
     foreach (Element::children($form['permissions']) as $key) {
 
       // Row template.
-      $row = array(
-        'data' => array(), // Array of table cells.
-        'title' => array(), // HTML attribute on table row tag.
-        FPA_ATTR_MODULE => array(), // HTML attribute on table row tag.
-        FPA_ATTR_PERMISSION => array(), // HTML attribute on table row tag.
-        FPA_ATTR_CHECKED => array(),
-        FPA_ATTR_NOT_CHECKED => array(),
-      );
+      $row = [
+        // Array of table cells.
+        'data' => [],
+        // HTML attribute on table row tag.
+        'title' => [],
+        // HTML attribute on table row tag.
+        FPA_ATTR_MODULE => [],
+        // HTML attribute on table row tag.
+        FPA_ATTR_PERMISSION => [],
+        FPA_ATTR_CHECKED => [],
+        FPA_ATTR_NOT_CHECKED => [],
+      ];
 
       $current_element = $form['permissions'][$key];
       hide($form['permissions'][$key]);
@@ -185,31 +214,30 @@ class FPAFormBuilder{
       // Determine if row is module or permission.
       if (is_numeric($sub_children[0])) {
         // Module row.
-
         $row['class'][] = 'fpa-module-row';
 
         // Mark current row with escaped module name.
-        $row[FPA_ATTR_MODULE] = array(
-          // System name
+        $row[FPA_ATTR_MODULE] = [
+          // System name.
           0 => $key,
-          // Readable name
+          // Readable name.
           1 => strip_tags($current_element[0]['#markup']),
-        );
+        ];
 
-        // Readable
+        // Readable.
         hide($form['permissions'][$key][0]);
-        $row['data'][] = array(
+        $row['data'][] = [
           'data' => $form['permissions'][$key][0],
-          'class' => array('module'),
+          'class' => ['module'],
           'id' => 'module-' . $key,
           'colspan' => count($form['role_names']['#value']) + 1,
-        );
+        ];
 
-        $row['title'] = array($key);
+        $row['title'] = [$key];
 
         $row[FPA_ATTR_SYSTEM_NAME] = $row[FPA_ATTR_MODULE][0];
 
-        $classes = array();
+        $classes = [];
         foreach ($row[FPA_ATTR_MODULE] as $item) {
           $classes[] = Html::getClass($item);
         }
@@ -233,27 +261,31 @@ class FPAFormBuilder{
 
         $permission_system_name = $form['permissions'][$key]['description']['#context']['title']->render();
         // TODO: find out why this was done in D7
-//        $permission_system_name = '';
-//        // Might be empty if no modules are displayed in Permissions Filter module.
-//        if (!empty($sub_children[$roles_keys[0]])) {
-//          $permission_system_name = $sub_children[$roles_keys[0]['#return_value'];
-//        }
+        /*
+        $permission_system_name = '';
+         // Might be empty if no modules are displayed in Permissions Filter module.
+        if (!empty($sub_children[$roles_keys[0]])) {
+        $permission_system_name = $sub_children[$roles_keys[0]['#return_value'];
+        }
+         */
 
         $label = $permission_col_template;
 
         $label['description'] = $current_element['description'];
 
         // TODO: work on integration with permission filter module
-//        // Permissions filter might cause no Roles to display.
-//        if (count(element_children($form['checkboxes'])) == 0) {
-//          unset($label['checkbox_cell']);
-//        }
+        /*
+        Permissions filter might cause no Roles to display.
+        if (count(element_children($form['checkboxes'])) == 0) {
+          unset($label['checkbox_cell']);
+        }
+         */
 
-        // Readable
-        $row['data'][] = array(
+        // Readable.
+        $row['data'][] = [
           'data' => $label,
-          'class' => array('permission'),
-        );
+          'class' => ['permission'],
+        ];
 
         foreach ($roles_keys as $rid) {
           $checkbox = $form['permissions'][$key][$rid];
@@ -261,7 +293,8 @@ class FPAFormBuilder{
           $checkbox['#title'] = $roles[$rid]->get('label') . ': ' . $checkbox['#title'];
           $checkbox['#title_display'] = 'invisible';
 
-          // Filter permissions strips role id class from checkbox. Used by Drupal core functionality.
+          // Filter permissions strips role id class from checkbox.
+          // Used by Drupal core functionality.
           $checkbox['#attributes']['class'][] = 'rid-' . $rid;
 
           // Set authenticated role behavior class on page load.
@@ -269,10 +302,12 @@ class FPAFormBuilder{
             $row['class'][] = 'fpa-authenticated-role-behavior';
           }
 
-          // For all roles that inherit permissions from 'authenticated user' role, add in dummy checkbox for authenticated role behavior.
-          // TODO: needs further testing
+          // For all roles that inherit permissions from 'authenticated user'
+          // role,add in dummy checkboxfor authenticated role behavior.
+          // TODO: needs further testing.
           if ($rid != 'anonymous' && $rid != 'authenticated') {
-            $checkbox['#suffix'] = $dummy_checkbox_output; // '#suffix' doesn't have wrapping HTML like '#field_suffix'.
+            // '#suffix' doesn't have wrapping HTML like '#field_suffix'.
+            $checkbox['#suffix'] = $dummy_checkbox_output;
           }
 
           // Add rid's to row attribute for checked status filter.
@@ -283,43 +318,43 @@ class FPAFormBuilder{
             $row[FPA_ATTR_NOT_CHECKED][] = $rid;
           }
 
-          $row['data'][] = array(
+          $row['data'][] = [
             'data' => $checkbox,
-            'class' => array(
+            'class' => [
               'checkbox',
-            ),
-            'title' => array(
+            ],
+            'title' => [
               $roles[$rid]->get('label'),
-            ),
-            // For role filter
-            FPA_ATTR_ROLE => array(
+            ],
+            // For role filter.
+            FPA_ATTR_ROLE => [
               $rid,
-            ),
-          );
+            ],
+          ];
         }
 
         if (!empty($rid)) {
-          $row['title'] = array(
+          $row['title'] = [
             $key,
-          );
+          ];
 
-          $row[FPA_ATTR_SYSTEM_NAME] = array(
+          $row[FPA_ATTR_SYSTEM_NAME] = [
             $key,
-          );
+          ];
         }
 
         // Mark current row with escaped permission name.
-        $row[FPA_ATTR_PERMISSION] = array(
+        $row[FPA_ATTR_PERMISSION] = [
           // Permission system name.
           0 => $permission_system_name,
           // Readable description.
           1 => $form['permissions'][$key]['description']['#context']['title']->render(),
-        );
+        ];
 
         // Mark current row with current module.
         $row[FPA_ATTR_MODULE] = $rows[$module][FPA_ATTR_MODULE];
 
-        $classes = array();
+        $classes = [];
         foreach ($row[FPA_ATTR_PERMISSION] as $item) {
           $classes[] = Html::getClass($item);
         }
@@ -337,15 +372,15 @@ class FPAFormBuilder{
       $rows[$i++] = $row;
     }
 
-    $reset_button = array(
+    $reset_button = [
       '#type' => 'html_tag',
       '#tag' => 'input',
-      '#attributes' => array(
+      '#attributes' => [
         'type' => 'reset',
         'class' => 'form-submit',
         'value' => t('Reset changes'),
-      ),
-    );
+      ],
+    ];
 
     // If there is no submit button, don't add the reset button.
     if (count(Element::children($form['actions'])) > 0) {
@@ -359,51 +394,53 @@ class FPAFormBuilder{
       $actions_output[] = $form['actions'][$key];
     }
 
-    $header = array();
+    $header = [];
 
-    $header[] = array(
+    $header[] = [
       'data' => [
         'label' => [
           '#type' => 'markup',
           '#markup' => t('Permission'),
         ],
-        'actions' => $actions_output
+        'actions' => $actions_output,
       ],
-    );
+    ];
 
     foreach ($form['role_names']['#value'] as $rid => $label) {
       hide($form['role_names']['#value'][$rid]);
 
-      $header[] = array(
+      $header[] = [
         'data' => [
           'label' => [
             '#type' => 'markup',
-            '#markup' => $label
+            '#markup' => $label,
           ],
-          'checkbox' => $nameless_checkbox
+          'checkbox' => $nameless_checkbox,
         ],
-        'class' => array(
+        'class' => [
           'checkbox',
-        ),
-        'title' => array(
+        ],
+        'title' => [
           $label,
-        ),
-        FPA_ATTR_ROLE => array(
+        ],
+        FPA_ATTR_ROLE => [
           $rid,
-        ),
-      );
+        ],
+      ];
       $user_roles[$rid] = $label;
     }
 
-    $table = array(
+    $table = [
       'header' => $header,
       'rows' => $rows,
-    );
+    ];
 
     $table_wrapper = static::buildTableWrapper($table, $modules, $user_roles, $actions_output);
 
     foreach (Element::children($form) as $key) {
-      if ($key == 'actions' || $key == 'permissions') continue;
+      if ($key == 'actions' || $key == 'permissions') {
+        continue;
+      }
       $table_wrapper[$key] = $form[$key];
     }
 
@@ -415,202 +452,213 @@ class FPAFormBuilder{
     return $form;
   }
 
+  /**
+   * Build table wrapper.
+   * @param $permissions_table
+   *   Permissions table.
+   * @param $modules
+   *   Array of modules.
+   * @param $user_roles
+   *   Array of user roles.
+   * @param $actions_output
+   *   Actions.
+   *
+   * @return array
+   *   Returns render array.
+   */
   protected static function buildTableWrapper($permissions_table, $modules, $user_roles, $actions_output) {
     $renderer = \Drupal::service('renderer');
 
-    // TODO: find out if there is a sf way to do this
+    // TODO: find out if there is a sf way to do this.
     $same_page = trim(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_PATH), '/') == $_GET['q'];
 
-    $render = array(
+    $render = [
       '#type' => 'container',
-      '#attributes' => array(
-        'class' => array(
+      '#attributes' => [
+        'class' => [
           'fpa-container',
-        ),
-      ),
-    );
+        ],
+      ],
+    ];
 
-    $hiders = array(
-      'fpa-hide-descriptions' => array(
+    $hiders = [
+      'fpa-hide-descriptions' => [
         'hide' => t('Hide descriptions'),
         'show' => t('Show descriptions'),
-      ),
-      'fpa-hide-system-names' => array(
+      ],
+      'fpa-hide-system-names' => [
         'hide' => t('Hide system names'),
         'show' => t('Show system names'),
-      ),
-    );
+      ],
+    ];
 
     $render['#attributes']['class'][] = 'fpa-hide-system-names';
 
-    $hide_container = array(
+    $hide_container = [
       '#type' => 'container',
-      '#attributes' => array(
-        'class' => array(
+      '#attributes' => [
+        'class' => [
           'fpa-toggle-container',
-        ),
-      ),
-    );
+        ],
+      ],
+    ];
 
     foreach ($hiders as $hide_class => $labels) {
-      $hide_container[$hide_class] = array(
+      $hide_container[$hide_class] = [
         '#theme' => 'link',
         '#text' => '',
         '#path' => '',
-        '#options' => array(
-          'attributes' => array_merge($labels, array(
+        '#options' => [
+          'attributes' => array_merge($labels, [
             'fpa-toggle-class' => $hide_class,
-          )),
+          ]),
           'html' => TRUE,
           'fragment' => ' ',
-          'external' => TRUE, // Prevent base path from being added to link.
-        ),
-      );
+          // Prevent base path from being added to link.
+          'external' => TRUE,
+        ],
+      ];
     }
 
     $render['hide_container'] = $hide_container;
 
-    $wrapper = array(
+    $wrapper = [
       '#type' => 'container',
-      '#attributes' => array(
-        'class' => array(
+      '#attributes' => [
+        'class' => [
           'fpa-wrapper',
-        ),
-      ),
-    );
+        ],
+      ],
+    ];
 
     $render['wrapper'] = &$wrapper;
 
 
-    /**
-     * <style /> block template.
-     */
-    $style_template = array(
+    // <style /> block template.
+    $style_template = [
       '#type' => 'container',
-      '#attributes' => array(
-        'class' => array(
-          'style-wrapper-class-name', // Override on specific block.
-        ),
-      ),
-    );
-
-    $style_template['style'] = array(
+      '#attributes' => [
+        'class' => [
+          // Override on specific block.
+          'style-wrapper-class-name',
+        ],
+      ],
+    ];
+
+    $style_template['style'] = [
       '#type' => 'html_tag',
       '#tag' => 'style',
-      '#attributes' => array(
-        'type' => array(
+      '#attributes' => [
+        'type' => [
           'text/css',
-        ),
-      ),
-      '#value' => '', // #value needed for closing tag.
-    );
+        ],
+      ],
+      // #value needed for closing tag.
+      '#value' => '',
+    ];
 
-    /**
-     * <style /> block for role filtering.
-     */
+    // <style /> block for role filtering.
     $wrapper['role_styles'] = $style_template;
     $wrapper['role_styles']['#attributes']['class'][0] = 'fpa-role-styles';
 
-    /**
-     * <style /> block for permission filtering.
-     */
+    // <style /> block for permission filtering.
     $wrapper['perm_styles'] = $style_template;
     $wrapper['perm_styles']['#attributes']['class'][0] = 'fpa-perm-styles';
 
-    /**
-     * Left section contains module list and form submission button.
-     */
-    $left_section = array(
+
+    // Left section contains module list and form submission button.
+    $left_section = [
       '#type' => 'container',
-      '#attributes' => array(
-        'class' => array(
+      '#attributes' => [
+        'class' => [
           'fpa-left-section',
-        ),
-      ),
-    );
+        ],
+      ],
+    ];
 
     $wrapper['left_section'] = &$left_section;
 
 
-    /**
-     * Right section contains filter form and permissions table.
-     */
-    $right_section = array(
+    // Right section contains filter form and permissions table.
+    $right_section = [
       '#type' => 'container',
-      '#attributes' => array(
-        'class' => array(
+      '#attributes' => [
+        'class' => [
           'fpa-right-section',
-        ),
-      ),
-    );
+        ],
+      ],
+    ];
 
     $wrapper['right_section'] = &$right_section;
 
-    $module_template = array(
-      '#wrapper_attributes' => array(
-        FPA_ATTR_MODULE => array(),
-        FPA_ATTR_PERMISSION => array()
-      ),
-      'data' => array(
+    $module_template = [
+      '#wrapper_attributes' => [
+        FPA_ATTR_MODULE => [],
+        FPA_ATTR_PERMISSION => [],
+      ],
+      'data' => [
         '#type' => 'container',
-        '#attributes' => array(),
+        '#attributes' => [],
 
         'link' => NULL,
 
-        'counters' => array(),
+        'counters' => [],
 
-        'total' => array(
+        'total' => [
           '#type' => 'html_tag',
           '#tag' => 'span',
-          '#attributes' => array(
-            'class' => array('fpa-perm-total'),
+          '#attributes' => [
+            'class' => ['fpa-perm-total'],
             'fpa-total' => 0,
-          ),
-          '#value' => '', // #value needed for closing tag.
-        ),
-      ),
-    );
+          ],
+          // #value needed for closing tag.
+          '#value' => '',
+        ],
+      ],
+    ];
 
-    $counter_template = array(
+    $counter_template = [
       '#type' => 'html_tag',
       '#tag' => 'span',
-      '#attributes' => array(
-        'class' => array('fpa-perm-counter'),
-        FPA_ATTR_PERMISSION => array(), // Counters only count permissions match.
-      ),
-      '#value' => '', // #value required for closing tag.
-    );
+      '#attributes' => [
+        'class' => ['fpa-perm-counter'],
+        // Counters only count permissions match.
+        FPA_ATTR_PERMISSION => [],
+      ],
+      // #value required for closing tag.
+      '#value' => '',
+    ];
 
-    $items = array();
+    $items = [];
 
-    $all_modules = array(
+    $all_modules = [
       'text' => t('All modules'),
-      FPA_ATTR_MODULE => array(),
-      FPA_ATTR_PERMISSION => array(),
-    );
+      FPA_ATTR_MODULE => [],
+      FPA_ATTR_PERMISSION => [],
+    ];
 
     array_unshift($modules, $all_modules);
 
-    $all_modules_counters = array();
+    $all_modules_counters = [];
 
     foreach ($modules as $module) {
 
       $module_item = $module_template;
 
       $module_item['#wrapper_attributes'][FPA_ATTR_MODULE] = $module[FPA_ATTR_MODULE];
-      $module_item['#wrapper_attributes'][FPA_ATTR_PERMISSION] = array_reduce($module[FPA_ATTR_PERMISSION], 'array_merge', array());
+      $module_item['#wrapper_attributes'][FPA_ATTR_PERMISSION] = array_reduce($module[FPA_ATTR_PERMISSION], 'array_merge', []);
 
       // Use link for accessibility and tabability.
-      $options = array(
+      $options = [
         'fragment' => 'all',
-      );
+      ];
 
       if (!empty($module['title'])) {
         $options['fragment'] = 'module-' . $module['title'][0];
         $options['attributes']['title'] = $module['title'][0];
       }
 
-      $module_item['data']['link'] = Link::createFromRoute($module['text'], 'user.admin_permissions', array(), $options)->toRenderable();
+      $module_item['data']['link'] = Link::createFromRoute($module['text'], 'user.admin_permissions', [], $options)->toRenderable();
 
       foreach ($module[FPA_ATTR_PERMISSION] as $module_perm) {
         $counter_item = $counter_template;
@@ -627,36 +675,36 @@ class FPAFormBuilder{
     $items[0]['data']['counters'] = $all_modules_counters;
     $items[0]['data']['total']['#attributes']['fpa-total'] = count($all_modules_counters);
 
-    $left_section['list'] = array(
+    $left_section['list'] = [
       '#items' => $items,
       '#theme' => 'item_list',
-    );
+    ];
 
     $left_section['buttons'] = $actions_output;
 
-    $filter_form = array(
+    $filter_form = [
       '#type' => 'container',
-      '#attributes' => array(
-        'class' => array(
+      '#attributes' => [
+        'class' => [
           'fpa-filter-form',
-        ),
-      ),
-    );
+        ],
+      ],
+    ];
 
-    $clear_button = array(
+    $clear_button = [
       '#type' => 'html_tag',
       '#tag' => 'input',
-      '#attributes' => array(
-        'type' => array(
+      '#attributes' => [
+        'type' => [
           'button',
-        ),
-        'class' => array(
+        ],
+        'class' => [
           'fpa-clear-search',
           'form-submit',
-        ),
+        ],
         'value' => 'Clear filter',
-      ),
-    );
+      ],
+    ];
 
     $default_filter = '';
 
@@ -669,43 +717,44 @@ class FPAFormBuilder{
     }
 
 
-    $filter_form['permission_module_filter'] = array(
+    $filter_form['permission_module_filter'] = [
       '#type' => 'textfield',
       '#title' => t('Filter:'),
       '#size' => 25,
       '#field_suffix' => $renderer->render($clear_button),
-      '#attributes' => array(
-        'placeholder' => array(
+      '#attributes' => [
+        'placeholder' => [
           'permission@module',
-        ),
+        ],
         'autofocus' => 'autofocus',
-      ),
+      ],
       '#value' => $default_filter,
       '#description' => t('<p>Enter in the format of "permission@module",</p><p>e.g. <em>admin@system</em> will show only permissions with the<br>text "admin" in modules with the text "system".</p><p>This will also match on system name of a permission.</p>'),
-    );
+    ];
 
     /*
      * Populate the permission filter styles.
      */
-    $matches = array();
+    $matches = [];
 
     preg_match('/^\s*([^@]*)@?(.*?)\s*$/i', $filter_form['permission_module_filter']['#value'], $matches);
 
-    array_shift($matches); // Remove whole match item.
+    // Remove whole match item.
+    array_shift($matches);
 
     $safe_matches = array();
-    foreach($matches as $match) {
+    foreach ($matches as $match) {
       $safe_matches[] = Html::getClass($match);
     }
 
     $module_match = !empty($_COOKIE['module_match']) ? $_COOKIE['module_match'] : '*=';
 
-    $filters = array(
+    $filters = [
       Unicode::strlen($safe_matches[0]) > 0 ? ('[' . FPA_ATTR_PERMISSION .               '*="' . $safe_matches[0] . '"]') : '',
       Unicode::strlen($safe_matches[1]) > 0 ? ('[' . FPA_ATTR_MODULE     . $module_match . '"' . $safe_matches[1] . '"]') : '',
-    );
+    ];
 
-    $filter_styles = array(
+    $filter_styles = [
       '.fpa-table-wrapper tr[' . FPA_ATTR_MODULE . ']{display: none;}',
 
       '.fpa-table-wrapper tr[' . FPA_ATTR_MODULE . ']',
@@ -723,49 +772,50 @@ class FPAFormBuilder{
       '.fpa-left-section li[' . FPA_ATTR_MODULE . ']',
       Unicode::strlen($filters[1]) > 0 ? $filters[1] : '[' . FPA_ATTR_MODULE . '=""]',
       '{margin-right:-1px; background-color: white; border-right: solid 1px transparent;}',
-    );
+    ];
 
     $wrapper['perm_styles']['style']['#value'] = implode('', $filter_styles);
 
 
-    $cookie_roles = (!empty($_COOKIE['fpa_roles']) && $same_page) ? json_decode($_COOKIE['fpa_roles']) : array();
+    $cookie_roles = (!empty($_COOKIE['fpa_roles']) && $same_page) ? json_decode($_COOKIE['fpa_roles']) : [];
 
-    $options = array(
+    $options = [
       '*' => t('--All Roles'),
-    );
+    ];
 
     if (!empty($user_roles)) {
-      $options += $user_roles; // Preserves keys.
+      // Preserves keys.
+      $options += $user_roles;
     }
 
     if (in_array('*', $cookie_roles)) {
-      $cookie_roles  = array('*');
+      $cookie_roles = ['*'];
     }
 
-    $filter_form['role_filter'] = array(
+    $filter_form['role_filter'] = [
       '#type' => 'select',
       '#title' => t('Roles:'),
       '#description' => t('Select which roles to display.<br>Ctrl+click to select multiple.'),
       '#size' => 5,
       '#options' => $options,
-      '#attributes' => array(
+      '#attributes' => [
         'multiple' => 'multiple',
-        'autocomplete' => 'off', // Keep browser from populating this from 'cached' input.
-      ),
-      '#value' => count(array_intersect($cookie_roles, array_keys($options))) > 0 ? $cookie_roles : array('*'),
-    );
+        // Keep browser from populating this from 'cached' input.
+        'autocomplete' => 'off',
+      ],
+      '#value' => count(array_intersect($cookie_roles, array_keys($options))) > 0 ? $cookie_roles : ['*'],
+    ];
 
     /*
      * Populate the roles styles.
      */
     if (!in_array('*', $filter_form['role_filter']['#value'])) {
 
-      $role_styles = array(
+      $role_styles = [
         '.fpa-table-wrapper [' . FPA_ATTR_ROLE . '] {display: none;}',
-      );
+      ];
 
       foreach ($filter_form['role_filter']['#value'] as $value) {
-
         $role_styles[] = '.fpa-table-wrapper [' . FPA_ATTR_ROLE . '="' . $value . '"] {display: table-cell;}';
       }
 
@@ -774,23 +824,23 @@ class FPAFormBuilder{
       $wrapper['role_styles']['style']['#value'] = implode('', $role_styles);
     }
 
-    $checked_status = array(
+    $checked_status = [
       '#type' => 'checkboxes',
       '#title' => t('Display permissions that are:'),
-      '#options' => array(
+      '#options' => [
         FPA_ATTR_CHECKED => t('Checked'),
         FPA_ATTR_NOT_CHECKED => t('Not Checked'),
-      ),
-      '#attributes' => array(),
+      ],
+      '#attributes' => [],
       '#title_display' => 'before',
       '#description' => t('Applies to all visible roles.<br />Unsaved changes are not counted.<br />Most effective when a single role is visible.<br />Empty module rows sometimes display when used with permission filter.'),
-    );
+    ];
 
     $checked_status_keys = array_keys($checked_status['#options']);
 
     $checked_status['#value'] = array_combine($checked_status_keys, $checked_status_keys);
 
-    $pseudo_form = array();
+    $pseudo_form = [];
     $filter_form['checked_status'] = Checkboxes::processCheckboxes($checked_status, new FormState(), $pseudo_form);
 
     foreach (Element::children($filter_form['checked_status']) as $key) {
@@ -799,35 +849,36 @@ class FPAFormBuilder{
 
     $right_section['filter_form'] = $filter_form;
 
-    $table_wrapper = array(
+    $table_wrapper = [
       '#type' => 'container',
-      '#attributes' => array(
-        'class' => array(
+      '#attributes' => [
+        'class' => [
           'fpa-table-wrapper',
-        ),
-      ),
-    );
+        ],
+      ],
+    ];
 
-    $table_wrapper['table'] = array(
+    $table_wrapper['table'] = [
       '#theme' => 'table',
       '#header' => $permissions_table['header'],
       '#rows' => $permissions_table['rows'],
-      '#attributes' => array(
+      '#attributes' => [
         'id' => 'permissions',
-      ),
-    );
+      ],
+    ];
 
-    // Show after full table HTML is loaded. Reduces progressive table load reflow/repaint.
-    $table_wrapper['show_table'] = array(
+    // Show after full table HTML is loaded.
+    // Reduces progressive table load reflow/repaint.
+    $table_wrapper['show_table'] = [
       '#type' => 'html_tag',
       '#tag' => 'style',
-      '#attributes' => array(
-        'type' => array(
+      '#attributes' => [
+        'type' => [
           'text/css',
-        ),
-      ),
+        ],
+      ],
       '#value' => '#permissions {display: table;} .fpa-table-wrapper {background: none;}',
-    );
+    ];
 
     $table_wrapper['buttons'] = $actions_output;
 
@@ -835,4 +886,5 @@ class FPAFormBuilder{
 
     return $render;
   }
-}
\ No newline at end of file
+
+}
diff --git a/src/Routing/RouteSubscriber.php b/src/Routing/RouteSubscriber.php
index 82d92b9..199803e 100644
--- a/src/Routing/RouteSubscriber.php
+++ b/src/Routing/RouteSubscriber.php
@@ -7,7 +7,6 @@
 
 namespace Drupal\fpa\Routing;
 
-
 use Drupal\Core\Routing\RouteSubscriberBase;
 use Symfony\Component\Routing\RouteCollection;
 
@@ -15,6 +14,7 @@ use Symfony\Component\Routing\RouteCollection;
  * Listens to the dynamic route events.
  */
 class RouteSubscriber extends RouteSubscriberBase {
+
   /**
    * {@inheritdoc}
    */
@@ -23,7 +23,7 @@ class RouteSubscriber extends RouteSubscriberBase {
     if ($route) {
       $route->setDefaults(array(
         '_title' => 'Permissions',
-        '_controller' => '\Drupal\fpa\Controller\FPAController::permissionsList'
+        '_controller' => '\Drupal\fpa\Controller\FPAController::permissionsList',
       ));
     }
   }
-- 
2.15.1

