Coder Social home page Coder Social logo

alumnforce / coding-conventions Goto Github PK

View Code? Open in Web Editor NEW
10.0 10.0 2.0 49 KB

[DEPRECATED] Style guide & coding conventions for AlumnForce projects

License: Creative Commons Attribution 4.0 International

code-style mysql naming-conventions php style-guide

coding-conventions's People

Contributors

geoffroy-aubry avatar jeanfrancois-mevia avatar mrdlef avatar nunomaduro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

coding-conventions's Issues

[Proposal] Avoid redundant Phpdocs and comments

This issue addresses the usage of comments/phpdocs.

comments/phpdocs should be avoided as much as possible by writing expressive code.

Don't use docblocks for methods that can be fully type hinted (unless you need a description).

Only add a description when it provides more context than the method/class signature itself. Use full sentences for descriptions, including a period at the end.

Part of this proposal was inspired in https://guidelines.spatie.be/code-style/laravel-php#docblocks


Class or interface headers:

Good:

<?php

namespace Stripe\Model\Configuration;

class Repository
{

Good:

/**
 * This class contains methods that give the information
 * about what env the application is working on.
 *
 * Usage:
 *     if ((new EnvironmentChecker())->inProduction()) {
 *         // Do your work knowing that you are in production
 *     } else {
 *         // Do your work knowing that you are in development
 *     }
 */
class EnvironmentChecker

Bad:

<?php

/*
 * This file is part of AlumnForce.
 *
 * (c) XXXXX <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Stripe\Model\Configuration;

/**
 * @category  Stripe
 * @package   Stripe
 * @author    Nuno Maduro <[email protected]>
 * @copyright 2016 Mevia
 * @license   http://alumnforce.org Private
 */
class Repository

Methods:

Good:

    /**
     * @return boolean <-- Good, if you can't use type-hints.
     */
    public function inProduction()
    {
        return APPLICATION_ENV === self::PRODUCTION;
    }

Good:

    public function inProduction(): boolean
    {
        return APPLICATION_ENV === self::PRODUCTION;
    }

Bad:

    /**
     * Checks if the application is in production. <-- The method name is already understandable.
     *
     * @return boolean
     */
    public function inProduction()
    {
        return APPLICATION_ENV === self::PRODUCTION;
    }

Bad:

    /**
     * @param $something // <-- No need for this since we have the type hint.
     *
     * @return boolean // <-- No need for this since we have the return hint.
     */
    public function inProduction(string $something): bool
    {
    }

Comments:

Good:

     // For single line comment.

    /**
     * Multiline comments
     * should use
     * this format
     */

Class attributes:

Good:

    /**
     * @var \Mevia\Tools\EnvironmentChecker // <-- If needed, fully qualified namespace always.
     */
    private $environmentChecker;

Good:

class CountryIsoTypeRepository implements CountryIsoTypeRepositoryContract
{
    private $app; // <-- No need for Phpdocs, the constructor is explicit.

    public function __construct(ApplicationContract $app)
    {
        $this->app = $app;
    }

Bad:

    /**
     * Holds an instance of the EnvironmentChecker. <-- No need for this.
     *
     * @var \Mevia\Tools\EnvironmentChecker
     */
    private $environmentChecker;

I think there is no need of going deeper on this proposal. You get the point. If something is not clear please write on the comments before voting.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.