Skip to content

Commit

Permalink
[BUGFIX] Prevent null-check on get_class occurrence
Browse files Browse the repository at this point in the history
Since PHP's get_class() has the unlucky ability to pass null
(resp. nothing) as argument and considers the calling class
in this case which leads to side effects; and PHP 7.2 doesn't
allow null values at all anymore; this change fixes a case
where this might happen as of the interface since a null
object can be passed.
  • Loading branch information
Adrian Föder authored and dbu committed Dec 1, 2017
1 parent 10e49f6 commit 9430bc8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion PublishWorkflow/Voter/PublishableVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function supportsClass($class)
*/
public function vote(TokenInterface $token, $object, array $attributes)
{
if (!$this->supportsClass(get_class($object))) {
if ($object === null || !$this->supportsClass(get_class($object))) {
return self::ACCESS_ABSTAIN;
}

Expand Down
10 changes: 10 additions & 0 deletions Tests/Unit/PublishWorkflow/Voter/PublishableVoterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,14 @@ public function testUnsupportedClass()
);
$this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $result);
}

public function testNullObject()
{
$result = $this->voter->vote(
$this->token,
null,
array()
);
$this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $result);
}
}

0 comments on commit 9430bc8

Please sign in to comment.