From 6d967d3f043317be88ba6ecf5f01f4eaa699ec6e Mon Sep 17 00:00:00 2001 From: Bertrand Drouhard Date: Fri, 27 Oct 2017 08:59:08 +0000 Subject: [PATCH 1/4] Explicit error message in the Mapper for keyExists function --- Configurability/ConfigurableServiceHelper.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Configurability/ConfigurableServiceHelper.php b/Configurability/ConfigurableServiceHelper.php index 560f846a..e19b2add 100644 --- a/Configurability/ConfigurableServiceHelper.php +++ b/Configurability/ConfigurableServiceHelper.php @@ -30,7 +30,7 @@ class ConfigurableServiceHelper const CONF_MESSAGE = 'message'; const CONF_RECOVERABLE = 'recoverable'; - const CONF_NO_RESULTS = 'noResults'; + const CONF_NO_RESULTS = 'no_results'; const STEP_DEFINE = 'define'; const STEP_VALIDATE = 'validate'; @@ -96,11 +96,13 @@ public function createContext(array $options, MessageInterface $message = null, return $context; } - public function resolveArray($input, &$context){ + public function resolveArray($input, &$context) + { $output = []; - foreach($input as $key => $value){ - $output[$key] = $this->resolve($value,$context); + foreach ($input as $key => $value) { + $output[$key] = $this->resolve($value, $context); } + return $output; } @@ -163,6 +165,7 @@ public function executeStep($stepAction, &$stepActionParams, &$options, array &$ break; case self::STEP_VALIDATE: $this->validate($stepActionParams, $context); + return true; break; default: @@ -196,7 +199,6 @@ public function define(array $definitions, array &$context) public function validate(array $stepConfig, array &$context) { - $config = $this->validateResolver->resolve($stepConfig); $rule = $config[self::CONF_RULE]; @@ -206,7 +208,7 @@ public function validate(array $stepConfig, array &$context) $display_message = $config[self::CONF_DISPLAY_MESSAGE]; $evaluation = $this->resolve($rule, $context); - if ($evaluation !== true) { + if (true !== $evaluation) { $message = $this->resolve($message, $context); if ($no_results) { throw new NoResultsException($message); From 86b2b3b7a3661bb67fde9f31ea026721ffce0d4d Mon Sep 17 00:00:00 2001 From: Bertrand Drouhard Date: Fri, 27 Oct 2017 09:01:30 +0000 Subject: [PATCH 2/4] Unify parameter name for no_results instead of noResults --- Tools/Mapper/Mapper.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Tools/Mapper/Mapper.php b/Tools/Mapper/Mapper.php index 810b43c6..3ce4922c 100644 --- a/Tools/Mapper/Mapper.php +++ b/Tools/Mapper/Mapper.php @@ -42,7 +42,7 @@ public function addMappings(array $mappings) */ public function formatDate($format, \DateTime $date = null) { - if ($date === null) { + if (null === $date) { return null; } @@ -87,7 +87,7 @@ public function resolve(&$mapping, &$obj, &$context) foreach ($mapping as $key => $value) { $resolved = $this->resolve($value, $obj, $context); - if ($resolved !== null) { + if (null !== $resolved) { $res[$key] = $resolved; } } @@ -146,6 +146,10 @@ public function mapAll($elements, $mappingName, $context = []) */ public function keyExists(array $obj, $key) { + if (!is_string($key) and !is_integer($key)) { + throw new \RuntimeException('keyExists expected either a string or an integer, \''.print_r($key, true).'\' was given.'); + } + return array_key_exists($key, $obj); } @@ -302,11 +306,11 @@ public function serializeWithGroup($data, $format, $group) } /** - * Return the n-th section of the given string splitted by piece of the given length + * Return the n-th section of the given string splitted by piece of the given length. * * @param string $string - * @param int $length - * @param int $section + * @param int $length + * @param int $section * * @return string */ @@ -320,6 +324,7 @@ public function wordWrap($string, $length, $section) if (isset($lines[$section])) { $result = $lines[$section]; } + return $result; } From 6c1a29b3d0d24cb2342f84034f5688fd75d458e1 Mon Sep 17 00:00:00 2001 From: Bertrand Drouhard Date: Mon, 6 Nov 2017 16:38:05 +0000 Subject: [PATCH 3/4] Split pull request to keep only unify parameter name for no_results --- Tools/Mapper/Mapper.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Tools/Mapper/Mapper.php b/Tools/Mapper/Mapper.php index 3ce4922c..a0bf0a6e 100644 --- a/Tools/Mapper/Mapper.php +++ b/Tools/Mapper/Mapper.php @@ -146,10 +146,6 @@ public function mapAll($elements, $mappingName, $context = []) */ public function keyExists(array $obj, $key) { - if (!is_string($key) and !is_integer($key)) { - throw new \RuntimeException('keyExists expected either a string or an integer, \''.print_r($key, true).'\' was given.'); - } - return array_key_exists($key, $obj); } From e046dfe75d84427778c6fd2c09989ed7d30b9cac Mon Sep 17 00:00:00 2001 From: Bertrand Drouhard Date: Mon, 6 Nov 2017 16:41:03 +0000 Subject: [PATCH 4/4] Replace Mapper.php with previous version --- Tools/Mapper/Mapper.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Tools/Mapper/Mapper.php b/Tools/Mapper/Mapper.php index a0bf0a6e..810b43c6 100644 --- a/Tools/Mapper/Mapper.php +++ b/Tools/Mapper/Mapper.php @@ -42,7 +42,7 @@ public function addMappings(array $mappings) */ public function formatDate($format, \DateTime $date = null) { - if (null === $date) { + if ($date === null) { return null; } @@ -87,7 +87,7 @@ public function resolve(&$mapping, &$obj, &$context) foreach ($mapping as $key => $value) { $resolved = $this->resolve($value, $obj, $context); - if (null !== $resolved) { + if ($resolved !== null) { $res[$key] = $resolved; } } @@ -302,11 +302,11 @@ public function serializeWithGroup($data, $format, $group) } /** - * Return the n-th section of the given string splitted by piece of the given length. + * Return the n-th section of the given string splitted by piece of the given length * * @param string $string - * @param int $length - * @param int $section + * @param int $length + * @param int $section * * @return string */ @@ -320,7 +320,6 @@ public function wordWrap($string, $length, $section) if (isset($lines[$section])) { $result = $lines[$section]; } - return $result; }