This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class EstoqueProduto | |
{ | |
... | |
public function retirar($quantidade) { ... } | |
public function depositar($quantidade) { ... } | |
public function getValor() { ... } | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class EstoqueProduto | |
{ | |
... | |
public function retirar($quantidade) { ... } | |
public function depositar($quantidade) { ... } | |
public function getValor() { ... } | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Usando uma interface: | |
interface AssinaturaInterface | |
{ | |
public function isPremium(); | |
public function getValor(); | |
public function cobrar(CartaoCredito $cartao); | |
} | |
class Assinatura implements AssinaturaInterface { ... } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Endereço | |
class Endereco | |
{ | |
public function getDescricao() | |
{ | |
return implode(', ', [ | |
$this->logradouro, | |
$this->numero, | |
$this->bairro, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Endereco { ... } | |
class Autor { ... } | |
class Permissao { ... } | |
// se o endereço é null, o endereço é desconhecido: | |
class EnderecoDesconhecido { ... } | |
// se o autor é null, o autor é anônimo: | |
class AutorAnonimo { ... } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$loginUsuario = Maybe($usuario)->getLogin()->val('anônimo'); | |
// se $usuario é um objeto, $loginUsuario recebe o valor de getLogin() | |
// se $usuario é null, $loginUsuario recebe "anônimo" | |
// O código acima é equivalente a: | |
$loginUsuario = $usuario ? $usuario->getLogin() : 'anônimo'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Usuario | |
{ | |
public function cobrar() | |
{ | |
$this->assinatura->cobrar($this->getCartaoCredito()); // sem testar por null! | |
} | |
public function isPremium() | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AssinaturaGratuita extends Assinatura | |
{ | |
public function isPremium() | |
{ | |
return false; | |
} | |
public function getValor() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Usuario | |
{ | |
public function cobrar() | |
{ | |
// aqui | |
if (!empty($this->assinatura)) { | |
$this->assinatura->cobrar($this->getCartaoCredito()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
class UserException extends Exception { } | |
class Application | |
{ | |
... | |
public function getUser() : User |