genkgo / mail

Library to send e-mails over different transports and protocols (like SMTP and IMAP) using immutable messages and streams. Also includes SMTP server.
https://mail.readthedocs.io/
Other
402 stars 21 forks source link

Implement PHP-CS-Fixer code style rule-set #33

Closed GwendolenLynch closed 6 years ago

GwendolenLynch commented 6 years ago

Changes

Use case

Usage

As discussed, once fully implemented this will allow a developer to not have to focus at all on code style, while maintaining a consistent base for future contribution.

Fixes to code style can be performed in one of two ways.

As a composer script that runs across all files:

composer lint

Running directly to update a single file (or directory):

vendor/bin/php-cs-fixer fix --verbose src/ClassFile.php

Ruleset

This is the part that almost certainly makes this PR a work in progress.

I have based this on Symfony's standards, as it seemed closest to what was in use now. I have no firm opinion either way, as long as there is a reference point, I'll just run the fixer and comply with what is desired :smile:

Notable results:

Points for further discussion:

PHP 7, and especially post-7.1, remove the need & use of a lot of PHPDoc. For example:

    /**
     * ClientFactory constructor.
     *
     * @param ConnectionInterface $connection
     */
    public function __construct(ConnectionInterface $connection) {}

    /**
     * @param int    $method
     * @param string $password
     * @param string $username
     *
     * @return ClientFactory
     */
    public function withAuthentication(int $method, string $username, string $password): self {}

All parameters are type-hinted, and visually and IDE recognisable without PHPDoc. Removing those lowers maintenance overhead on both developers and contributors as the code base grows and evolves.

The obvious exception is where a mixed variable is expected, at which point that should be expected to be defined by an @param entry. Obviously mixed data variables are highly undesirable anyway, so well maintained code … well, the point should appear :wink:

NOTE: If this is considered desirable, it should be carried out prior to using the CS fixer to create an updated branch.

frederikbosch commented 6 years ago

See #46.