Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joaorobertopb/e183797c9d55e2829dfcf999f2a62557 to your computer and use it in GitHub Desktop.
Save joaorobertopb/e183797c9d55e2829dfcf999f2a62557 to your computer and use it in GitHub Desktop.
Evite o uso de flags como parâmetro! Porquê? porque o uso de flags indicam que essa função faz mais de uma coisa. Lembre-se, funções devem fazer apenas uma coisa!
<?php
//Ruim
function createFile(string $name, bool $temp = false): void
{
if ($temp) {
touch('./temp/'.$name);
} else {
touch($name);
}
}
//Bom
function createFile(string $name): void
{
touch($name);
}
function createTempFile(string $name): void
{
touch('./temp/'.$name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment