diff --git a/.codeclimate.yml b/.codeclimate.yml index 4bd9ecf83..0a0eaa203 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -3,10 +3,32 @@ version: "2" checks: file-lines: enabled: false - method-complexity: - enabled: true + argument-count: + config: + threshold: 4 + complex-logic: + config: + threshold: 4 + file-lines: config: threshold: 250 + method-complexity: + config: + threshold: 250 + method-count: + config: + threshold: 250 + method-lines: + config: + threshold: 500 + nested-control-flow: + config: + threshold: 4 + return-statements: + config: + threshold: 4 + similar-code: + enabled: false plugins: csslint: enabled: false diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index 34182e8d2..04981eeda 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -2417,18 +2417,48 @@ class e_form return false; } - $snippet = THEME."snippets/form_".$type.".html"; + $regId = 'core/form/snippet/'.$type; - if(!file_exists($snippet)) + if($snippet = e107::getRegistry($regId)) + { + return $snippet; + } + + $snippetPath = THEME."snippets/form_".$type.".html"; + + if(!file_exists($snippetPath)) { return false; } - return file_get_contents($snippet, false, null, 0, 1024); + $content = file_get_contents($snippetPath, false, null, 0, 1024); + + e107::setRegistry($regId, $content); + + return $content; } + private function renderSnippet($snippet, $options, $name, $value) + { + $snip = $options; + if(!empty($options['class'])) + { + $snip['class'] = trim($options['class']); + unset($options['class']); + } + + $snip['attributes'] = $this->get_attributes($options, $name, $value); + + foreach($snip as $k=>$v) + { + $search[] = '{'.$k.'}'; + } + + return str_replace($search, array_values($snip), $snippet); + + } /** * Render a checkbox @@ -2487,35 +2517,15 @@ class e_form $options['class'] .= ' form-check-input'; - if($text = $this->getSnippet('checkbox')) + if($snippet = $this->getSnippet('checkbox')) { - // todo move all this to its own method. eg. renderSnippet() - $snip = $options; - $snip['name'] = $name; - $snip['value'] = $value; - $snip['attributes'] = $this->get_attributes($options, $name, $value); - $snip['readonly'] = $this->get_attributes(['readonly'=> $options['readonly']]); - $snip['checked'] = $this->get_attributes(['checked'=> $options['checked']]); - $snip['active'] = trim($active); - $snip['class'] = trim($options['class']); - $snip['id'] = $this->_format_id($options['id'], $name, $value, null); - - foreach($snip as $k=>$v) - { - $search[] = '{'.$k.'}'; - } - - return str_replace($search, array_values($snip), $text); + return $this->renderSnippet($snippet, $options, $name, $value); } - $pre = (!empty($options['label'])) ? "" : ""; unset($options['label']); // not to be used as attribute; - - - return $pre. "get_attributes($options, $name, $value)." />".$post; diff --git a/e107_tests/tests/unit/e_formTest.php b/e107_tests/tests/unit/e_formTest.php index a1609deb2..d77312d5d 100644 --- a/e107_tests/tests/unit/e_formTest.php +++ b/e107_tests/tests/unit/e_formTest.php @@ -1148,7 +1148,7 @@ class e_formTest extends \Codeception\Test\Unit $result = $this->_frm->checkbox('myname', 3, true, ['readonly'=>true]); $expected = ""; diff --git a/e107_themes/bootstrap3/snippets/form_checkbox.html b/e107_themes/bootstrap3/snippets/form_checkbox.html index 047e6c1c2..dadea820a 100644 --- a/e107_themes/bootstrap3/snippets/form_checkbox.html +++ b/e107_themes/bootstrap3/snippets/form_checkbox.html @@ -1,4 +1,4 @@ \ No newline at end of file