-1

I have a group of Serializer classes that I want to put under a namespace. How would I call those classes and their filenames according to PSR?

Should I have:

/Serializer
    Markdown.php (class Markdown)
    Json.php (class Json)
    Html.php (class Html)
Vendor\Package\Serializer\Markdown

or

/Serializer
    MarkdownSerializer.php (class MarkdownSerializer)
    JsonSerializer.php (class JsonSerializer)
    HtmlSerializer.php (class HtmlSerializer)
Vendor\Package\Serializer\MarkdownSerializer
  • Should the namespace and folder name be plural, i.e. "Serializers"?

  • How should I capitalize JSON - JsonSerializer or JSONSerializer


I guess suffixing files with Serializer is better because if I have a base class Serializer.php that others extend, they would be called FooSerializer.php and it would make sense. Otherwise, if I have a base class, how would I call it? If I have Serializer.php and Markdown.php, nothing would indicate that one extends the other in any way.

dodov
  • 5,206
  • 3
  • 34
  • 65

1 Answers1

0
  • Suffixing classes: There is only a very general PSR Naming Convention.
  • Class suffixes are very common (in most cases). Example: MarkdownSerializer
  • PSR-1: Class names MUST be declared in StudlyCaps. For example: JsonSerializer
  • In practice the most namespaces and class names are singluar.
odan
  • 4,757
  • 5
  • 20
  • 49