Skip to content

refactor: use ::class to config() param - #7611

Merged
kenjis merged 1 commit into
codeigniter4:developfrom
kenjis:refactor-config-classname
Jun 26, 2023
Merged

refactor: use ::class to config() param#7611
kenjis merged 1 commit into
codeigniter4:developfrom
kenjis:refactor-config-classname

Conversation

@kenjis

@kenjis kenjis commented Jun 24, 2023

Copy link
Copy Markdown
Member

Description
::class keyword is better than string for IDE or static analysis.

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 kenjis added the refactor Pull requests that refactor code label Jun 24, 2023

@TimexPeachtree TimexPeachtree left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code looks great for refactor more concise.
want to check if this has going to be in a major update 4.4.x or within 4.3.x

@kenjis

kenjis commented Jun 24, 2023

Copy link
Copy Markdown
Member Author

develop means 4.3.x now.

@mostafakhudair

Copy link
Copy Markdown
Contributor

Why should the framework care about the IDE?
::class means more code line.

@datamweb

Copy link
Copy Markdown
Contributor

Why should the framework care about the IDE?

Because it guides the developers. and provides more details when programming.

@kenjis

kenjis commented Jun 25, 2023

Copy link
Copy Markdown
Member Author
  1. If we use ::class, IDE can navigate us to the Config property.
    Screenshot 2023-06-26 7 34 28

  2. When we use ::class, IDE can autocomplete the classname.
    Screenshot 2023-06-26 7 37 53

@kenjis

kenjis commented Jun 25, 2023

Copy link
Copy Markdown
Member Author

::class means more code line.

If you mean use statements like use Config\Exceptions;,
I think it is better to write all use statements for all dependencies.
Then all classes on which this class depends will be visible.
Too many usesstatements mean too many dependencies, which may be an issue in class design.

config('classname') hides the dependency.

And if you use IDE, the use statement will be added automatically.

@kenjis
kenjis merged commit 3bb0831 into codeigniter4:develop Jun 26, 2023
@kenjis
kenjis deleted the refactor-config-classname branch June 26, 2023 00:35
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.

5 participants