1 | <?php |
||
13 | class CommitMsgTool |
||
14 | { |
||
15 | /** |
||
16 | * @var MergeValidatorInterface |
||
17 | */ |
||
18 | private $mergeValidator; |
||
19 | /** |
||
20 | * @var QueryBus |
||
21 | */ |
||
22 | private $queryBus; |
||
23 | /** |
||
24 | * @var CommitMessageFinderInterface |
||
25 | */ |
||
26 | private $commitMessageFinder; |
||
27 | |||
28 | /** |
||
29 | * CommitMsgTool constructor. |
||
30 | * |
||
31 | * @param MergeValidatorInterface $mergeValidator |
||
32 | * @param QueryBus $queryBus |
||
33 | * @param CommitMessageFinderInterface $commitMessageFinder |
||
34 | */ |
||
35 | 2 | public function __construct( |
|
44 | |||
45 | /** |
||
46 | * @param InputInterface $input |
||
47 | * |
||
48 | * @throws InvalidCommitMessageException |
||
49 | */ |
||
50 | 2 | public function run(InputInterface $input) |
|
51 | { |
||
52 | /** @var ConfigurationDataResponse $configurationDataResponse */ |
||
53 | 2 | $configurationDataResponse = $this->queryBus->handle(new ConfigurationDataFinderQuery()); |
|
54 | |||
55 | 2 | if (true === $configurationDataResponse->getCommitMsg()->isCommitMsg()) { |
|
56 | 1 | $commitContent = $this->commitMessageFinder->find($input->getFirstArgument()); |
|
57 | |||
58 | 1 | $validMessage = $this->isValidCommitMessage( |
|
59 | 1 | $configurationDataResponse->getCommitMsg()->getRegularExpression(), |
|
60 | $commitContent |
||
61 | ); |
||
62 | |||
63 | 1 | if (false === $validMessage) { |
|
64 | 1 | throw new InvalidCommitMessageException(); |
|
65 | } |
||
66 | } |
||
67 | 1 | } |
|
68 | |||
69 | /** |
||
70 | * @param string $regularExpression |
||
71 | * @param string $commitMessage |
||
72 | * |
||
73 | * @return bool |
||
74 | */ |
||
75 | 1 | private function isValidCommitMessage($regularExpression, $commitMessage) |
|
79 | } |
||
80 |