1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Application\Message; |
4
|
|
|
|
5
|
|
|
use Composer\IO\IOInterface; |
6
|
|
|
|
7
|
|
|
class MessageConfigData |
8
|
|
|
{ |
9
|
|
|
const TOOL = 'message'; |
10
|
|
|
const DEFAULT_RIGHT_MESSAGE = 'HEY, GOOD JOB!!'; |
11
|
|
|
const DEFAULT_ERROR_MESSAGE = 'FIX YOUR FUCKING CODE!!'; |
12
|
|
|
const KEY_RIGHT_MESSAGE = 'right-message'; |
13
|
|
|
const KEY_ERROR_MESSAGE = 'error-message'; |
14
|
|
|
/** |
15
|
|
|
* @var array |
16
|
|
|
*/ |
17
|
|
|
private $configData; |
18
|
|
|
/** |
19
|
|
|
* @var IOInterface |
20
|
|
|
*/ |
21
|
|
|
private $io; |
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $hook; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* MessageConfigData constructor. |
29
|
|
|
* |
30
|
|
|
* @param IOInterface $io |
31
|
|
|
* @param $hook |
32
|
|
|
*/ |
33
|
9 |
|
public function __construct(IOInterface $io, $hook) |
34
|
|
|
{ |
35
|
9 |
|
$this->io = $io; |
36
|
9 |
|
$this->hook = $hook; |
37
|
9 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param array $data |
41
|
|
|
* |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
9 |
|
public function config(array $data) |
45
|
|
|
{ |
46
|
9 |
|
$this->configData = $data; |
47
|
9 |
|
$this->configMessages(); |
48
|
|
|
|
49
|
9 |
|
return $this->configData[self::TOOL]; |
50
|
|
|
} |
51
|
|
|
|
52
|
9 |
|
private function configMessages() |
53
|
|
|
{ |
54
|
9 |
|
if (!isset($this->configData[self::TOOL])) { |
55
|
8 |
|
$this->configData = null; |
|
|
|
|
56
|
8 |
|
$rightMessage = $this->setMessage( |
57
|
8 |
|
sprintf('Write a right message for %s hook:', $this->hook), |
58
|
|
|
self::DEFAULT_RIGHT_MESSAGE |
59
|
8 |
|
); |
60
|
8 |
|
$errorMessage = $this->setMessage( |
61
|
8 |
|
sprintf('Write a error message for %s hook:', $this->hook), |
62
|
|
|
self::DEFAULT_ERROR_MESSAGE |
63
|
8 |
|
); |
64
|
|
|
|
65
|
8 |
|
$this->configData[self::TOOL][self::KEY_RIGHT_MESSAGE] = $rightMessage; |
66
|
8 |
|
$this->configData[self::TOOL][self::KEY_ERROR_MESSAGE] = $errorMessage; |
67
|
8 |
|
} |
68
|
9 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $message |
72
|
|
|
* @param string $default |
73
|
|
|
* |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
8 |
|
private function setMessage($message, $default) |
77
|
|
|
{ |
78
|
8 |
|
return strtoupper($this->io |
79
|
8 |
|
->ask(sprintf('<info>%s</info> [<comment>%s</comment>]', $message, $default), $default)); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..