alumnforce / coding-conventions Goto Github PK
View Code? Open in Web Editor NEW[DEPRECATED] Style guide & coding conventions for AlumnForce projects
License: Creative Commons Attribution 4.0 International
[DEPRECATED] Style guide & coding conventions for AlumnForce projects
License: Creative Commons Attribution 4.0 International
We need to add coding standards for JavaScript, Twig, Less and those I may be miss.
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
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
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
{
}
Good:
// For single line comment.
/**
* Multiline comments
* should use
* this format
*/
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.