Skip to content

Instantly share code, notes, and snippets.

Created October 10, 2017 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c7c275305a57b5391f5c5d32efe40132 to your computer and use it in GitHub Desktop.
Save anonymous/c7c275305a57b5391f5c5d32efe40132 to your computer and use it in GitHub Desktop.
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