Skip to content

Commit

Permalink
Fixing bug where transformers would attempt to transform an array.
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Lewis <[email protected]>
  • Loading branch information
jasonlewis committed May 2, 2014
1 parent 423bec6 commit bb12cdf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function transform($class, $transformer)
/**
* Transform a response with a registered transformer.
*
* @param mixed $response
* @param string|object $response
* @return mixed
*/
public function transformResponse($response)
Expand Down Expand Up @@ -157,7 +157,7 @@ protected function resolveTransformer($transformer)
/**
* Get transformer from a class.
*
* @param mixed $class
* @param string|object $class
* @return string|\Closure
* @throws \RuntimeException
*/
Expand All @@ -181,11 +181,16 @@ protected function getTransformer($class)
/**
* Determine if a class has a transformer.
*
* @param mixed $class
* @param string|object $class
* @return bool
*/
protected function hasTransformer($class)
{
if ( ! is_object($class) and ! is_string($class))
{
return false;
}

$class = is_object($class) ? get_class($class) : $class;

return isset($this->transformers[$class]);
Expand Down
2 changes: 2 additions & 0 deletions tests/TransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function testRegisterTransformer()

public function testDeterminingIfResponseIsTransformable()
{
$this->assertFalse($this->transformer->transformableResponse(['foo' => 'bar']));
$this->assertFalse($this->transformer->transformableResponse(new stdClass));
$this->assertFalse($this->transformer->transformableResponse('Foo'));
$this->transformer->transform('Foo', 'Bar');
$this->assertTrue($this->transformer->transformableResponse('Foo'));
Expand Down

0 comments on commit bb12cdf

Please sign in to comment.