<?php
class ExternalPost
{
private $reactions;
private $comments;
private $shares;
public function __construct(Reactions $reactions = null, Comments $comments = null, Shares $shares = null)
{
$this->reactions = $reactions;
$this->comments = $comments;
$this->shares = $shares;
}
public function getReactions()
{
if (null === $this->reactions) {
$this->reactions = new Reactions;
}
return $this->reactions;
}
public function getComments()
{
if(null === $this->comments) {
$this->comments = new Comments;
}
return $this->comments;
}
public function getShares()
{
if (null === $this->shares) {
$this->shares = new Shares;
}
return $this->shares;
}
public function getTotal()
{
return $this->getReactions()->getTotal() +
$this->getComments()->getTotal() +
$this->getShares()->getCount();
}
}
class Summary
{
private $total_count = 0;
public function getTotalCount()
{
return $this->total_count;
}
public function setTotalCount($total)
{
$this->total_count = $total;
return $this;
}
}
abstract class Summation
{
protected $summary;
public function __construct(Summary $summary = null)
{
if (null === $summary) {
$summary = new Summary;
}
$this->summary = $summary;
}
public function getTotal()
{
return $this->summary->getTotalCount();
}
public function setTotal($total)
{
$this->summary->setTotalCount($total);
return $this;
}
}
class Reactions extends Summation{}
class Comments extends Summation{}
class Shares
{
private $count = 0;
public function getCount()
{
}
public function setCount($count)
{
return $this;
}
}
$reactions = new Reactions;
$reactions->setTotal(1);
$comments = new Comments;
$reactions->setTotal(2);
$ExternalPost = new ExternalPost($reactions, $comments);
$ExternalPost->getShares()->setCount(3);