-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathCodeFileGeneratorConfig.php
More file actions
140 lines (123 loc) · 3.57 KB
/
CodeFileGeneratorConfig.php
File metadata and controls
140 lines (123 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
declare(strict_types=1);
namespace phpowermove\codegen\config;
use phpowermove\docblock\Docblock;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Configuration for code file generation
*
* @author Thomas Gossmann
*/
class CodeFileGeneratorConfig extends CodeGeneratorConfig {
protected function configureOptions(OptionsResolver $resolver): void {
parent::configureOptions($resolver);
$resolver->setDefaults([
'headerComment' => null,
'headerDocblock' => null,
'blankLineAtEnd' => true,
'declareStrictTypes' => false,
'generateScalarTypeHints' => function (Options $options) {
return $options['declareStrictTypes'];
},
'generateReturnTypeHints' => function (Options $options) {
return $options['declareStrictTypes'];
},
]);
$resolver->setAllowedTypes('headerComment', ['null', 'string', 'phpowermove\\docblock\\Docblock']);
$resolver->setAllowedTypes('headerDocblock', ['null', 'string', 'phpowermove\\docblock\\Docblock']);
$resolver->setAllowedTypes('blankLineAtEnd', 'bool');
$resolver->setAllowedTypes('declareStrictTypes', 'bool');
$resolver->setNormalizer('headerComment', function (Options $options, $value) {
return $this->toDocblock($value);
});
$resolver->setNormalizer('headerDocblock', function (Options $options, $value) {
return $this->toDocblock($value);
});
}
/**
*
* @param mixed $value
* @return Docblock|null
*/
private function toDocblock($value): ?Docblock {
if (is_string($value)) {
$value = Docblock::create()->setLongDescription($value);
}
return $value;
}
/**
* Returns the file header comment
*
* @return Docblock the header comment
*/
public function getHeaderComment(): ?Docblock {
return $this->options['headerComment'];
}
/**
* Sets the file header comment
*
* @param Docblock $comment the header comment
* @return $this
*/
public function setHeaderComment(Docblock $comment) {
$this->options['headerComment'] = $comment;
return $this;
}
/**
* Returns the file header docblock
*
* @return Docblock the docblock
*/
public function getHeaderDocblock(): ?Docblock {
return $this->options['headerDocblock'];
}
/**
* Sets the file header docblock
*
* @param Docblock $docblock the docblock
* @return $this
*/
public function setHeaderDocblock(Docblock $docblock) {
$this->options['headerDocblock'] = $docblock;
return $this;
}
/**
* Returns whether a blank line should be generated at the end of the file
*
* @return bool `true` if it will be generated and `false` if not
*/
public function getBlankLineAtEnd(): bool {
return $this->options['blankLineAtEnd'];
}
/**
* Sets whether a blank line should be generated at the end of the file
*
* @param bool $show `true` if it will be generated and `false` if not
* @return $this
*/
public function setBlankLineAtEnd(bool $show) {
$this->options['blankLineAtEnd'] = $show;
return $this;
}
/**
* Returns whether a `declare(strict_types=1);` statement should be printed
* below the header comments (PHP 7)
*
* @return bool `true` if it will be printed and `false` if not
*/
public function getDeclareStrictTypes(): bool {
return $this->options['declareStrictTypes'];
}
/**
* Sets whether a `declare(strict_types=1);` statement should be printed
* below the header comments (PHP 7)
*
* @param bool $strict `true` if it will be printed and `false` if not
* @return $this
*/
public function setDeclareStrictTypes(bool $strict) {
$this->options['declareStrictTypes'] = $strict;
return $this;
}
}