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 ContaGratuita extends Conta | |
| { | |
| public function cobrar($valor) | |
| { | |
| // não faz nada | |
| } | |
| } |
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 Autorizacao | |
| { | |
| public function autorizar(Usuario $usuario, $acao) | |
| { | |
| return true; | |
| } | |
| } | |
| class AutorizacaoApi extends Autorizacao |
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 | |
| if ($this->logger instanceof DatabaseLogger) { | |
| $this->logger->conectar(); | |
| } | |
| $this->logger->log('Fatura enviada com sucesso!'); |
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 T { ... } | |
| class S extends T { ... } | |
| $o1 = new S; | |
| $o2 = new T; | |
| // aceita tanto $o1 quanto $o2, | |
| // pois S é um sub-tipo de T | |
| function programaP(T $objeto) |
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 DatabaseLogger extends Logger | |
| { | |
| public function __construct(..., Database $database) | |
| { | |
| parent::__construct(...); | |
| $this->database = $database; | |
| if (!$this->database->isConnected()) { |
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 | |
| interface Arrayable | |
| { | |
| public function toArray(); | |
| } | |
| class Pedido implements Arrayable // implementa a interface | |
| { | |
| public function toArray() | |
| { |
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 | |
| abstract class Arrayable | |
| { | |
| abstract public function toArray(); | |
| } | |
| class Pedido extends Arrayable | |
| { | |
| public function toArray() | |
| { |
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 | |
| $impostometro = new Impostometro; | |
| $impostometro->somar($remedio); | |
| $impostometro->somar($cosmetico); | |
| $impostometro->somar($perfume); | |
| $impostometro->somar($aplicacaoInjecao); | |
| ... | |
| echo 'Nós pagamos $ ', $impostometro->getTotal(), ' em impostos!'; |
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 | |
| interface Tributavel | |
| { | |
| /** | |
| * Calcula o valor dos impostos que incidem sobre esta entidade. | |
| * @return float | |
| */ | |
| public function getValorImpostos(); | |
| } |
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 | |
| public function registrarItem($item) | |
| { | |
| if (!is_null($item)) { | |
| $itemRepository = $this->getItemRepository(); | |
| if (!is_null($itemRepository)) { | |
| $repository->persist($item); | |
| } | |
| } | |
| } |