| Total Complexity | 5 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class SuiteTicket |
||
| 10 | { |
||
| 11 | use InteractsWithCache; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var Application |
||
| 15 | */ |
||
| 16 | protected $app; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * SuiteTicket constructor. |
||
| 20 | * @param Application $app |
||
| 21 | */ |
||
| 22 | public function __construct(Application $app) |
||
| 23 | { |
||
| 24 | $this->app = $app; |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param string $ticket |
||
| 29 | * @return $this |
||
| 30 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
| 31 | */ |
||
| 32 | public function setTicket(string $ticket) |
||
| 33 | { |
||
| 34 | $this->getCache()->set($this->getCacheKey(), $ticket, 600); |
||
| 35 | |||
| 36 | return $this; |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @return string |
||
| 41 | * @throws RuntimeException |
||
| 42 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
| 43 | */ |
||
| 44 | public function getTicket(): string |
||
| 45 | { |
||
| 46 | if ($cached = $this->getCache()->get($this->getCacheKey())) { |
||
| 47 | return $cached; |
||
| 48 | } |
||
| 49 | |||
| 50 | throw new RuntimeException('Credential "suite_ticket" does not exist in cache.'); |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | protected function getCacheKey(): string |
||
| 59 | } |
||
| 60 | |||
| 61 | } |