You are here

protected function CssLintForm::decodeRules in Advanced CSS/JS Aggregation 8.3

Same name and namespace in other branches
  1. 8.4 advagg_validator/src/Form/CssLintForm.php \Drupal\advagg_validator\Form\CssLintForm::decodeRules()

Decode a .csslintrc file to rules array.

Parameters

string $rule_string: The raw rule string.

Return value

array The rules array.

1 call to CssLintForm::decodeRules()
CssLintForm::buildForm in advagg_validator/src/Form/CssLintForm.php
Form constructor.

File

advagg_validator/src/Form/CssLintForm.php, line 54

Class

CssLintForm
Configure form for CSSHint validation of CSS files.

Namespace

Drupal\advagg_validator\Form

Code

protected function decodeRules($rule_string) {
  $values = [
    'errors' => 2,
    'warning' => 1,
    'ignore' => 0,
    'exclude-list' => 1,
  ];
  $rules = [];
  $group = '';
  $raw = explode("\n", $rule_string);
  foreach ($raw as $rule) {
    if (empty($rule)) {
      continue;
    }
    if (substr($rule, 0, 1) === '-') {
      $split = explode('=', trim($rule, " \t\n\r\0\v-,"));
      $group = $split[0];
      $rules[$group] = [];
      if (isset($split[1])) {
        $rules[$group][$split[1]] = $values[$group];
      }
      continue;
    }
    $rules[$group][trim($rule, " \t\n\r\0\v,")] = $values[$group];
  }
  return $rules;
}