| Total Complexity | 9 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php namespace FlatPlan\Components; |
||
| 3 | class Social extends AbstractComponent { |
||
| 4 | |||
| 5 | private $role; |
||
| 6 | private $url; |
||
| 7 | |||
| 8 | protected $roles = ['instagram', 'facebook_post', 'tweet']; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * @param string $role |
||
| 12 | * @param string $url |
||
| 13 | * @return void |
||
| 14 | */ |
||
| 15 | public function __construct($role, $url) |
||
| 16 | { |
||
| 17 | $this->setRole($role); |
||
| 18 | $this->setUrl($url); |
||
| 19 | } |
||
| 20 | |||
| 21 | public function setRole($role) |
||
| 22 | { |
||
| 23 | if (!in_array($role, $this->roles)) { |
||
| 24 | throw new \ErrorException('Invalid role supplied.'); |
||
| 25 | } |
||
| 26 | $this->role = $role; |
||
| 27 | } |
||
| 28 | |||
| 29 | public function getRole() |
||
| 30 | { |
||
| 31 | return $this->role; |
||
| 32 | } |
||
| 33 | |||
| 34 | public function setUrl($url) |
||
| 35 | { |
||
| 36 | if (!filter_var($url, FILTER_VALIDATE_URL)) { |
||
| 37 | throw new \ErrorException('Invalid url supplied.'); |
||
| 38 | } |
||
| 39 | $this->url = $url; |
||
| 40 | } |
||
| 41 | |||
| 42 | public function getUrl() |
||
| 43 | { |
||
| 44 | return $this->url; |
||
| 45 | } |
||
| 46 | |||
| 47 | public function getComponent() |
||
| 48 | { |
||
| 49 | $component = new \stdClass(); |
||
| 50 | $component->role = $this->getRole(); |
||
| 51 | $component->url = $this->getUrl(); |
||
| 52 | return $component; |
||
| 53 | } |
||
| 54 | |||
| 55 | public function __toString() |
||
| 58 | } |
||
| 59 | } |
||
| 60 |