Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
66.67% |
14 / 21 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ApieRunGlobalMethodCommand | |
66.67% |
14 / 21 |
|
80.00% |
4 / 5 |
10.37 | |
0.00% |
0 / 1 |
| getCommandName | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getCommandHelp | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getMetadata | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| getSuccessMessage | |
36.36% |
4 / 11 |
|
0.00% |
0 / 1 |
8.12 | |||
| requiresId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\Console\Commands; |
| 3 | |
| 4 | use Apie\Common\ValueObjects\DecryptedAuthenticatedUser; |
| 5 | use Apie\Common\Wrappers\TextEncrypter; |
| 6 | use Apie\Console\Helpers\DisplayResultHelper; |
| 7 | use Apie\Core\Actions\ActionResponse; |
| 8 | use Apie\Core\BoundedContext\BoundedContextId; |
| 9 | use Apie\Core\ContextConstants; |
| 10 | use Apie\Core\Entities\EntityInterface; |
| 11 | use Apie\Core\Identifiers\KebabCaseSlug; |
| 12 | use Apie\Core\Metadata\MetadataFactory; |
| 13 | use Apie\Core\Metadata\MetadataInterface; |
| 14 | |
| 15 | final class ApieRunGlobalMethodCommand extends ApieMetadataDirectedConsoleCommand |
| 16 | { |
| 17 | protected function getCommandName(): string |
| 18 | { |
| 19 | assert(null !== $this->reflectionMethod); |
| 20 | return KebabCaseSlug::fromClass($this->reflectionClass) . ':run:' . KebabCaseSlug::fromClass($this->reflectionMethod); |
| 21 | } |
| 22 | |
| 23 | protected function getCommandHelp(): string |
| 24 | { |
| 25 | assert(null !== $this->reflectionMethod); |
| 26 | return 'This command runs ' . $this->reflectionMethod->getName() . ' from service ' . $this->reflectionClass->getShortName(); |
| 27 | } |
| 28 | |
| 29 | protected function getMetadata(): MetadataInterface |
| 30 | { |
| 31 | assert(null !== $this->reflectionMethod); |
| 32 | return MetadataFactory::getMethodMetadata( |
| 33 | $this->reflectionMethod, |
| 34 | $this->apieContext |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | protected function getSuccessMessage(ActionResponse $actionResponse): string |
| 39 | { |
| 40 | if ($this->reflectionMethod->name === 'verifyAuthentication' |
| 41 | && $actionResponse->result instanceof EntityInterface |
| 42 | && $actionResponse->apieContext->hasContext(TextEncrypter::class)) { |
| 43 | /** @var TextEncrypter $textEncrypter */ |
| 44 | $textEncrypter = $actionResponse->apieContext->getContext(TextEncrypter::class); |
| 45 | $decryptedUserId = DecryptedAuthenticatedUser::createFromEntity( |
| 46 | $actionResponse->result, |
| 47 | new BoundedContextId($actionResponse->apieContext->getContext(ContextConstants::BOUNDED_CONTEXT_ID)), |
| 48 | time() + 3600 |
| 49 | ); |
| 50 | $this->consoleCliStorage->store('_APIE_AUTHENTICATED', $textEncrypter->encrypt($decryptedUserId->toNative())); |
| 51 | } |
| 52 | return 'The result was: ' . PHP_EOL . DisplayResultHelper::displayResult($actionResponse->result); |
| 53 | } |
| 54 | |
| 55 | protected function requiresId(): bool |
| 56 | { |
| 57 | return false; |
| 58 | } |
| 59 | } |