<?php
namespace Alura\Banco\Modelo;
/**
* Class Endereco
* @package Alura\Banco\Modelo
* @property-read string $cidade
* @property-read string $bairro
* @property-read string $rua
* @property-read string $numero
*/
class Endereco
{
private $cidade;
private $bairro;
private $rua;
private $numero;
public function __construct(string $cidade, string $bairro, string $rua, string $numero)
{
$this->cidade = $cidade;
$this->bairro = $bairro;
$this->rua = $rua;
$this->numero = $numero;
}
public function recuperaCidade(): string
{
return $this->cidade;
}
public function recuperaBairro(): string
{
return $this->bairro;
}
public function recuperaRua(): string
{
return $this->rua;
}
public function recuperaNumero(): string
{
return $this->numero;
}
public function __toString(): string
{
return "{$this -> rua}, {$this -> numero}, {$this->bairro}, {$this->cidade}";
}
public function __get($atributo)
{
$metodo = 'recupera'.ucfirst($atributo);
return $this->$metodo();
}
public function alteraCidade ($novaCidade): string
{
return $this->cidade = $novaCidade;
}
public function alteraBairro ($novoBairro): string
{
return $this->bairro = $novoBairro;
}
public function alteraRua ($novaRua): string
{
return $this->rua = $novaRua;
}
public function alteraNumero ($novoNumero): string
{
return $this->numero = $novoNumero;
}
public function __set($local, $valor)
{
$local = 'altera'.ucfirst($local);
return $this->$local($valor);
}
}