From 9110c6413e8aba8890432315465d7644a2a70182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20M=C3=A1rton?= Date: Mon, 4 Mar 2013 20:35:29 +0100 Subject: [PATCH] Minor code reorg to reduce duplication --- src/Composer/Command/ConfigCommand.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index 03f090231..3025742bc 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -248,20 +248,23 @@ EOT return $this->configSource->addConfigSetting('github-oauth.'.$matches[1], $values[0]); } + $booleanValidator = function ($val) { return in_array($val, array('true', 'false', '1', '0'), true); }; + $booleanNormalizer = function ($val) { return $val !== 'false' && (bool) $val; }; + // handle config values $uniqueConfigValues = array( 'process-timeout' => array('is_numeric', 'intval'), 'use-include-path' => array( - function ($val) { return in_array($val, array('true', 'false', '1', '0'), true); }, - function ($val) { return $val !== 'false' && (bool) $val; } + $booleanValidator, + $booleanNormalizer ), 'prefer-source' => array( - function ($val) { return in_array($val, array('true', 'false', '1', '0'), true); }, - function ($val) { return $val !== 'false' && (bool) $val; } + $booleanValidator, + $booleanNormalizer ), 'notify-on-install' => array( - function ($val) { return in_array($val, array('true', 'false', '1', '0'), true); }, - function ($val) { return $val !== 'false' && (bool) $val; } + $booleanValidator, + $booleanNormalizer ), 'vendor-dir' => array('is_string', function ($val) { return $val; }), 'bin-dir' => array('is_string', function ($val) { return $val; }),