Skip to content

Conversation

@ianitsky
Copy link

@ianitsky ianitsky commented Mar 7, 2017

ContextErrorException: Notice: Undefined index: CURLOPT_HTTPHEADER

Fixes #45

$idColumns = !empty($meta) ? end($meta)->getIdentifierColumnNames() : [];

return !empty($idColumns) ? end($idColumns) : 'id';
if (empty($idColumns)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all: Thank you for contributing! And sorry for being that late.

In general your bugfix is a good one. But we just need to clean up the code a bit. If you had a look at the rest of the code we tried...
... not to mutate existing variables and
... not to create/mutate variables in a branch

Example:

    if($x) {
        $var = 'value';
    } else {
        $var = 'anotherValue';
    }

turns to

$var = $x ? 'value' : 'anotherValue';

The idea is to use conditions as statements instead of expressions to ensure we don't generate side effects.

So what we need here is something like:

    if(!empty($idColumns)) return end($idColumns);

    $reservedTokens = array_filter($tokens['SELECT'], function($token) {
        return $token['expr'] === 'reserved';
    });

    $finalTokens = count($reservedTokens) > 0 ? $reservedTokens : $tokens;

    return end($finalTokens[0]['no_quotes']['parts']);

Maybe I missed a detail, but I hope it helps you to understand what I want to change here.
May you be so kind and change these few lines so I can merge the PR?

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