diff --git a/en/contributing/cakephp-coding-conventions.rst b/en/contributing/cakephp-coding-conventions.rst index 4b764eff17..3f04fb3283 100644 --- a/en/contributing/cakephp-coding-conventions.rst +++ b/en/contributing/cakephp-coding-conventions.rst @@ -569,6 +569,17 @@ underscore character, for example:: define('LONG_NAMED_CONSTANT', 2); +Enums +----- + +Enum cases are defined in ``CamelCase`` style:: + + enum ArticleStatus: string + { + case Published = 'Y'; + case NotPublishedYet = 'N'; + } + Careful when using empty()/isset() ================================== diff --git a/en/intro/conventions.rst b/en/intro/conventions.rst index a2bf72cee2..7a98cf25c2 100644 --- a/en/intro/conventions.rst +++ b/en/intro/conventions.rst @@ -114,6 +114,10 @@ Entity class names are singular CamelCased and have no suffix. ``User``, matching the ``users``, ``menu_links`` and ``user_favorite_pages`` tables respectively. +Enum class names should use a ``{Entity}{Column}`` convention, and enum cases +should use CamelCased names. + + View Conventions ================ diff --git a/en/orm/database-basics.rst b/en/orm/database-basics.rst index 7ccd4b4d73..402f9ecd8b 100644 --- a/en/orm/database-basics.rst +++ b/en/orm/database-basics.rst @@ -479,10 +479,16 @@ Where ``ArticleStatus`` contains something like:: enum ArticleStatus: string { - case PUBLISHED = 'Y'; - case UNPUBLISHED = 'N'; + case Published = 'Y'; + case Unpublished = 'N'; } +CakePHP recommends a few conventions for enums: + +- Enum classnames should follow ``{Entity}{ColumnName}`` style to enable + detection while running bake and to aid with project consistency. +- Enum cases should use CamelCase style. + .. _adding-custom-database-types: Adding Custom Types