Namespaces

Verze:

07. 06. 2025

Zodpovědná osoba:

Dominik Šlechta

Namespace in PascalCase

  • Rule: Each namespace MUST be declared in PascalCase (also known as UpperCamelCase).

  • Reason: PascalCase is the convention in PHP for namespaces, helping to differentiate them from variables and functions. It enhances consistency and readability in the codebase.

Example (Correct):

namespace MyProject;
namespace MyProject\SubNamespace;

Example (Incorrect):

namespace myproject;
namespace myproject\subnamespace;

Top-Level Namespace

  • Rule: Each namespace MUST have a top-level namespace.

  • Reason: The top-level namespace serves as the root or primary namespace of your project, organizing all the other sub-namespaces under it.

Example (Correct):

namespace MyProject; 
namespace MyProject\SubNamespace;

Example (Incorrect):

namespace;
namespace \SubNamespace;

Sub-Namespace

  • Rule: Each namespace SHOULD have at least one sub-namespace.

  • Reason: Sub-namespaces help organize different components or modules of the project, ensuring better structure and maintainability.

Example (Correct):

namespace MyProject\SubNamespace;

Example (Incorrect):

namespace MyProject;