| Total Complexity | 5 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 7 | trait VisibleCondition |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var Closure|null |
||
| 11 | */ |
||
| 12 | protected $visibleCondition; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @return bool |
||
| 16 | */ |
||
| 17 | public function isVisible() |
||
| 18 | { |
||
| 19 | if (is_bool($this->visibleCondition)) { |
||
|
|
|||
| 20 | return $this->visibleCondition; |
||
| 21 | } |
||
| 22 | |||
| 23 | if (is_callable($this->visibleCondition)) { |
||
| 24 | return (bool) call_user_func($this->visibleCondition, $this->getModel()); |
||
| 25 | } |
||
| 26 | |||
| 27 | return true; |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param Closure|bool $visibleCondition |
||
| 32 | * |
||
| 33 | * @return $this |
||
| 34 | */ |
||
| 35 | public function setVisible($visibleCondition) |
||
| 36 | { |
||
| 37 | $this->visibleCondition = $visibleCondition; |
||
| 38 | |||
| 39 | return $this; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param Closure $condition |
||
| 44 | * |
||
| 45 | * @return $this |
||
| 46 | */ |
||
| 47 | public function setVisibilityCondition(Closure $condition) |
||
| 52 | } |
||
| 53 | } |
||
| 54 |