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

[CONTRIB-8128] Enforce coding guidelines for requiring namespaces for any new PHP files #26

Open
sarjona opened this issue Jan 15, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@sarjona
Copy link
Member

sarjona commented Jan 15, 2021

This is about to enforce the following policy decided recently (https://tracker.moodle.org/browse/MDLSITE-6087).

Policy: Require formal namespaces for any new PHP files
Since 19th June 2020, this rule applies:

  1. Formal namespaces are required for any new classes in Moodle. The following exceptions apply:
    1. there is no requirement to move existing non-namespaced classes to a namespace; and
    2. where an existing mechanism exists for loading a class, and that mechanism does not support the use of a namespaced class, the existing pseudo-namespaced prefix on the class name will be allowed.
  2. The use of a pseudo-namespace prefix on classnames is deprecated and should only be used in the above situations.
  3. The use of namespaces must conform to the following rules:
    1. Classes belonging to a namespace must be created in a classes directory inside a plugin (e.g. mod/forum/classes), or for core code, in lib/classes or subsystemdir/classes.
    2. The classname and filename for all namespaced classes must conform to the automatic class loading rules. The use of formal PHP namespaces in all new code is required.

Valid examples:

namespace mod_forum;
class example {
}
 
namespace mod_forum\external;
class example {
}
 
namespace core_user;
class example {
}

No longer valid:

class mod_forum_example {
}
 
class mod_forum_external_invalid {
}
 
class core_user_example {
}

This issue is about to verify these details in the codechecker. Nothing more, nothing less.


Reporter: Sara Arjona
Original issue: https://tracker.moodle.org/browse/CONTRIB-8128

@sarjona sarjona added the bug Something isn't working label Jan 15, 2021
@stronk7 stronk7 transferred this issue from moodlehq/moodle-local_codechecker Sep 21, 2022
@jrchamp
Copy link
Contributor

jrchamp commented Sep 18, 2023

This is detected in moodle-extra by PSR1.Classes.ClassDeclaration.MissingNamespace. Unfortunately, Moodle still expects certain classes to exist in the global namespace, such as mod_<modname>_mod_form and the {backup,restore}_<modname>_activity_task classes.

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

No branches or pull requests

2 participants