protected function makeNestedDataObject(string $class, $data, $key): DataObjectInterface
    {
        $data = ($data instanceof Arrayable) ? $data->toArray() : $data;

        if ( ! is_array($data)) {

            throw new UnexpectedValueException(
                "Cannot instantiate data object '{$class}' with non-array data for key '{$key}'"
                . (is_scalar($data) || is_object($data) && method_exists($data, '__toString')
                    ?   ' (data: ' . (string) $data . ')'
                    :   null)
            );
        }

        /** @var DataObjectInterface $data */
        return new $class($data);
    }
protected function makeNestedDataObject(string $class, $data, $key): DataObjectInterface
    {
        $data = ($data instanceof Arrayable) ? $data->toArray() : $data;

        if ( ! is_array($data)) {

            throw new UnexpectedValueException(
                "Cannot instantiate data object '{$class}' with non-array data for key '{$key}'"
                . (is_scalar($data) || is_object($data) && method_exists($data, '__toString')
                    ?   ' (data: ' . (string) $data . ')'
                    :   null)
            );
        }

        /** @var DataObjectInterface $data */
        return new $class($data);
    }
protected function makeNestedDataObject ( string $ class , $ data , $ key ) : DataObjectInterface { $ data = ( $ data instanceof Arrayable ) ? $ data -> toArray ( ) : $ data ; if ( ! is_array ( $ data ) ) { throw new UnexpectedValueException ( "Cannot instantiate data object '{$class}' with non-array data for key '{$key}'" . ( is_scalar ( $ data ) || is_object ( $ data ) && method_exists ( $ data , '__toString' ) ? ' (data: ' . ( string ) $ data . ')' : null ) ) ; } /** @var DataObjectInterface $data */ return new $ class ( $ data ) ; }
Makes a new nested data object for a given class and data.

@param string $class
@param mixed  $data
@param string $key
@return DataObjectInterface
Makes a new nested data object for a given class and data .