diff --git a/composer.json b/composer.json index 829f952..5c89203 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ } ], "require": { - "php": ">=5.4.0" + "php": ">=7.1" }, "require-dev": { "phpmd/phpmd" : "~2.2", diff --git a/src/CallbackParameter.php b/src/CallbackParameter.php index a32bead..91647d7 100644 --- a/src/CallbackParameter.php +++ b/src/CallbackParameter.php @@ -2,6 +2,8 @@ namespace PHPFluent\Callback; +use ReflectionClass; +use ReflectionException; use ReflectionParameter; /** @@ -63,7 +65,7 @@ public function isOptional() */ public function isArray() { - return $this->reflection->isArray(); + return $this->reflection->getType() && $this->reflection->getType()->getName() === 'array'; } /** @@ -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()); } /** @@ -92,6 +95,7 @@ public function isObject() * @param mixed $value * * @return bool + * @throws ReflectionException */ public function isCompatible($value) { @@ -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; + } }