Skip to content

Instantly share code, notes, and snippets.

View joaorobertopb's full-sized avatar
💻
Coding

João Roberto P. Borges joaorobertopb

💻
Coding
View GitHub Profile
@joaorobertopb
joaorobertopb / clean-code_avoid_negative_conditionals.php
Last active October 5, 2018 00:34
Evite condicionais negativos.
<?php
//Ruim
function shouldNotProccess() { //Não devo processar
// ...
}
if (!shouldNotProccess()) { // Devo processar?
// …
}
@joaorobertopb
joaorobertopb / clean-code_implicit_boolean.php
Created October 5, 2018 00:10
Utilize booleanos de forma implícita!
<?php
//Ruim
if (in_array(self::GRUPO_ADMINISTRADOR, $gruposAcesso)) {
return true;
}
return false;
//Bom
@joaorobertopb
joaorobertopb / clean-code_magic_numbers2.php
Created October 4, 2018 23:49
Sempre que possível utilize constantes para representar valores fixos! E evite os números mágicos dessa forma.
<?php
const GRUPO_ADMINISTRADOR = 10;
private function deveExecutar()
{
$gruposAcesso = explode(',',$_SESSION['GRUPOSACESSO']);
if (in_array(self::GRUPO_ADMINISTRADOR, $gruposAcesso)) {
return true;
@joaorobertopb
joaorobertopb / clean-code_magic_numbers1.php
Created October 4, 2018 23:47
Você sabe o que significa o número 10?! Então... Esse é um número "mágico" no meio do código...
<?php
private function deveExecutar()
{
$gruposAcesso = explode(',',$_SESSION['GRUPOSACESSO']);
if (in_array(10, $gruposAcesso)) {
return true;
}
@joaorobertopb
joaorobertopb / clean-code_names_example2.php
Created October 4, 2018 23:37
Use nomes passíveis de busca! A variável $e além de estar abreviada, não é passível de busca, pois a letra “e” sozinha, compõem diversos outros nomes...
<?php
try {
// Faz alguma coisa…
} catch (Exception $e) {
return $e->getMessage();
}
@joaorobertopb
joaorobertopb / clean-code_names_example1.php
Last active October 3, 2018 12:55
Clean Code concepts - PHP Examples
<?php
$ymd = date('Y-m-d'); // Ruim
$currentDate = date('Y-m-d'); // Bom
/* Ruim */ var $d = 0; //quantidade de dias trabalhados
/* Bom */ var $workDays = 0;
@joaorobertopb
joaorobertopb / gitVersion.php
Last active June 15, 2018 12:14
Get latest git tag version with PHP.
<?php
if (! function_exists('git_version')) {
/**
* Get latest git tag version.
*
* @return string
*/
function git_version()
{
@joaorobertopb
joaorobertopb / install-docker-ce-ubuntu-18.04.md
Last active December 18, 2018 16:16
Install docker on Ubuntu 18.04

Install docker - Ubuntu 18.04

sudo apt update

sudo apt install apt-transport-https ca-certificates curl software-properties-common

sudo gedit /etc/apt/sources.list.d/docker.list

copy this line: deb [arch=amd64] https://download.docker.com/linux/ubuntu artful stable save file!

@joaorobertopb
joaorobertopb / trecho-illuminate-model.php
Last active May 5, 2018 20:18
Exemplo de código utilizado em um dos meus artigos: medium.com/@joaorobertopb
<?php
//Trecho de código, retirado de https://github.com/laravel/framework/blob/5.6/src/Illuminate/Database/Eloquent/Model.php#L189
/**
* The "booting" method of the model.
*
* @return void
*/
protected static function boot()
@joaorobertopb
joaorobertopb / php_cs.dist
Created April 28, 2018 19:07
Tutorial PHP CS Fixer
<?php
$finder = PhpCsFixer\Finder::create()
->exclude('somedir')
->notPath('src/Symfony/Component/Translation/Tests/fixtures/resources.php')
->in(__DIR__);
return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,