style: update coding style with php-cs-fixer 3.46.0#8400
style: update coding style with php-cs-fixer 3.46.0#8400kenjis merged 17 commits intocodeigniter4:developfrom
Conversation
| try { | ||
| // ... | ||
| } catch (\Exception $e) { | ||
| } catch (Exception $e) { |
There was a problem hiding this comment.
Is it better to set leading_backslash_in_global_namespace to true for User Guide?
See https://cs.symfony.com/doc/rules/import/fully_qualified_strict_types.html
If we do so, the leading \ will not be removed, and if it is not in the current sample code it will be added.
There was a problem hiding this comment.
leading backlash has no effect when in global namespace, right? so adding it is superfluous.
There was a problem hiding this comment.
It has no effect in PHP syntax, but actually most code will be written in some namespace like App\Controllers,
So when there is no leading backslash, if a user copies and pastes the sample code, the code will not work unless they import the class.
Is it better that sample code should work as it is as possible when a dev copies and pastes?
There was a problem hiding this comment.
In such cases, it may be better to add namespaces for those files.
There was a problem hiding this comment.
IMO the code copied from the user guide should work out of the box. Less experienced users may not know they have to import the class. If there is a way to automatically add an import to our code examples then that would be fine. Otherwise, I would leave it as it is.
There was a problem hiding this comment.
the code copied from the user guide should work out of the box.
I agree with this.
import_symbols option imports symbols when the classname in the code is namespaced (containing \).
But Exception in the above sample is not imported.
2474290 to
eb88fd4
Compare
| } | ||
|
|
||
| $object = new Myclass(); | ||
| $object = new \Myclass(); |
There was a problem hiding this comment.
Where should we put this Myclass?
|
|
||
| // Call on an instance method | ||
| $user = new User(); | ||
| $user = new \User(); |
There was a problem hiding this comment.
Where should we put thisUser?
| final class AuthenticationFeatureTest extends CIUnitTestCase | ||
| { | ||
| use AuthTrait; | ||
| use \AuthTrait; |
There was a problem hiding this comment.
Where should we put this trait?
b0451da to
abb734c
Compare
The code copied from the user guide should work out of the box as possible.
c972f1e to
73cb246
Compare
Description
Checklist: