Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed PHP Warning: Array to string conversion in src/ArrayRedactor.p… #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/ArrayRedactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct($content = [], array $keys = [], $ink = '[REDACTED]'
/**
* Provide the content to undergo redaction
*
* @param mixed array|string $content The content to redact (either array of json)
* @param mixed array|string $content The content to redact (either array of json)
* @return object \Mtownsend\ArrayRedactor\ArrayRedactor
*/
public function content($content = [])
Expand All @@ -60,7 +60,7 @@ public function content($content = [])
/**
* Set the keys to redact
*
* @param array $keys A non-associative array of keys that should be redacted in the content
* @param array $keys A non-associative array of keys that should be redacted in the content
* @return object \Mtownsend\ArrayRedactor\ArrayRedactor
*/
public function keys($keys = [])
Expand All @@ -72,7 +72,7 @@ public function keys($keys = [])
/**
* Set the value to replace redacted key values with
*
* @param mixed $ink What should replace the redacted data
* @param mixed $ink What should replace the redacted data
* @return object \Mtownsend\ArrayRedactor\ArrayRedactor
*/
public function ink($ink = '[REDACTED]')
Expand All @@ -93,7 +93,10 @@ public function redact()
}

if (!is_array($this->content) || !$this->isAssocArray($this->content)) {
throw new ArrayRedactorException("ArrayRedactor received invalid content `{$this->content}`");
throw new ArrayRedactorException(sprintf(
"ArrayRedactor received invalid content%s",
is_scalar($this->content) ? `{$this->content}` : ''
));
}

// Recursively traverse the array and redact the specified keys
Expand Down Expand Up @@ -129,7 +132,7 @@ public function __invoke()
/**
* Determine if the given array is associative or non-associative
*
* @param array $array
* @param array $array
* @return boolean
*/
protected function isAssocArray(array $array)
Expand All @@ -141,7 +144,7 @@ protected function isAssocArray(array $array)
/**
* Check if the string received is valid json
*
* @param string $string Assumed json string
* @param string $string Assumed json string
* @return boolean
*/
protected function isValidJson($string)
Expand Down