From e3cbac38cee6313a1a4aa84e8888e63d49ba03d6 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 22 Oct 2016 22:11:36 +0200 Subject: [PATCH] Improved output on api-key:list command --- .../CLI/src/Command/Api/ListKeysCommand.php | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/module/CLI/src/Command/Api/ListKeysCommand.php b/module/CLI/src/Command/Api/ListKeysCommand.php index e6f70ec0..5e93adeb 100644 --- a/module/CLI/src/Command/Api/ListKeysCommand.php +++ b/module/CLI/src/Command/Api/ListKeysCommand.php @@ -73,12 +73,15 @@ class ListKeysCommand extends Command $key = $row->getKey(); $expiration = $row->getExpirationDate(); $rowData = []; + $formatMethod = ! $row->isEnabled() + ? 'getErrorString' + : ($row->isExpired() ? 'getWarningString' : 'getSuccessString'); if ($enabledOnly) { - $rowData[] = $key; + $rowData[] = $this->{$formatMethod}($key); } else { - $rowData[] = $row->isEnabled() ? $this->getSuccessString($key) : $this->getErrorString($key); - $rowData[] = $row->isEnabled() ? $this->getSuccessString('+++') : $this->getErrorString('---'); + $rowData[] = $this->{$formatMethod}($key); + $rowData[] = $this->{$formatMethod}($this->getEnabledSymbol($row)); } $rowData[] = isset($expiration) ? $expiration->format(\DateTime::ISO8601) : '-'; @@ -105,4 +108,22 @@ class ListKeysCommand extends Command { return sprintf('%s', $string); } + + /** + * @param $string + * @return string + */ + protected function getWarningString($string) + { + return sprintf('%s', $string); + } + + /** + * @param ApiKey $apiKey + * @return string + */ + protected function getEnabledSymbol(ApiKey $apiKey) + { + return ! $apiKey->isEnabled() || $apiKey->isExpired() ? '---' : '+++'; + } }