fix: Call to a member function getErrors() on null in CheckQueryReturnTrait by kenjis · Pull Request #1088 · codeigniter4/shield · GitHub
Skip to content

fix: Call to a member function getErrors() on null in CheckQueryReturnTrait#1088

Merged
kenjis merged 2 commits into
codeigniter4:developfrom
kenjis:fix-CheckQueryReturnTrait-validation-error-CI45
Apr 8, 2024
Merged

fix: Call to a member function getErrors() on null in CheckQueryReturnTrait#1088
kenjis merged 2 commits into
codeigniter4:developfrom
kenjis:fix-CheckQueryReturnTrait-validation-error-CI45

Conversation

@kenjis

@kenjis kenjis commented Apr 8, 2024

Copy link
Copy Markdown
Member

Description
Fixes #1087

Since CI 4.5.0, $this->validation may be null.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@datamweb datamweb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@kenjis How about this?

    protected function checkValidationError(): void
    {
        $validationErrors = $this->validation?->getErrors();

        if ($validationErrors !== [] && $validationErrors !== null) {
            $message = 'Validation error:';

            foreach ($validationErrors as $field => $error) {
                $message .= ' [' . $field . '] ' . $error;
            }

            throw new ValidationException($message);
        }
    }

@kenjis kenjis force-pushed the fix-CheckQueryReturnTrait-validation-error-CI45 branch from 01d781b to 27a017d Compare April 8, 2024 11:22
@kenjis

kenjis commented Apr 8, 2024

Copy link
Copy Markdown
Member Author

@kenjis

kenjis commented Apr 8, 2024

Copy link
Copy Markdown
Member Author

$this->validation?->getErrors() requires PHP 8.0.
Shield still supports PHP 7.4.

"php": "^7.4.3 || ^8.0",

@kenjis kenjis force-pushed the fix-CheckQueryReturnTrait-validation-error-CI45 branch from bb27508 to 35bbb77 Compare April 8, 2024 12:25

@datamweb datamweb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, the code is more readable.

@kenjis kenjis merged commit cf646b8 into codeigniter4:develop Apr 8, 2024
@kenjis kenjis deleted the fix-CheckQueryReturnTrait-validation-error-CI45 branch April 8, 2024 12:35
@datamweb

Copy link
Copy Markdown
Collaborator

Wait for a new version of Shield to be released, or temporarily use the develop branch:

composer require codeigniter4/shield:dev-develop

@quickdunk

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: [CI 4.5.0] After registration/login, "Error: Call to a member function getErrors() on null"

3 participants