Skip to content

Adding PHP8 support #3

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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;
}
}