@@ -73,7 +73,7 @@ public function __construct(string $sourceCode, bool $overwrite = false, bool $u
73
73
$ this ->setSourceCode ($ sourceCode );
74
74
}
75
75
76
- public function setIo (ConsoleStyle $ io )
76
+ public function setIo (ConsoleStyle $ io ): void
77
77
{
78
78
$ this ->io = $ io ;
79
79
}
@@ -83,7 +83,7 @@ public function getSourceCode(): string
83
83
return $ this ->sourceCode ;
84
84
}
85
85
86
- public function addEntityField (string $ propertyName , array $ columnOptions , array $ comments = [])
86
+ public function addEntityField (string $ propertyName , array $ columnOptions , array $ comments = []): void
87
87
{
88
88
$ typeHint = $ this ->getEntityTypeHint ($ columnOptions ['type ' ]);
89
89
$ nullable = $ columnOptions ['nullable ' ] ?? false ;
@@ -110,7 +110,7 @@ public function addEntityField(string $propertyName, array $columnOptions, array
110
110
}
111
111
}
112
112
113
- public function addEmbeddedEntity (string $ propertyName , string $ className )
113
+ public function addEmbeddedEntity (string $ propertyName , string $ className ): void
114
114
{
115
115
$ typeHint = $ this ->addUseStatementIfNecessary ($ className );
116
116
@@ -150,27 +150,27 @@ public function addEmbeddedEntity(string $propertyName, string $className)
150
150
$ this ->addSetter ($ propertyName , $ typeHint , false );
151
151
}
152
152
153
- public function addManyToOneRelation (RelationManyToOne $ manyToOne )
153
+ public function addManyToOneRelation (RelationManyToOne $ manyToOne ): void
154
154
{
155
155
$ this ->addSingularRelation ($ manyToOne );
156
156
}
157
157
158
- public function addOneToOneRelation (RelationOneToOne $ oneToOne )
158
+ public function addOneToOneRelation (RelationOneToOne $ oneToOne ): void
159
159
{
160
160
$ this ->addSingularRelation ($ oneToOne );
161
161
}
162
162
163
- public function addOneToManyRelation (RelationOneToMany $ oneToMany )
163
+ public function addOneToManyRelation (RelationOneToMany $ oneToMany ): void
164
164
{
165
165
$ this ->addCollectionRelation ($ oneToMany );
166
166
}
167
167
168
- public function addManyToManyRelation (RelationManyToMany $ manyToMany )
168
+ public function addManyToManyRelation (RelationManyToMany $ manyToMany ): void
169
169
{
170
170
$ this ->addCollectionRelation ($ manyToMany );
171
171
}
172
172
173
- public function addInterface (string $ interfaceName )
173
+ public function addInterface (string $ interfaceName ): void
174
174
{
175
175
$ this ->addUseStatementIfNecessary ($ interfaceName );
176
176
@@ -181,7 +181,7 @@ public function addInterface(string $interfaceName)
181
181
/**
182
182
* @param string $trait the fully-qualified trait name
183
183
*/
184
- public function addTrait (string $ trait )
184
+ public function addTrait (string $ trait ): void
185
185
{
186
186
$ importedClassName = $ this ->addUseStatementIfNecessary ($ trait );
187
187
@@ -217,19 +217,19 @@ public function addTrait(string $trait)
217
217
$ this ->updateSourceCodeFromNewStmts ();
218
218
}
219
219
220
- public function addAccessorMethod (string $ propertyName , string $ methodName , $ returnType , bool $ isReturnTypeNullable , array $ commentLines = [], $ typeCast = null )
220
+ public function addAccessorMethod (string $ propertyName , string $ methodName , $ returnType , bool $ isReturnTypeNullable , array $ commentLines = [], $ typeCast = null ): void
221
221
{
222
222
$ this ->addCustomGetter ($ propertyName , $ methodName , $ returnType , $ isReturnTypeNullable , $ commentLines , $ typeCast );
223
223
}
224
224
225
- public function addGetter (string $ propertyName , $ returnType , bool $ isReturnTypeNullable , array $ commentLines = [])
225
+ public function addGetter (string $ propertyName , $ returnType , bool $ isReturnTypeNullable , array $ commentLines = []): void
226
226
{
227
227
$ methodName = 'get ' .Str::asCamelCase ($ propertyName );
228
228
229
229
$ this ->addCustomGetter ($ propertyName , $ methodName , $ returnType , $ isReturnTypeNullable , $ commentLines );
230
230
}
231
231
232
- public function addSetter (string $ propertyName , $ type , bool $ isNullable , array $ commentLines = [])
232
+ public function addSetter (string $ propertyName , $ type , bool $ isNullable , array $ commentLines = []): void
233
233
{
234
234
$ builder = $ this ->createSetterNodeBuilder ($ propertyName , $ type , $ isNullable , $ commentLines );
235
235
$ builder ->addStmt (
@@ -245,7 +245,7 @@ public function addSetter(string $propertyName, $type, bool $isNullable, array $
245
245
/**
246
246
* @param Node[] $params
247
247
*/
248
- public function addConstructor (array $ params , string $ methodBody )
248
+ public function addConstructor (array $ params , string $ methodBody ): void
249
249
{
250
250
if (null !== $ this ->getConstructorNode ()) {
251
251
throw new \LogicException ('Constructor already exists. ' );
@@ -264,7 +264,7 @@ public function addConstructor(array $params, string $methodBody)
264
264
/**
265
265
* @param Node[] $params
266
266
*/
267
- public function addMethodBuilder (Builder \Method $ methodBuilder , array $ params = [], string $ methodBody = null )
267
+ public function addMethodBuilder (Builder \Method $ methodBuilder , array $ params = [], string $ methodBody = null ): void
268
268
{
269
269
$ this ->addMethodParams ($ methodBuilder , $ params );
270
270
@@ -275,7 +275,7 @@ public function addMethodBuilder(Builder\Method $methodBuilder, array $params =
275
275
$ this ->addMethod ($ methodBuilder ->getNode ());
276
276
}
277
277
278
- public function addMethodBody (Builder \Method $ methodBuilder , string $ methodBody )
278
+ public function addMethodBody (Builder \Method $ methodBuilder , string $ methodBody ): void
279
279
{
280
280
$ nodes = $ this ->parser ->parse ($ methodBody );
281
281
$ methodBuilder ->addStmts ($ nodes );
@@ -311,7 +311,7 @@ public function createMethodLevelBlankLine()
311
311
return $ this ->createBlankLineNode (self ::CONTEXT_CLASS_METHOD );
312
312
}
313
313
314
- public function addProperty (string $ name , array $ annotationLines = [], $ defaultValue = null )
314
+ public function addProperty (string $ name , array $ annotationLines = [], $ defaultValue = null ): void
315
315
{
316
316
if ($ this ->propertyExists ($ name )) {
317
317
// we never overwrite properties
@@ -331,7 +331,7 @@ public function addProperty(string $name, array $annotationLines = [], $defaultV
331
331
$ this ->addNodeAfterProperties ($ newPropertyNode );
332
332
}
333
333
334
- public function addAnnotationToClass (string $ annotationClass , array $ options )
334
+ public function addAnnotationToClass (string $ annotationClass , array $ options ): void
335
335
{
336
336
$ annotationClassAlias = $ this ->addUseStatementIfNecessary ($ annotationClass );
337
337
$ docComment = $ this ->getClassNode ()->getDocComment ();
@@ -369,7 +369,7 @@ public function addAnnotationToClass(string $annotationClass, array $options)
369
369
$ this ->updateSourceCodeFromNewStmts ();
370
370
}
371
371
372
- private function addCustomGetter (string $ propertyName , string $ methodName , $ returnType , bool $ isReturnTypeNullable , array $ commentLines = [], $ typeCast = null )
372
+ private function addCustomGetter (string $ propertyName , string $ methodName , $ returnType , bool $ isReturnTypeNullable , array $ commentLines = [], $ typeCast = null ): void
373
373
{
374
374
$ propertyFetch = new Node \Expr \PropertyFetch (new Node \Expr \Variable ('this ' ), $ propertyName );
375
375
@@ -402,7 +402,7 @@ private function addCustomGetter(string $propertyName, string $methodName, $retu
402
402
$ this ->addMethod ($ getterNodeBuilder ->getNode ());
403
403
}
404
404
405
- private function createSetterNodeBuilder (string $ propertyName , $ type , bool $ isNullable , array $ commentLines = [])
405
+ private function createSetterNodeBuilder (string $ propertyName , $ type , bool $ isNullable , array $ commentLines = []): Builder \ Method
406
406
{
407
407
$ methodName = 'set ' .Str::asCamelCase ($ propertyName );
408
408
$ setterNodeBuilder = (new Builder \Method ($ methodName ))->makePublic ();
@@ -423,10 +423,8 @@ private function createSetterNodeBuilder(string $propertyName, $type, bool $isNu
423
423
/**
424
424
* @param string $annotationClass The annotation: e.g. "@ORM\Column"
425
425
* @param array $options Key-value pair of options for the annotation
426
- *
427
- * @return string
428
426
*/
429
- private function buildAnnotationLine (string $ annotationClass , array $ options )
427
+ private function buildAnnotationLine (string $ annotationClass , array $ options ): string
430
428
{
431
429
$ formattedOptions = array_map (function ($ option , $ value ) {
432
430
if (\is_array ($ value )) {
@@ -472,7 +470,7 @@ private function quoteAnnotationValue($value)
472
470
return sprintf ('"%s" ' , $ value );
473
471
}
474
472
475
- private function addSingularRelation (BaseRelation $ relation )
473
+ private function addSingularRelation (BaseRelation $ relation ): void
476
474
{
477
475
$ typeHint = $ this ->addUseStatementIfNecessary ($ relation ->getTargetClassName ());
478
476
if ($ relation ->getTargetClassName () == $ this ->getThisFullClassName ()) {
@@ -550,7 +548,7 @@ private function addSingularRelation(BaseRelation $relation)
550
548
$ this ->addMethod ($ setterNodeBuilder ->getNode ());
551
549
}
552
550
553
- private function addCollectionRelation (BaseCollectionRelation $ relation )
551
+ private function addCollectionRelation (BaseCollectionRelation $ relation ): void
554
552
{
555
553
$ typeHint = $ relation ->isSelfReferencing () ? 'self ' : $ this ->addUseStatementIfNecessary ($ relation ->getTargetClassName ());
556
554
@@ -730,7 +728,7 @@ private function addCollectionRelation(BaseCollectionRelation $relation)
730
728
$ this ->addMethod ($ removerNodeBuilder ->getNode ());
731
729
}
732
730
733
- private function addStatementToConstructor (Node \Stmt $ stmt )
731
+ private function addStatementToConstructor (Node \Stmt $ stmt ): void
734
732
{
735
733
if (!$ this ->getConstructorNode ()) {
736
734
$ constructorNode = (new Builder \Method ('__construct ' ))->makePublic ()->getNode ();
@@ -756,11 +754,9 @@ private function addStatementToConstructor(Node\Stmt $stmt)
756
754
}
757
755
758
756
/**
759
- * @return Node\Stmt\ClassMethod|null
760
- *
761
757
* @throws \Exception
762
758
*/
763
- private function getConstructorNode ()
759
+ private function getConstructorNode (): ? Node \ Stmt \ ClassMethod
764
760
{
765
761
foreach ($ this ->getClassNode ()->stmts as $ classNode ) {
766
762
if ($ classNode instanceof Node \Stmt \ClassMethod && '__construct ' == $ classNode ->name ) {
@@ -849,7 +845,7 @@ public function addUseStatementIfNecessary(string $class): string
849
845
return $ shortClassName ;
850
846
}
851
847
852
- private function updateSourceCodeFromNewStmts ()
848
+ private function updateSourceCodeFromNewStmts (): void
853
849
{
854
850
$ newCode = $ this ->printer ->printFormatPreserving (
855
851
$ this ->newStmts ,
@@ -879,7 +875,7 @@ private function updateSourceCodeFromNewStmts()
879
875
$ this ->setSourceCode ($ newCode );
880
876
}
881
877
882
- private function setSourceCode (string $ sourceCode )
878
+ private function setSourceCode (string $ sourceCode ): void
883
879
{
884
880
$ this ->sourceCode = $ sourceCode ;
885
881
$ this ->oldStmts = $ this ->parser ->parse ($ sourceCode );
@@ -919,10 +915,7 @@ private function getNamespaceNode(): Node\Stmt\Namespace_
919
915
return $ node ;
920
916
}
921
917
922
- /**
923
- * @return Node|null
924
- */
925
- private function findFirstNode (callable $ filterCallback )
918
+ private function findFirstNode (callable $ filterCallback ): ?Node
926
919
{
927
920
$ traverser = new NodeTraverser ();
928
921
$ visitor = new NodeVisitor \FirstFindingVisitor ($ filterCallback );
@@ -932,10 +925,7 @@ private function findFirstNode(callable $filterCallback)
932
925
return $ visitor ->getFoundNode ();
933
926
}
934
927
935
- /**
936
- * @return Node|null
937
- */
938
- private function findLastNode (callable $ filterCallback , array $ ast )
928
+ private function findLastNode (callable $ filterCallback , array $ ast ): ?Node
939
929
{
940
930
$ traverser = new NodeTraverser ();
941
931
$ visitor = new NodeVisitor \FindingVisitor ($ filterCallback );
@@ -980,7 +970,7 @@ private function createBlankLineNode(string $context)
980
970
}
981
971
}
982
972
983
- private function createSingleLineCommentNode (string $ comment , string $ context )
973
+ private function createSingleLineCommentNode (string $ comment , string $ context ): Node \ Stmt
984
974
{
985
975
$ this ->pendingComments [] = $ comment ;
986
976
switch ($ context ) {
@@ -997,7 +987,7 @@ private function createSingleLineCommentNode(string $comment, string $context)
997
987
}
998
988
}
999
989
1000
- private function createDocBlock (array $ commentLines )
990
+ private function createDocBlock (array $ commentLines ): string
1001
991
{
1002
992
$ docBlock = "/** \n" ;
1003
993
foreach ($ commentLines as $ commentLine ) {
@@ -1013,7 +1003,7 @@ private function createDocBlock(array $commentLines)
1013
1003
return $ docBlock ;
1014
1004
}
1015
1005
1016
- private function addMethod (Node \Stmt \ClassMethod $ methodNode )
1006
+ private function addMethod (Node \Stmt \ClassMethod $ methodNode ): void
1017
1007
{
1018
1008
$ classNode = $ this ->getClassNode ();
1019
1009
$ methodName = $ methodNode ->name ;
@@ -1058,7 +1048,7 @@ private function addMethod(Node\Stmt\ClassMethod $methodNode)
1058
1048
$ this ->updateSourceCodeFromNewStmts ();
1059
1049
}
1060
1050
1061
- private function makeMethodFluent (Builder \Method $ methodBuilder )
1051
+ private function makeMethodFluent (Builder \Method $ methodBuilder ): void
1062
1052
{
1063
1053
if (!$ this ->fluentMutators ) {
1064
1054
return ;
@@ -1071,7 +1061,7 @@ private function makeMethodFluent(Builder\Method $methodBuilder)
1071
1061
$ methodBuilder ->setReturnType ('self ' );
1072
1062
}
1073
1063
1074
- private function getEntityTypeHint ($ doctrineType )
1064
+ private function getEntityTypeHint ($ doctrineType ): ? string
1075
1065
{
1076
1066
switch ($ doctrineType ) {
1077
1067
case 'string ' :
@@ -1120,7 +1110,7 @@ private function getEntityTypeHint($doctrineType)
1120
1110
}
1121
1111
}
1122
1112
1123
- private function isInSameNamespace ($ class )
1113
+ private function isInSameNamespace ($ class ): bool
1124
1114
{
1125
1115
$ namespace = substr ($ class , 0 , strrpos ($ class , '\\' ));
1126
1116
@@ -1137,7 +1127,7 @@ private function getThisFullClassName(): string
1137
1127
*
1138
1128
* Useful for adding properties, or adding a constructor.
1139
1129
*/
1140
- private function addNodeAfterProperties (Node $ newNode )
1130
+ private function addNodeAfterProperties (Node $ newNode ): void
1141
1131
{
1142
1132
$ classNode = $ this ->getClassNode ();
1143
1133
@@ -1185,12 +1175,12 @@ private function addNodeAfterProperties(Node $newNode)
1185
1175
$ this ->updateSourceCodeFromNewStmts ();
1186
1176
}
1187
1177
1188
- private function createNullConstant ()
1178
+ private function createNullConstant (): Node \ Expr \ ConstFetch
1189
1179
{
1190
1180
return new Node \Expr \ConstFetch (new Node \Name ('null ' ));
1191
1181
}
1192
1182
1193
- private function addNodesToSetOtherSideOfOneToOne (RelationOneToOne $ relation , Builder \Method $ setterNodeBuilder )
1183
+ private function addNodesToSetOtherSideOfOneToOne (RelationOneToOne $ relation , Builder \Method $ setterNodeBuilder ): void
1194
1184
{
1195
1185
if (!$ relation ->isNullable ()) {
1196
1186
$ setterNodeBuilder ->addStmt ($ this ->createSingleLineCommentNode (
@@ -1302,7 +1292,7 @@ private function getMethodIndex(string $methodName)
1302
1292
return false ;
1303
1293
}
1304
1294
1305
- private function propertyExists (string $ propertyName )
1295
+ private function propertyExists (string $ propertyName ): bool
1306
1296
{
1307
1297
foreach ($ this ->getClassNode ()->stmts as $ i => $ node ) {
1308
1298
if ($ node instanceof Node \Stmt \Property && $ node ->props [0 ]->name ->toString () === $ propertyName ) {
@@ -1313,14 +1303,14 @@ private function propertyExists(string $propertyName)
1313
1303
return false ;
1314
1304
}
1315
1305
1316
- private function writeNote (string $ note )
1306
+ private function writeNote (string $ note ): void
1317
1307
{
1318
1308
if (null !== $ this ->io ) {
1319
1309
$ this ->io ->text ($ note );
1320
1310
}
1321
1311
}
1322
1312
1323
- private function addMethodParams (Builder \Method $ methodBuilder , array $ params )
1313
+ private function addMethodParams (Builder \Method $ methodBuilder , array $ params ): void
1324
1314
{
1325
1315
foreach ($ params as $ param ) {
1326
1316
$ methodBuilder ->addParam ($ param );
0 commit comments