| Total Complexity | 8 |
| Total Lines | 65 |
| Duplicated Lines | 0 % |
| Coverage | 95.24% |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
| 1 | <?php |
||
| 12 | trait HasStrategyTrait |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var null|AbstractStrategy |
||
| 16 | */ |
||
| 17 | protected $strategy = null; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @return AbstractStrategy|null |
||
| 21 | */ |
||
| 22 | 2 | public function getStrategy() |
|
| 23 | { |
||
| 24 | 2 | if ($this->strategy === null) { |
|
| 25 | 2 | $this->initStrategy(); |
|
| 26 | } |
||
| 27 | |||
| 28 | 2 | return $this->strategy; |
|
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param AbstractStrategy|null $strategy |
||
| 33 | */ |
||
| 34 | 2 | public function setStrategy($strategy) |
|
| 35 | { |
||
| 36 | 2 | $this->strategy = $strategy; |
|
| 37 | 2 | } |
|
| 38 | |||
| 39 | 2 | protected function initStrategy() |
|
| 40 | { |
||
| 41 | 2 | $this->setStrategy($this->generateStrategy()); |
|
| 42 | 2 | } |
|
| 43 | |||
| 44 | /** |
||
| 45 | * @return AbstractStrategy |
||
| 46 | */ |
||
| 47 | 2 | protected function generateStrategy() |
|
| 48 | { |
||
| 49 | 2 | $strategy = $this->newStrategy(); |
|
| 50 | |||
| 51 | 2 | return $strategy; |
|
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @return AbstractStrategy |
||
| 56 | */ |
||
| 57 | 2 | protected function newStrategy() |
|
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @return string |
||
| 66 | */ |
||
| 67 | 2 | protected function getStrategyClassName() |
|
| 77 | } |
||
| 78 | } |
||
| 79 |