@@ -49,6 +49,9 @@ |
||
49 | 49 | return new static($name); |
50 | 50 | } |
51 | 51 | |
52 | + /** |
|
53 | + * @param string $name |
|
54 | + */ |
|
52 | 55 | public function __construct($name) { |
53 | 56 | parent::__construct($name); |
54 | 57 | $this->initParameters(); |
@@ -17,6 +17,9 @@ |
||
17 | 17 | private $visitors; |
18 | 18 | private $filename; |
19 | 19 | |
20 | + /** |
|
21 | + * @param string $filename |
|
22 | + */ |
|
20 | 23 | public function __construct($filename) { |
21 | 24 | $this->filename = $filename; |
22 | 25 | $this->visitors = new Set(); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * Returns whether this node is a boolean value |
75 | 75 | * |
76 | 76 | * @param Node $node |
77 | - * @return bool |
|
77 | + * @return boolean|null |
|
78 | 78 | */ |
79 | 79 | private function isBool(Node $node) { |
80 | 80 | if ($node instanceof ConstFetch) { |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * Returns whether this node is a null value |
92 | 92 | * |
93 | 93 | * @param Node $node |
94 | - * @return bool |
|
94 | + * @return boolean|null |
|
95 | 95 | */ |
96 | 96 | private function isNull(Node $node) { |
97 | 97 | if ($node instanceof ConstFetch) { |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * Returns the value from a node |
105 | 105 | * |
106 | 106 | * @param Node $node |
107 | - * @return mixed |
|
107 | + * @return string |
|
108 | 108 | */ |
109 | 109 | private function getExpression(Node $node) { |
110 | 110 | if ($node instanceof ConstFetch) { |
@@ -31,7 +31,7 @@ |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | if ($prevNode && $prevNode->getLine() && $node->getLine()) { |
34 | - $diff = $node->getLine()- $prevNode->getLine(); |
|
34 | + $diff = $node->getLine() - $prevNode->getLine(); |
|
35 | 35 | if ($diff > 0) { |
36 | 36 | $result .= str_repeat("\n", $diff - 1); |
37 | 37 | } |
@@ -9,26 +9,26 @@ discard block |
||
9 | 9 | |
10 | 10 | class PrettyPrinter extends Standard { |
11 | 11 | |
12 | - /** |
|
13 | - * Pretty prints an array of nodes (statements) and indents them optionally. |
|
14 | - * |
|
15 | - * @param Node[] $nodes Array of nodes |
|
16 | - * @param bool $indent Whether to indent the printed nodes |
|
17 | - * |
|
18 | - * @return string Pretty printed statements |
|
19 | - */ |
|
20 | - protected function pStmts(array $nodes, bool $indent = true): string { |
|
21 | - $result = ''; |
|
12 | + /** |
|
13 | + * Pretty prints an array of nodes (statements) and indents them optionally. |
|
14 | + * |
|
15 | + * @param Node[] $nodes Array of nodes |
|
16 | + * @param bool $indent Whether to indent the printed nodes |
|
17 | + * |
|
18 | + * @return string Pretty printed statements |
|
19 | + */ |
|
20 | + protected function pStmts(array $nodes, bool $indent = true): string { |
|
21 | + $result = ''; |
|
22 | 22 | $prevNode = null; |
23 | 23 | |
24 | - foreach ($nodes as $node) { |
|
25 | - $comments = $node->getAttribute('comments', []); |
|
26 | - if ($comments) { |
|
27 | - $result .= "\n" . $this->pComments($comments); |
|
28 | - if ($node instanceof Stmt\Nop) { |
|
29 | - continue; |
|
30 | - } |
|
31 | - } |
|
24 | + foreach ($nodes as $node) { |
|
25 | + $comments = $node->getAttribute('comments', []); |
|
26 | + if ($comments) { |
|
27 | + $result .= "\n" . $this->pComments($comments); |
|
28 | + if ($node instanceof Stmt\Nop) { |
|
29 | + continue; |
|
30 | + } |
|
31 | + } |
|
32 | 32 | |
33 | 33 | if ($prevNode && $prevNode->getLine() && $node->getLine()) { |
34 | 34 | $diff = $node->getLine()- $prevNode->getLine(); |
@@ -37,16 +37,16 @@ discard block |
||
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | - $result .= "\n" . $this->p($node) . ($node instanceof Expr ? ';' : ''); |
|
40 | + $result .= "\n" . $this->p($node) . ($node instanceof Expr ? ';' : ''); |
|
41 | 41 | $prevNode = $node; |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | 44 | if ($indent) { |
45 | - return preg_replace('~\n(?!$)~', "\n ", $result); |
|
46 | - } else { |
|
47 | - return $result; |
|
48 | - } |
|
49 | - } |
|
45 | + return preg_replace('~\n(?!$)~', "\n ", $result); |
|
46 | + } else { |
|
47 | + return $result; |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | 51 | public function pExpr_Array(Array_ $node) { |
52 | 52 | return '[' . $this->pCommaSeparated($node->items) . ']'; |
@@ -28,7 +28,7 @@ |
||
28 | 28 | |
29 | 29 | /** |
30 | 30 | * |
31 | - * @param AbstractModel|TypePart $model |
|
31 | + * @param AbstractModel $model |
|
32 | 32 | * @param bool $allowed |
33 | 33 | * |
34 | 34 | * @return string|null |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | 'string', 'int', 'integer', 'bool', 'boolean', 'float', 'double', 'object', 'mixed', 'resource' |
13 | 13 | ]; |
14 | 14 | |
15 | - protected static $php7typeHints = [ |
|
15 | + protected static $php7typeHints = [ |
|
16 | 16 | 'string', 'int', 'integer', 'bool', 'boolean', 'float', 'double' |
17 | 17 | ]; |
18 | 18 | |
@@ -36,15 +36,15 @@ discard block |
||
36 | 36 | private function getType(AbstractModel $model, bool $allowed, bool $nullable): ?string { |
37 | 37 | $types = $model->getTypes(); |
38 | 38 | if (!$types || $types->size() !== 1) { |
39 | - return null; |
|
40 | - } |
|
39 | + return null; |
|
40 | + } |
|
41 | 41 | $type = (string)$types->values()->toArray()[0]; |
42 | 42 | if (!in_array($type, self::$noTypeHints, true) |
43 | - || ($allowed && in_array($type, self::$php7typeHints, true))) { |
|
43 | + || ($allowed && in_array($type, self::$php7typeHints, true))) { |
|
44 | 44 | |
45 | - $type = self::$typeHintMap[$type] ?? $type; |
|
45 | + $type = self::$typeHintMap[$type] ?? $type; |
|
46 | 46 | |
47 | - if ($nullable && $model->getNullable()) { |
|
47 | + if ($nullable && $model->getNullable()) { |
|
48 | 48 | $type = '?' . $type; |
49 | 49 | } |
50 | 50 |
@@ -38,7 +38,7 @@ |
||
38 | 38 | if (!$types || $types->size() !== 1) { |
39 | 39 | return null; |
40 | 40 | } |
41 | - $type = (string)$types->values()->toArray()[0]; |
|
41 | + $type = (string) $types->values()->toArray()[0]; |
|
42 | 42 | if (!in_array($type, self::$noTypeHints, true) |
43 | 43 | || ($allowed && in_array($type, self::$php7typeHints, true))) { |
44 | 44 |
@@ -33,8 +33,7 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * Sets the type |
35 | 35 | * |
36 | - * @param null|string|PhpTypeInterface[] $type |
|
37 | - * @param string $description |
|
36 | + * @param null|string|PhpTypeInterface[] $types |
|
38 | 37 | * @return $this |
39 | 38 | */ |
40 | 39 | public function setTypes(iterable $types) { |
@@ -50,7 +49,6 @@ discard block |
||
50 | 49 | * adds a type |
51 | 50 | * |
52 | 51 | * @param string|PhpTypeInterface $type |
53 | - * @param string $description |
|
54 | 52 | * @return $this |
55 | 53 | */ |
56 | 54 | public function addType($type) { |
@@ -27,8 +27,8 @@ discard block |
||
27 | 27 | private $typeNullable = false; |
28 | 28 | |
29 | 29 | public function initTypes(): void { |
30 | - $this->types = new Map(); |
|
31 | - } |
|
30 | + $this->types = new Map(); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Sets the type |
@@ -37,13 +37,13 @@ discard block |
||
37 | 37 | * @param string $description |
38 | 38 | * @return $this |
39 | 39 | */ |
40 | - public function setTypes(iterable $types) { |
|
41 | - $this->types->clear(); |
|
42 | - foreach ($types as $type) { |
|
43 | - $this->addType($type); |
|
44 | - } |
|
40 | + public function setTypes(iterable $types) { |
|
41 | + $this->types->clear(); |
|
42 | + foreach ($types as $type) { |
|
43 | + $this->addType($type); |
|
44 | + } |
|
45 | 45 | |
46 | - return $this; |
|
46 | + return $this; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -54,17 +54,17 @@ discard block |
||
54 | 54 | * @return $this |
55 | 55 | */ |
56 | 56 | public function addType($type) { |
57 | - if ($type === 'null') { |
|
58 | - $this->setNullable(true); |
|
59 | - return $this; |
|
60 | - } |
|
61 | - if ($type) { |
|
62 | - if (!$type instanceof PhpTypeInterface) { |
|
63 | - $type = new PhpType($type); |
|
64 | - } |
|
65 | - |
|
66 | - $this->types->set($type->getQualifiedName(), $type); |
|
67 | - } |
|
57 | + if ($type === 'null') { |
|
58 | + $this->setNullable(true); |
|
59 | + return $this; |
|
60 | + } |
|
61 | + if ($type) { |
|
62 | + if (!$type instanceof PhpTypeInterface) { |
|
63 | + $type = new PhpType($type); |
|
64 | + } |
|
65 | + |
|
66 | + $this->types->set($type->getQualifiedName(), $type); |
|
67 | + } |
|
68 | 68 | |
69 | 69 | return $this; |
70 | 70 | } |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | * @return $this |
77 | 77 | */ |
78 | 78 | public function setTypeDescription(string $description) { |
79 | - if (!$description) { |
|
80 | - return $this; |
|
81 | - } |
|
79 | + if (!$description) { |
|
80 | + return $this; |
|
81 | + } |
|
82 | 82 | $this->typeDescription = $description; |
83 | 83 | return $this; |
84 | 84 | } |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | public function getTypeExpression(): ?string { |
96 | - return TypeUtils::typesToExpression($this->types); |
|
97 | - } |
|
96 | + return TypeUtils::typesToExpression($this->types); |
|
97 | + } |
|
98 | 98 | |
99 | 99 | /** |
100 | 100 | * Returns the type description |
@@ -79,7 +79,6 @@ |
||
79 | 79 | /** |
80 | 80 | * Sets the parent class name |
81 | 81 | * |
82 | - * @param PhpClass|string|null $name the new parent |
|
83 | 82 | * @return $this |
84 | 83 | */ |
85 | 84 | public function setParentClassName($parent) { |
@@ -71,10 +71,10 @@ discard block |
||
71 | 71 | return $this->parentClassName; |
72 | 72 | } |
73 | 73 | |
74 | - public function getParentClass(): PhpClass { |
|
75 | - return class_exists($this->parentClassName) ? |
|
76 | - self::fromName($this->parentClassName) : PhpClass::create($this->parentClassName); |
|
77 | - } |
|
74 | + public function getParentClass(): PhpClass { |
|
75 | + return class_exists($this->parentClassName) ? |
|
76 | + self::fromName($this->parentClassName) : PhpClass::create($this->parentClassName); |
|
77 | + } |
|
78 | 78 | |
79 | 79 | /** |
80 | 80 | * Sets the parent class name |
@@ -84,12 +84,12 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function setParentClassName($parent) { |
86 | 86 | if ($parent instanceof PhpClass) { |
87 | - $this->addUseStatement($parent->getQualifiedName()); |
|
88 | - $parent = $parent->getName(); |
|
89 | - } |
|
90 | - $this->parentClassName = $parent; |
|
87 | + $this->addUseStatement($parent->getQualifiedName()); |
|
88 | + $parent = $parent->getName(); |
|
89 | + } |
|
90 | + $this->parentClassName = $parent; |
|
91 | 91 | |
92 | - return $this; |
|
92 | + return $this; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | public function generateDocblock(): void { |
@@ -4,11 +4,23 @@ |
||
4 | 4 | |
5 | 5 | interface PhpTypeInterface extends NamespaceInterface |
6 | 6 | { |
7 | + /** |
|
8 | + * @return string |
|
9 | + */ |
|
7 | 10 | public function getName(): ?string; |
8 | 11 | |
12 | + /** |
|
13 | + * @return string |
|
14 | + */ |
|
9 | 15 | public function getQualifiedName(): ?string; |
10 | 16 | |
17 | + /** |
|
18 | + * @return parts\NamePart |
|
19 | + */ |
|
11 | 20 | public function setName(?string $name); |
12 | 21 | |
22 | + /** |
|
23 | + * @return parts\QualifiedNamePart |
|
24 | + */ |
|
13 | 25 | public function setQualifiedName(?string $qualifiedName); |
14 | 26 | } |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | interface PhpTypeInterface extends NamespaceInterface |
6 | 6 | { |
7 | - public function getName(): ?string; |
|
7 | + public function getName(): ?string; |
|
8 | 8 | |
9 | - public function getQualifiedName(): ?string; |
|
9 | + public function getQualifiedName(): ?string; |
|
10 | 10 | |
11 | - public function setName(?string $name); |
|
11 | + public function setName(?string $name); |
|
12 | 12 | |
13 | - public function setQualifiedName(?string $qualifiedName); |
|
13 | + public function setQualifiedName(?string $qualifiedName); |
|
14 | 14 | } |
@@ -2,8 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace gossi\codegen\model; |
4 | 4 | |
5 | -interface PhpTypeInterface extends NamespaceInterface |
|
6 | -{ |
|
5 | +interface PhpTypeInterface extends NamespaceInterface { |
|
7 | 6 | public function getName(): ?string; |
8 | 7 | |
9 | 8 | public function getQualifiedName(): ?string; |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * A quick way to add a parameter which is created from the given parameters |
36 | 36 | * |
37 | 37 | * @param string $name |
38 | - * @param string[]|PhpTypeInterface[] $types |
|
38 | + * @param string[]|PhpTypeInterface[] $type |
|
39 | 39 | * @param mixed $defaultValue omit the argument to define no default value |
40 | 40 | * |
41 | 41 | * @return $this |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * A quick way to add a parameter with description which is created from the given parameters |
47 | 47 | * |
48 | 48 | * @param string $name |
49 | - * @param string[]|PhpTypeInterface[] $types |
|
49 | + * @param string[]|PhpTypeInterface[] $type |
|
50 | 50 | * @param null|string $typeDescription |
51 | 51 | * @param mixed $defaultValue omit the argument to define no default value |
52 | 52 | * |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | /** |
85 | 85 | * Returns a collection of parameters |
86 | 86 | * |
87 | - * @return array |
|
87 | + * @return PhpParameter[] |
|
88 | 88 | */ |
89 | 89 | public function getParameters(); |
90 | 90 |