Skip to content
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

Handle a non-existent field in an array #136

Merged
merged 1 commit into from
Jul 11, 2016
Merged

Handle a non-existent field in an array #136

merged 1 commit into from
Jul 11, 2016

Conversation

hackel
Copy link
Contributor

@hackel hackel commented Jul 9, 2016

This was giving me an error, since I had several records for which a particular field was not defined. Since I use a schema-less DB (MongoDB), this field doesn't even exist with a null value. data_get performs an array_key_exists check before attempting to use $part as an index for the $res array.

This entire method could actually be replaced with data_get for simplicity, since this is what Laravel uses internally to retrieve values in dot notation.

protected function extractCellValue($fieldName)
{
    try {
        return data_get($this->src, $fieldName);
    } catch (Exception $e) {
        throw new RuntimeException(
            "Can't read '$fieldName' property from DataRow",
            0,
            $e
        );
    }
}

This was giving me an error, since I had several records for which a particular field was not defined.  Since I use a schema-less DB (MongoDB), this field doesn't even exist with a null value.  `data_get` performs an `array_key_exists` check before attempting to use `$part` as an index for the `$res` array.

This entire method could actually be replaced with data_get for simplicity, since this is what Laravel uses internally to retrieve values in dot notation.
```php
protected function extractCellValue($fieldName)
{
    try {
        return data_get($this->src, $fieldName);
    } catch (Exception $e) {
        throw new RuntimeException(
            "Can't read '$fieldName' property from DataRow",
            0,
            $e
        );
    }
}
```
@Nayjest
Copy link
Owner

Nayjest commented Jul 11, 2016

Hi!
Thanks for contribution, I will examine it today.

@Nayjest Nayjest merged commit 155d74f into Nayjest:master Jul 11, 2016
@Nayjest
Copy link
Owner

Nayjest commented Jul 11, 2016

Released in v1.3.0

@hackel hackel deleted the patch-3 branch July 15, 2016 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants