1 | <?php |
||
22 | class CommandHelper |
||
23 | { |
||
24 | /** @var SharepCommandProcessor */ |
||
25 | private $sharepCommandProcessor; |
||
26 | /** @var ErrorMessage */ |
||
27 | private $errorMessage; |
||
28 | /** @var NotRecognizedUserMessage */ |
||
29 | private $notRecognizedUserMessage; |
||
30 | /** @var SerializerInterface */ |
||
31 | private $serializer; |
||
32 | /** @var MemberRepository */ |
||
33 | private $memberRepository; |
||
34 | /** @var LoggerInterface */ |
||
35 | private $logger; |
||
36 | |||
37 | 3 | public function __construct( |
|
52 | |||
53 | 3 | public function handleWebhook(array $data): Layout |
|
54 | { |
||
55 | try { |
||
56 | 3 | $message = null; |
|
57 | 3 | $commandData = $this->calculateCommandData($data); |
|
58 | |||
59 | 3 | $member = $this->memberRepository->findOneBySlackUserId($commandData->userId); |
|
60 | 3 | if (!$member instanceof Member) { |
|
61 | $message = $this->notRecognizedUserMessage->generate(); |
||
62 | } |
||
63 | |||
64 | 3 | if (SharepCommandProcessor::COMMAND === $commandData->command) { |
|
65 | 2 | $message = $this->sharepCommandProcessor->process($commandData); |
|
66 | } |
||
67 | |||
68 | 1 | if (!$message instanceof Layout) { |
|
69 | 1 | $message = $this->errorMessage->generate(); |
|
70 | } |
||
71 | 2 | } catch (\Throwable $e) { |
|
72 | 2 | $this->logger->error($e); |
|
73 | 2 | $message = $this->errorMessage->generate(); |
|
74 | } |
||
75 | |||
76 | 3 | return $message; |
|
77 | } |
||
78 | |||
79 | 3 | private function calculateCommandData(array $data): CommandData |
|
87 | } |
||
88 |