1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of CaptainHook. |
4
|
|
|
* |
5
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace CaptainHook\App\Console\Command\Hook; |
11
|
|
|
|
12
|
|
|
use CaptainHook\App\Config; |
13
|
|
|
use CaptainHook\App\Console\Command\Hook; |
14
|
|
|
use CaptainHook\App\Hooks; |
15
|
|
|
use SebastianFeldmann\Git\CommitMessage; |
16
|
|
|
use SebastianFeldmann\Git\Repository; |
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class PrepareCommitMessage |
23
|
|
|
* |
24
|
|
|
* @package CaptainHook |
25
|
|
|
* @author Sebastian Feldmann <[email protected]> |
26
|
|
|
* @link https://github.com/sebastianfeldmann/captainhook |
27
|
|
|
* @since Class available since Release 3.0.1 |
28
|
|
|
*/ |
29
|
|
|
class PrepareCommitMsg extends Hook |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Hook to execute |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $hookName = Hooks::PREPARE_COMMIT_MSG; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* File to read/write the commit message from/to |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
private $file; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Commit mode [null|message|template|merge|squash|commit] |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
private $mode; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Commit hash if mode is commit during -c or --amend |
54
|
|
|
* |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
private $hash; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Configure the command |
61
|
|
|
*/ |
62
|
1 |
|
protected function configure() |
63
|
|
|
{ |
64
|
1 |
|
parent::configure(); |
65
|
1 |
|
$this->addArgument('file', InputArgument::REQUIRED, 'File containing the commit log message'); |
66
|
1 |
|
$this->addArgument('mode', InputArgument::OPTIONAL, 'Current commit mode'); |
67
|
1 |
|
$this->addArgument('hash', InputArgument::OPTIONAL, 'Given commit hash'); |
68
|
1 |
|
} |
69
|
|
|
/** |
70
|
|
|
* Read the commit message from file |
71
|
|
|
* |
72
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
73
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
74
|
|
|
* @param \CaptainHook\App\Config $config |
75
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
76
|
|
|
*/ |
77
|
1 |
|
protected function setup(InputInterface $input, OutputInterface $output, Config $config, Repository $repository) |
78
|
|
|
{ |
79
|
1 |
|
$this->file = $input->getArgument('file'); |
|
|
|
|
80
|
1 |
|
$this->mode = $input->getArgument('mode'); |
|
|
|
|
81
|
1 |
|
$this->hash = $input->getArgument('hash'); |
|
|
|
|
82
|
1 |
|
$gitConfig = $repository->getConfigOperator(); |
83
|
1 |
|
$commentCharacter = $gitConfig->getSafely('core.commentchar', '#'); |
84
|
|
|
|
85
|
1 |
|
$repository->setCommitMsg(CommitMessage::createFromFile($this->file, $commentCharacter)); |
|
|
|
|
86
|
|
|
|
87
|
1 |
|
parent::setup($input, $output, $config, $repository); |
88
|
1 |
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Post action after all the configured actions are executed |
92
|
|
|
* |
93
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
94
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
95
|
|
|
* @param \CaptainHook\App\Config $config |
96
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
97
|
|
|
*/ |
98
|
1 |
|
protected function tearDown(InputInterface $input, OutputInterface $output, Config $config, Repository $repository) |
99
|
|
|
{ |
100
|
1 |
|
file_put_contents($this->file, $repository->getCommitMsg()->getRawContent()); |
101
|
1 |
|
} |
102
|
|
|
} |
103
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.