Create a gist now

Instantly share code, notes, and snippets.

anonymous /Ex1a.php
Created Oct 10, 2017

What would you like to do?
class User
{
...
protected $portfolioUrl;
public function setPortfolioUrl(string $url)
{
if (false === filter_var($url, FILTER_VALIDATE_URL)) {
throw new InvalidURL($url);
}
$this->portfolioUrl = $url;
}
public function getPortfolioUrl():string
{
return $this->portfolioUrl;
}
...
}
class User
{
...
protected $portfolioUrl;
public function setPortfolioUrl(Url $url)
{
$this->portfolioUrl = $url;
}
public function getPortfolioUrl():Url
{
return $this->portfolioUrl;
}
...
}
class Url
{
protected $url;
public function setUrl(string $url)
{
if (false === filter_var($url, FILTER_VALIDATE_URL)) {
throw new InvalidURL($url);
}
$this->url = $url;
}
public function getUrl():string
{
return $this->url;
}
...
}
class User
{
...
const SINGLE = ‘S’;
const IN_RELATIONSHIP = ‘R’;
protected $relationship;
public function setRelationship(string $relationship)
{
$this->relationship = $relationship;
}
public function getRelationship():string
{
return $this->relationship;
}
...
}
class User
{
...
protected $relationship;
public function setRelationship(Relationship $relationship)
{
$this->relationship = $relationship;
}
public function getRelationship():Relationship
{
return $this->relationship;
}
...
}
class Relationship
{
private $relationshipCode;
private function __construct($relationshipCode)
{
$this->relationshipCode = $relationshipCode;
}
public function getRelationshipCode()
{
return $this->relationshipCode;
}
public static function single():Relationship
{
return new self('S');
}
public static function inRelationship():Relationship
{
return new self('R');
}
}
class Offer
{
...
const DRAFT = 1;
const PUBLISHED = 2;
const CANCELED = 3;
...
protected $status;
public function setStatus(int $status)
{
$this->status = $status;
}
public function getStatus():int
{
return $this->status;
}
...
}
class Offer
{
...
const DRAFT = 1;
const PUBLISHED = 2;
Const CANCELLED = 3;
...
protected $status;
public function setStatus(OfferStatus $status)
{
$this-status = $status;
}
public function getStatus():OfferStatus
{
return $this->status;
}
...
}
abstract class OfferStatus
{
public abstract function getCode();
}
class DraftOffer extends OfferStatus
{
public function getCode()
{
return Offer::DRAFT;
}
}
class PublishedOffer extends OfferStatus
{
public function getCode()
{
return Offer::PUBLISHED;
}
}
class CancelledOffer extends OfferStatus
{
public function getCode()
{
return Offer::CANCELLED;
}
}
$todo = [];
$todo[0][‘description’] = ‘feed cat’;
$todo[0][‘done’] = true;
...
class Todo
{
protected $description;
protected $done;
public function __construct(string $description, bool $done)
{
$this->description = $description;
$this->done = $done;
}
public function setDone(bool $done)
{
$this->done = $done;
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment