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

refactor: add PHPDoc types in RouteCollection #7129

Merged
merged 4 commits into from
Jan 21, 2023

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Jan 16, 2023

Description

  • add PHPDoc types
  • fix PHPDoc comment
  • refactor

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

@kenjis
Copy link
Member Author

kenjis commented Jan 16, 2023

Does anyone know why PHPStan reports this error?

 ------ --------------------------------------------------------------------- 
  Line   system/Router/RouteCollection.php                                    
 ------ --------------------------------------------------------------------- 
  1172   Offset 'filter' on array{filter?: array<int, string>|string,         
         namespace?: string, hostname?: string, subdomain?: string, offset?:  
         int, priority?: int} on left side of ?? always exists and is not     
         nullable.                                                            
 ------ --------------------------------------------------------------------- 

@paulbalandan
Copy link
Member

This should fix the error:

        $options = $this->loadRoutesOptions($verb);

        if (! array_key_exists($search, $options) || ! array_key_exists('filter', $options[$search])) {
            return [];
        }

        if (is_string($options[$search]['filter'])) {
            return [$options[$search]['filter']];
        }

        return $options[$search]['filter'];

@kenjis kenjis force-pushed the add-phpdoc-type-RouteCollection branch from a95ab84 to 945342c Compare January 16, 2023 08:58
@kenjis
Copy link
Member Author

kenjis commented Jan 16, 2023

@paulbalandan Nice!
At least $options[$search]['filter'] in if (is_string($options[$search]['filter'])) { may not exisit.

@kenjis kenjis changed the title docs: add PHPDoc types in RouteCollection refactor: add PHPDoc types in RouteCollection Jan 16, 2023
@kenjis kenjis added the refactor Pull requests that refactor code label Jan 16, 2023
@kenjis kenjis merged commit 74056b6 into codeigniter4:develop Jan 21, 2023
@kenjis kenjis deleted the add-phpdoc-type-RouteCollection branch January 21, 2023 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Pull requests that refactor code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants