Skip to content

Commit c77af75

Browse files
committed
fix code issues, some more phpdoc
1 parent d075bd0 commit c77af75

10 files changed

Lines changed: 154 additions & 13 deletions

File tree

src/generator/CodeGenerator.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class CodeGenerator {
2323

2424
/** @var CodeGeneratorConfig */
2525
protected $config;
26+
27+
/** @var ModelGenerator */
28+
protected $generator;
2629

2730
/**
2831
*
@@ -59,12 +62,7 @@ public function getConfig() {
5962
* @return string the generated code
6063
*/
6164
public function generate(GenerateableInterface $model) {
62-
// if ($this->config->getGenerateDocblock()) {
63-
// $model->generateDocblock();
64-
// }
65-
66-
$generator = new ModelGenerator($this->config);
67-
return $generator->generate($model);
65+
return $this->generator->generate($model);
6866
}
6967

7068
}

src/generator/builder/AbstractBuilder.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,30 @@ public function __construct(ModelGenerator $generator) {
2929
* @param AbstractModel $model
3030
* @return void
3131
*/
32-
public abstract function build($model);
32+
abstract public function build(AbstractModel $model);
3333

34+
/**
35+
* @param AbstractModel $model
36+
* @return void
37+
*/
3438
protected function generate(AbstractModel $model) {
3539
$builder = $this->generator->getFactory()->getBuilder($model);
3640
$builder->build($model);
3741
}
3842

43+
/**
44+
* @return void
45+
*/
3946
protected function ensureBlankLine() {
4047
if (!$this->writer->endsWith("\n\n") && strlen($this->writer->rtrim()->getContent()) > 0) {
4148
$this->writer->writeln();
4249
}
4350
}
4451

52+
/**
53+
* @param DocblockInterface $model
54+
* @return void
55+
*/
4556
protected function buildDocblock(DocblockInterface $model) {
4657
$this->ensureBlankLine();
4758
if ($this->config->getGenerateDocblock()) {

src/generator/builder/MethodBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use gossi\codegen\generator\builder\parts\RoutineBuilderPart;
55
use gossi\codegen\model\AbstractModel;
6+
use gossi\codegen\model\PhpInterface;
67

78
class MethodBuilder extends AbstractBuilder {
89

src/generator/builder/parts/RoutineBuilderPart.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
use TypeBuilderPart;
1010

11+
/**
12+
* @param AbstractModel $model
13+
* @return void
14+
*/
1115
protected abstract function generate(AbstractModel $model);
1216

1317
protected function writeFunctionStatement(RoutineInterface $model) {
@@ -45,6 +49,6 @@ protected function writeFunctionReturnType(RoutineInterface $model) {
4549
protected function writeBody(RoutineInterface $model) {
4650
$this->writer->writeln(' {')->indent();
4751
$this->writer->writeln(trim($model->getBody()));
48-
$this->writer->outdent()->rtrim()->writeln("}");
52+
$this->writer->outdent()->rtrim()->writeln('}');
4953
}
5054
}

src/generator/builder/parts/StructBuilderPart.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
<?php
22
namespace gossi\codegen\generator\builder\parts;
33

4+
use gossi\codegen\generator\ComparatorFactory;
45
use gossi\codegen\model\AbstractModel;
56
use gossi\codegen\model\AbstractPhpStruct;
67
use gossi\codegen\model\ConstantsInterface;
8+
use gossi\codegen\model\DocblockInterface;
79
use gossi\codegen\model\NamespaceInterface;
810
use gossi\codegen\model\PropertiesInterface;
911
use gossi\codegen\model\TraitsInterface;
10-
use gossi\codegen\generator\ComparatorFactory;
1112

1213
trait StructBuilderPart {
1314

14-
protected abstract function ensureBlankLine();
15-
protected abstract function generate(AbstractModel $model);
15+
/**
16+
* @return void
17+
*/
18+
abstract protected function ensureBlankLine();
19+
20+
/**
21+
* @param AbstractModel $model
22+
* @return void
23+
*/
24+
abstract protected function generate(AbstractModel $model);
25+
26+
/**
27+
* @param DocblockInterface $model
28+
* @return void
29+
*/
30+
abstract protected function buildDocblock(DocblockInterface $model);
1631

1732
protected function buildHeader(AbstractPhpStruct $model) {
1833
$this->buildNamespace($model);

src/generator/builder/parts/TypeBuilderPart.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ trait TypeBuilderPart {
2323
'double' => 'float'
2424
];
2525

26+
/**
27+
*
28+
* @param AbstractModel $model
29+
* @param bool $allowed
30+
* @return string|null
31+
*/
2632
private function getType(AbstractModel $model, $allowed) {
2733
$type = $model->getType();
2834
if (!empty($type) && strpos($type, '|') === false

src/model/RoutineInterface.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33

44
interface RoutineInterface {
55

6+
/**
7+
* Sets a collection of parameters
8+
*
9+
* Note: clears all parameters before setting the new ones
10+
*
11+
* @param PhpParameter[] $parameters
12+
* @return $this
13+
*/
614
public function setParameters(array $parameters);
715

816
/**
@@ -66,7 +74,7 @@ public function replaceParameter($position, PhpParameter $parameter);
6674
/**
6775
* Remove a parameter at a given position
6876
*
69-
* @param int|string|PhpParameter $position
77+
* @param int|string|PhpParameter $param
7078
* @return $this
7179
*/
7280
public function removeParameter($param);

src/model/parts/ParametersPart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function replaceParameter($position, PhpParameter $parameter) {
149149
/**
150150
* Remove a parameter at a given position
151151
*
152-
* @param int|string|PhpParameter $position
152+
* @param int|string|PhpParameter $param
153153
* @return $this
154154
*/
155155
public function removeParameter($param) {

src/parser/visitor/ParserVisitorInterface.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,92 @@
1616

1717
interface ParserVisitorInterface {
1818

19+
/**
20+
* Visit a struct
21+
*
22+
* @param ClassLike $node
23+
* @return void
24+
*/
1925
public function visitStruct(ClassLike $node);
2026

27+
/**
28+
* Visit a class
29+
*
30+
* @param Class_ $node
31+
* @return void
32+
*/
2133
public function visitClass(Class_ $node);
2234

35+
/**
36+
* Visit an interface
37+
*
38+
* @param Interface_ $node
39+
* @return void
40+
*/
2341
public function visitInterface(Interface_ $node);
2442

43+
/**
44+
* Visit a trait
45+
*
46+
* @param Trait_ $node
47+
* @return void
48+
*/
2549
public function visitTrait(Trait_ $node);
2650

51+
/**
52+
* Visit a use statement inside a struct
53+
*
54+
* @param TraitUse $node
55+
* @return void
56+
*/
2757
public function visitTraitUse(TraitUse $node);
2858

59+
/**
60+
* Visit class constants
61+
*
62+
* @param ClassConst $node
63+
* @return void
64+
*/
2965
public function visitConstants(ClassConst $node);
3066

67+
/**
68+
* Visit a constant
69+
*
70+
* @param Const_ $node
71+
* @param Doc $doc
72+
* @return void
73+
*/
3174
public function visitConstant(Const_ $node, Doc $doc = null);
3275

76+
/**
77+
* Visit a property
78+
*
79+
* @param Property $node
80+
* @return void
81+
*/
3382
public function visitProperty(Property $node);
3483

84+
/**
85+
* Visit a namespace statement
86+
*
87+
* @param Namespace_ $node
88+
* @return void
89+
*/
3590
public function visitNamespace(Namespace_ $node);
3691

92+
/**
93+
* Visit a use statement
94+
*
95+
* @param UseUse $node
96+
* @return void
97+
*/
3798
public function visitUseStatement(UseUse $node);
3899

100+
/**
101+
* Visit a method
102+
*
103+
* @param ClassMethod $node
104+
* @return void
105+
*/
39106
public function visitMethod(ClassMethod $node);
40107
}

src/parser/visitor/parts/ValueParserPart.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ trait ValueParserPart {
2020
'true' => true
2121
];
2222

23+
/**
24+
* Parses the value of a node into the model
25+
*
26+
* @param ValueInterface $obj
27+
* @param Node $node
28+
* @return void
29+
*/
2330
private function parseValue(ValueInterface $obj, Node $node) {
2431
$value = $node instanceof Const_ ? $node->value : $node->default;
2532
if ($value !== null) {
@@ -31,6 +38,12 @@ private function parseValue(ValueInterface $obj, Node $node) {
3138
}
3239
}
3340

41+
/**
42+
* Returns whether this node is a primitive value
43+
*
44+
* @param Node $node
45+
* @return boolean
46+
*/
3447
private function isPrimitive(Node $node) {
3548
return $node instanceof String_
3649
|| $node instanceof LNumber
@@ -39,6 +52,12 @@ private function isPrimitive(Node $node) {
3952
|| $this->isNull($node);
4053
}
4154

55+
/**
56+
* Returns the primitive value
57+
*
58+
* @param Node $node
59+
* @return mixed
60+
*/
4261
private function getPrimitiveValue(Node $node) {
4362
if ($this->isBool($node)) {
4463
return (bool) $this->getExpression($node);
@@ -51,6 +70,12 @@ private function getPrimitiveValue(Node $node) {
5170
return $node->value;
5271
}
5372

73+
/**
74+
* Returns whether this node is a boolean value
75+
*
76+
* @param Node $node
77+
* @return boolean
78+
*/
5479
private function isBool(Node $node) {
5580
if ($node instanceof ConstFetch) {
5681
$const = $node->name->parts[0];
@@ -62,6 +87,12 @@ private function isBool(Node $node) {
6287
}
6388
}
6489

90+
/**
91+
* Returns whether this node is a null value
92+
*
93+
* @param Node $node
94+
* @return boolean
95+
*/
6596
private function isNull(Node $node) {
6697
if ($node instanceof ConstFetch) {
6798
$const = $node->name->parts[0];

0 commit comments

Comments
 (0)