Skip to content

Commit a1e916c

Browse files
committed
Named parts *Part; Fixed comments and cs
1 parent ce62ef1 commit a1e916c

42 files changed

Lines changed: 789 additions & 375 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.php_cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ return Config::create()
1818
->fixers([
1919
'encoding',
2020
'short_tag',
21-
//'braces',
2221
'eof_ending',
2322
'function_call_space',
2423
'function_declaration',

src/config/CodeFileGeneratorConfig.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,25 @@
44
use gossi\docblock\Docblock;
55
use Symfony\Component\OptionsResolver\Options;
66

7+
/**
8+
* Configuration for code file generation
9+
*
10+
* @author Thomas Gossmann
11+
*/
712
class CodeFileGeneratorConfig extends CodeGeneratorConfig {
813

14+
/**
15+
* @inheritDoc
16+
*/
917
protected function getOptionalOptions() {
1018
return array_merge([
1119
'headerComment', 'headerDocblock', 'blankLineAtEnd', 'declareStrictTypes'
1220
], parent::getOptionalOptions());
1321
}
1422

23+
/**
24+
* @inheritDoc
25+
*/
1526
protected function getDefaultOptions() {
1627
return array_merge(
1728
parent::getDefaultOptions(), [
@@ -28,6 +39,9 @@ protected function getDefaultOptions() {
2839
]);
2940
}
3041

42+
/**
43+
* @inheritDoc
44+
*/
3145
protected function getAllowedOptionTypes() {
3246
return array_merge([
3347
'headerComment' => 'string',
@@ -39,7 +53,7 @@ protected function getAllowedOptionTypes() {
3953

4054
/**
4155
* Returns the file header comment
42-
*
56+
*
4357
* @return string the header comment
4458
*/
4559
public function getHeaderComment() {
@@ -48,7 +62,7 @@ public function getHeaderComment() {
4862

4963
/**
5064
* Sets the file header comment
51-
*
65+
*
5266
* @param string $comment the header comment
5367
* @return $this
5468
*/
@@ -59,7 +73,7 @@ public function setHeaderComment($comment) {
5973

6074
/**
6175
* Returns the file header docblock
62-
*
76+
*
6377
* @return Docblock the docblock
6478
*/
6579
public function getHeaderDocblock() {
@@ -68,7 +82,7 @@ public function getHeaderDocblock() {
6882

6983
/**
7084
* Sets the file header docblock
71-
*
85+
*
7286
* @param Docblock $docblock the docblock
7387
* @return $this
7488
*/
@@ -79,7 +93,7 @@ public function setHeaderDocblock(Docblock $docblock) {
7993

8094
/**
8195
* Returns whether a blank line should be generated at the end of the file
82-
*
96+
*
8397
* @return bool `true` if it will be generated and `false` if not
8498
*/
8599
public function getBlankLineAtEnd() {
@@ -88,7 +102,7 @@ public function getBlankLineAtEnd() {
88102

89103
/**
90104
* Sets whether a blank line should be generated at the end of the file
91-
*
105+
*
92106
* @param bool $show `true` if it will be generated and `false` if not
93107
* @return $this
94108
*/
@@ -98,19 +112,19 @@ public function setBlankLineAtEnd($show) {
98112
}
99113

100114
/**
101-
* Returns whether a `declare(strict_types=1);` statement should be printed
115+
* Returns whether a `declare(strict_types=1);` statement should be printed
102116
* below the header comments (PHP 7)
103-
*
117+
*
104118
* @return bool `true` if it will be printed and `false` if not
105119
*/
106120
public function getDeclareStrictTypes() {
107121
return $this->options['declareStrictTypes'];
108122
}
109123

110124
/**
111-
* Sets whether a `declare(strict_types=1);` statement should be printed
125+
* Sets whether a `declare(strict_types=1);` statement should be printed
112126
* below the header comments (PHP 7)
113-
*
127+
*
114128
* @param bool $strict `true` if it will be printed and `false` if not
115129
* @return $this
116130
*/

src/config/CodeGeneratorConfig.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
use Symfony\Component\OptionsResolver\OptionsResolver;
66

77
/**
8-
* Configuration for code generator
9-
*
10-
* @author gossi
8+
* Configuration for code generation
9+
*
10+
* @author Thomas Gossmann
1111
*/
1212
class CodeGeneratorConfig {
1313

1414
protected $options;
1515

1616
/**
1717
* Creates a new configuration for code generator
18-
*
18+
*
1919
* @see https://php-code-generator.readthedocs.org/en/latest/generator.html
2020
* @param array $options
2121
*/
@@ -29,6 +29,11 @@ public function __construct(array $options = []) {
2929
$this->options = $resolver->resolve($options);
3030
}
3131

32+
/**
33+
* Return optional config options
34+
*
35+
* @return array
36+
*/
3237
protected function getOptionalOptions() {
3338
return [
3439
'generateDocblock',
@@ -38,6 +43,11 @@ protected function getOptionalOptions() {
3843
];
3944
}
4045

46+
/**
47+
* Return default config options
48+
*
49+
* @return array
50+
*/
4151
protected function getDefaultOptions() {
4252
return [
4353
'generateDocblock' => true,
@@ -49,6 +59,11 @@ protected function getDefaultOptions() {
4959
];
5060
}
5161

62+
/**
63+
* Return allowed option types
64+
*
65+
* @return array
66+
*/
5267
protected function getAllowedOptionTypes() {
5368
return [
5469
'generateDocblock' => 'bool',
@@ -60,7 +75,7 @@ protected function getAllowedOptionTypes() {
6075

6176
/**
6277
* Returns whether docblocks should be generated
63-
*
78+
*
6479
* @return bool `true` if they will be generated and `false` if not
6580
*/
6681
public function getGenerateDocblock() {
@@ -83,7 +98,7 @@ public function setGenerateDocblock($generate) {
8398

8499
/**
85100
* Returns whether empty docblocks are generated
86-
*
101+
*
87102
* @return bool `true` if they will be generated and `false` if not
88103
*/
89104
public function getGenerateEmptyDocblock() {
@@ -106,7 +121,7 @@ public function setGenerateEmptyDocblock($generate) {
106121

107122
/**
108123
* Returns whether scalar type hints will be generated for method parameters (PHP 7)
109-
*
124+
*
110125
* @return bool `true` if they will be generated and `false` if not
111126
*/
112127
public function getGenerateScalarTypeHints() {
@@ -126,7 +141,7 @@ public function setGenerateScalarTypeHints($generate) {
126141

127142
/**
128143
* Returns whether return type hints will be generated for method parameters (PHP 7)
129-
*
144+
*
130145
* @return bool `true` if they will be generated and `false` if not
131146
*/
132147
public function getGenerateReturnTypeHints() {

src/generator/CodeFileGenerator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77

88
/**
99
* Code file generator.
10-
*
10+
*
1111
* Generates code for a model and puts it into a file with `<?php` statements. Can also
12-
* generate header comments.
13-
*
14-
* @author gossi
12+
* generate header comments.
13+
*
14+
* @author Thomas Gossmann
1515
*/
1616
class CodeFileGenerator extends CodeGenerator {
1717

1818
/**
1919
* Creates a new CodeFileGenerator
20-
*
20+
*
2121
* @see https://php-code-generator.readthedocs.org/en/latest/generator.html
2222
* @param CodeFileGeneratorConfig|array $config
2323
*/
@@ -35,7 +35,7 @@ public function __construct($config = null) {
3535

3636
/**
3737
* {@inheritDoc}
38-
*
38+
*
3939
* @return CodeFileGeneratorConfig
4040
*/
4141
public function getConfig() {

src/generator/CodeGenerator.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
use gossi\codegen\model\GenerateableInterface;
66
use gossi\codegen\visitor\GeneratorVisitor;
77

8+
/**
9+
* Code generator
10+
*
11+
* Generates code for any generateable model
12+
*
13+
* @author Thomas Gossmann
14+
*/
815
class CodeGenerator {
916

1017
protected $config;
1118

1219
/**
13-
* @var DefaultGeneratorStrategy
20+
* @var GeneratorStrategy
1421
*/
1522
protected $strategy;
1623

@@ -37,7 +44,7 @@ protected function init() {
3744

3845
/**
3946
* Returns the used configuration
40-
*
47+
*
4148
* @return CodeGeneratorConfig
4249
*/
4350
public function getConfig() {
@@ -46,7 +53,7 @@ public function getConfig() {
4653

4754
/**
4855
* Returns the used generator strategy
49-
*
56+
*
5057
* @return DefaultGeneratorStrategy
5158
*/
5259
public function getGeneratorStrategy() {
@@ -55,7 +62,7 @@ public function getGeneratorStrategy() {
5562

5663
/**
5764
* Generates code from a given model
58-
*
65+
*
5966
* @param GenerateableInterface $model
6067
* @return string the generated code
6168
*/

src/generator/GeneratorStrategy.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public function setUseStatementSortFunc(\Closure $func = null) {
5656
$this->navigator->setUseStatementSortFunc($func);
5757
}
5858

59+
/**
60+
* @param GenerateableInterface $class
61+
* @return string
62+
*/
5963
public function generate(GenerateableInterface $class) {
6064
$this->visitor->reset();
6165
$this->navigator->accept($this->visitor, $class);

0 commit comments

Comments
 (0)