Assert\Assertion::isInstanceOf PHP Method

isInstanceOf() public static method

Assert that value is instance of given class-name.
public static isInstanceOf ( mixed $value, string $className, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$className string
$message string | null
$propertyPath string | null
return boolean
    public static function isInstanceOf($value, $className, $message = null, $propertyPath = null)
    {
        if (!$value instanceof $className) {
            $message = sprintf($message ?: 'Class "%s" was expected to be instanceof of "%s" but is not.', static::stringify($value), $className);
            throw static::createException($value, $message, static::INVALID_INSTANCE_OF, $propertyPath, array('class' => $className));
        }
        return true;
    }

Usage Example

 /**
  * @param $partId
  * @return \Modules\Parts\ReadModel\PartsThatWereManufactured
  */
 public function getReadModel($partId)
 {
     $partId = (string) $partId;
     $readModel = $this->repository->find($partId);
     Assertion::isInstanceOf($readModel, PartsThatWereManufactured::class);
     return $readModel;
 }
All Usage Examples Of Assert\Assertion::isInstanceOf