Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
],
"require": {
"php": ">=5.4.0"
"php": ">=7.1"
},
"require-dev": {
"phpmd/phpmd" : "~2.2",
Expand Down
28 changes: 23 additions & 5 deletions src/CallbackParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace PHPFluent\Callback;

use ReflectionClass;
use ReflectionException;
use ReflectionParameter;

/**
Expand Down Expand Up @@ -63,7 +65,7 @@ public function isOptional()
*/
public function isArray()
{
return $this->reflection->isArray();
return $this->reflection->getType() && $this->reflection->getType()->getName() === 'array';
}

/**
Expand All @@ -73,17 +75,18 @@ public function isArray()
*/
public function isCallable()
{
return $this->reflection->isCallable();
return $this->reflection->getType() && $this->reflection->getType()->getName() === 'callable';
}

/**
* Returns if parameter requires an object or not.
*
* @return bool
* @throws ReflectionException
*/
public function isObject()
{
return (null !== $this->reflection->getClass());
return (null !== $this->getClass());
}

/**
Expand All @@ -92,6 +95,7 @@ public function isObject()
* @param mixed $value
*
* @return bool
* @throws ReflectionException
*/
public function isCompatible($value)
{
Expand All @@ -103,10 +107,24 @@ public function isCompatible($value)
return is_callable($value);
}

if ($this->isObject()) {
return (is_object($value) && $this->reflection->getClass()->isInstance($value));
$class = $this->getClass();
if ($this->isObject() && $class) {
return (is_object($value) && $class->isInstance($value));
}

return (!is_array($value) && !is_callable($value) && !is_object($value));
}

/**
* Returns Reflection class
*
* @return ReflectionClass
* @throws ReflectionException
*/
public function getClass()
{
return $this->reflection->getType() && !$this->reflection->getType()->isBuiltin()
? new ReflectionClass($this->reflection->getType()->getName())
: null;
}
}