From 70b50c108e40ddaab1a75b18523089d127299f2a Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Mon, 12 May 2014 17:07:20 +0100 Subject: [PATCH] Reducing complexity of PhpCodeSniffer::__construct() - see #386 --- PHPCI/Plugin/PhpCodeSniffer.php | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/PHPCI/Plugin/PhpCodeSniffer.php b/PHPCI/Plugin/PhpCodeSniffer.php index 7c7f81e0..827e783c 100755 --- a/PHPCI/Plugin/PhpCodeSniffer.php +++ b/PHPCI/Plugin/PhpCodeSniffer.php @@ -109,14 +109,6 @@ class PhpCodeSniffer implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin $this->suffixes = (array)$options['suffixes']; } - if (isset($options['directory'])) { - $this->directory = $options['directory']; - } - - if (isset($options['standard'])) { - $this->standard = $options['standard']; - } - if (!empty($options['tab_width'])) { $this->tab_width = ' --tab-width='.$options['tab_width']; } @@ -125,20 +117,15 @@ class PhpCodeSniffer implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin $this->encoding = ' --encoding=' . $options['encoding']; } - if (isset($options['path'])) { - $this->path = $options['path']; - } + $this->setOptions($options); + } - if (isset($options['ignore'])) { - $this->ignore = $options['ignore']; - } - - if (isset($options['allowed_warnings'])) { - $this->allowed_warnings = (int)$options['allowed_warnings']; - } - - if (isset($options['allowed_errors'])) { - $this->allowed_errors = (int)$options['allowed_errors']; + protected function setOptions($options) + { + foreach (array('directory', 'standard', 'path', 'ignore', 'allowed_warnings', 'allowed_errors') as $key) { + if (array_key_exists($key, $options)) { + $this->{$key} = $options[$key]; + } } }