From a8ee4ca8801ef981e590290fcb52ebcdd3cab8d9 Mon Sep 17 00:00:00 2001 From: Guy Elsmore-Paddock Date: Tue, 20 Aug 2019 23:05:03 -0700 Subject: [PATCH] [#169] Address Scrutinizer Code Feedback - Cleans-up logic that was working around `$this->filters` being empty. - Fixes method visibility for `expandFilterArgs()`. --- src/Parameter.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Parameter.php b/src/Parameter.php index d7b32d4b..03edf160 100644 --- a/src/Parameter.php +++ b/src/Parameter.php @@ -256,7 +256,9 @@ public function __construct(array $data = [], array $options = []) $this->required = (bool) $this->required; $this->data = (array) $this->data; - if ($this->filters) { + if (empty($this->filters)) { + $this->filters = []; + } else { $this->setFilters((array) $this->filters); } @@ -320,7 +322,7 @@ public function filter($value, $stage = null) } // Formats are applied exclusively and supercede filters - if ($this->format) { + if (!empty($this->format)) { if (!$this->serviceDescription) { throw new \RuntimeException('No service description was set so ' . 'the value cannot be formatted.'); @@ -334,7 +336,7 @@ public function filter($value, $stage = null) } // Apply filters to the value - if ($this->filters) { + if (!empty($this->filters)) { $value = $this->invokeCustomFilters($value, $stage); } @@ -532,7 +534,7 @@ public function isStatic() */ public function getFilters() { - return $this->filters ?: []; + return $this->filters; } /** @@ -650,6 +652,7 @@ public function getFormat() private function setFilters(array $filters) { $this->filters = []; + foreach ($filters as $filter) { $this->addFilter($filter); } @@ -686,11 +689,7 @@ private function addFilter($filter) } } - if (!$this->filters) { - $this->filters = [$filter]; - } else { - $this->filters[] = $filter; - } + $this->filters[] = $filter; return $this; } @@ -792,7 +791,7 @@ private function invokeComplexFilter(array $filter, $value, $stage) { * * @return array The array of arguments, with all placeholders replaced. */ - function expandFilterArgs(array $filterArgs, $value, $stage) { + private function expandFilterArgs(array $filterArgs, $value, $stage) { $replacements = [ '@value' => $value, '@api' => $this,