src/Traits/CastsTrait.php
private function castToObject($value, $class)
    {
        if (!class_exists($class) || $value instanceof $class) {
            return $value;
        }

        $parentClasses = class_parents($class);

        if (in_array(Enum::class, $parentClasses) || in_array(AbstractObject::class, $parentClasses)) {
            return new $class($value);
        }

        if (in_array(Model::class, $parentClasses)) {
            return new $class($this->getClient(), $value);
        }

        if (in_array(ListObject::class, $parentClasses)) {
            return new $class($value);
        }

        return $value;
    }
private function castToObject($value, $class)
    {
        if (!class_exists($class) || $value instanceof $class) {
            return $value;
        }

        $parentClasses = class_parents($class);

        if (in_array(Enum::class, $parentClasses) || in_array(AbstractObject::class, $parentClasses)) {
            return new $class($value);
        }

        if (in_array(Model::class, $parentClasses)) {
            return new $class($this->getClient(), $value);
        }

        if (in_array(ListObject::class, $parentClasses)) {
            return new $class($value);
        }

        return $value;
    }
private function castToObject ( $ value , $ class ) { if ( ! class_exists ( $ class ) || $ value instanceof $ class ) { return $ value ; } $ parentClasses = class_parents ( $ class ) ; if ( in_array ( Enum :: class , $ parentClasses ) || in_array ( AbstractObject :: class , $ parentClasses ) ) { return new $ class ( $ value ) ; } if ( in_array ( Model :: class , $ parentClasses ) ) { return new $ class ( $ this -> getClient ( ) , $ value ) ; } if ( in_array ( ListObject :: class , $ parentClasses ) ) { return new $ class ( $ value ) ; } return $ value ; }
Casts value to the given class

@param $value
@param $class
@return mixed
Casts value to the given class