Skip to content

Commit

Permalink
[guzzle#169] Address Scrutinizer Code Feedback
Browse files Browse the repository at this point in the history
- Cleans-up logic that was working around `$this->filters` being empty.
- Fixes method visibility for `expandFilterArgs()`.
  • Loading branch information
Guy Elsmore-Paddock committed Aug 21, 2019
1 parent 8576ba1 commit a8ee4ca
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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.');
Expand All @@ -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);
}

Expand Down Expand Up @@ -532,7 +534,7 @@ public function isStatic()
*/
public function getFilters()
{
return $this->filters ?: [];
return $this->filters;
}

/**
Expand Down Expand Up @@ -650,6 +652,7 @@ public function getFormat()
private function setFilters(array $filters)
{
$this->filters = [];

foreach ($filters as $filter) {
$this->addFilter($filter);
}
Expand Down Expand Up @@ -686,11 +689,7 @@ private function addFilter($filter)
}
}

if (!$this->filters) {
$this->filters = [$filter];
} else {
$this->filters[] = $filter;
}
$this->filters[] = $filter;

return $this;
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a8ee4ca

Please sign in to comment.