Completed
Pull Request — master (#67)
by
unknown
02:38
created
src/generator/builder/parts/TypeBuilderPart.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/model/PhpClass.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -79,7 +79,6 @@
 block discarded – undo
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) {
Please login to merge, or discard this patch.
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -71,10 +71,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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 {
Please login to merge, or discard this patch.
src/model/RoutineInterface.php 1 patch
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/utils/TypeUtils.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -7,75 +7,75 @@
 block discarded – undo
7 7
 
8 8
 class TypeUtils
9 9
 {
10
-    public static $phpTypes = [
11
-        'string',
12
-        'int',
13
-        'integer',
14
-        'bool',
15
-        'boolean',
16
-        'float',
17
-        'double',
18
-        'object',
19
-        'mixed',
20
-        'resource',
21
-        'iterable',
22
-        'array',
23
-        'callable',
24
-    ];
10
+	public static $phpTypes = [
11
+		'string',
12
+		'int',
13
+		'integer',
14
+		'bool',
15
+		'boolean',
16
+		'float',
17
+		'double',
18
+		'object',
19
+		'mixed',
20
+		'resource',
21
+		'iterable',
22
+		'array',
23
+		'callable',
24
+	];
25 25
 
26
-    public static function expressionToTypes(?string $typeExpression): array {
27
-        if (!$typeExpression) {
28
-            return [];
29
-        }
26
+	public static function expressionToTypes(?string $typeExpression): array {
27
+		if (!$typeExpression) {
28
+			return [];
29
+		}
30 30
 
31
-        return explode('|', $typeExpression);
32
-    }
31
+		return explode('|', $typeExpression);
32
+	}
33 33
 
34
-    public static function guessQualifiedName(AbstractPhpStruct $stuct, string $type): string {
35
-        if (in_array($type, self::$phpTypes, true)) {
36
-            return $type;
37
-        }
34
+	public static function guessQualifiedName(AbstractPhpStruct $stuct, string $type): string {
35
+		if (in_array($type, self::$phpTypes, true)) {
36
+			return $type;
37
+		}
38 38
 
39
-        $suffix = '';
40
-        if (strpos($type, '[]') !== false) {
41
-            $type = str_replace('[]', '', $type);
42
-            $suffix = '[]';
43
-        }
39
+		$suffix = '';
40
+		if (strpos($type, '[]') !== false) {
41
+			$type = str_replace('[]', '', $type);
42
+			$suffix = '[]';
43
+		}
44 44
 
45
-        $uses = $stuct->getUseStatements();
46
-        foreach ($uses as $use) {
47
-            $regexp = '/\\\\' . preg_quote($type, '/') . '$/';
48
-            if (preg_match($regexp, $use)) {
49
-                return $use . $suffix;
50
-            }
51
-        }
45
+		$uses = $stuct->getUseStatements();
46
+		foreach ($uses as $use) {
47
+			$regexp = '/\\\\' . preg_quote($type, '/') . '$/';
48
+			if (preg_match($regexp, $use)) {
49
+				return $use . $suffix;
50
+			}
51
+		}
52 52
 
53
-        $sameNamespace = $stuct->getNamespace() . '\\' . $type;
54
-        if (class_exists($sameNamespace)) {
55
-            return $sameNamespace . $suffix;
56
-        }
53
+		$sameNamespace = $stuct->getNamespace() . '\\' . $type;
54
+		if (class_exists($sameNamespace)) {
55
+			return $sameNamespace . $suffix;
56
+		}
57 57
 
58
-        return $type . $suffix;
59
-    }
58
+		return $type . $suffix;
59
+	}
60 60
 
61
-    public static function isGlobalQualifiedName(string $name): bool {
62
-        return $name[0] === '\\' && substr_count($name, '\\') === 1;
63
-    }
61
+	public static function isGlobalQualifiedName(string $name): bool {
62
+		return $name[0] === '\\' && substr_count($name, '\\') === 1;
63
+	}
64 64
 
65
-    public static function isNativeType(string $type): bool {
66
-        return in_array($type, self::$phpTypes, true);
67
-    }
65
+	public static function isNativeType(string $type): bool {
66
+		return in_array($type, self::$phpTypes, true);
67
+	}
68 68
 
69
-    public static function typesToExpression(iterable $types): ?string {
70
-        $typeExpr = '';
71
-        foreach ($types as $type) {
72
-            $typeExpr .= '|' . $type;
73
-        }
69
+	public static function typesToExpression(iterable $types): ?string {
70
+		$typeExpr = '';
71
+		foreach ($types as $type) {
72
+			$typeExpr .= '|' . $type;
73
+		}
74 74
 
75
-        if (!$typeExpr) {
76
-            return null;
77
-        }
75
+		if (!$typeExpr) {
76
+			return null;
77
+		}
78 78
 
79
-        return trim($typeExpr, '|');
80
-    }
79
+		return trim($typeExpr, '|');
80
+	}
81 81
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,8 +5,7 @@
 block discarded – undo
5 5
 
6 6
 use gossi\codegen\model\AbstractPhpStruct;
7 7
 
8
-class TypeUtils
9
-{
8
+class TypeUtils {
10 9
     public static $phpTypes = [
11 10
         'string',
12 11
         'int',
Please login to merge, or discard this patch.
src/model/AbstractPhpStruct.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -57,12 +57,12 @@  discard block
 block discarded – undo
57 57
 		return new static($name);
58 58
 	}
59 59
 
60
-    public static function fromName(string $name): self
61
-    {
62
-        $ref = new \ReflectionClass($name);
60
+	public static function fromName(string $name): self
61
+	{
62
+		$ref = new \ReflectionClass($name);
63 63
 
64
-        return static::fromFile($ref->getFileName());
65
-    }
64
+		return static::fromFile($ref->getFileName());
65
+	}
66 66
 
67 67
 	/**
68 68
 	 * Creates a new struct
@@ -135,17 +135,17 @@  discard block
 block discarded – undo
135 135
 	 * @return $this
136 136
 	 */
137 137
 	public function addUseStatement($qualifiedName, string $alias = null) {
138
-        if ($qualifiedName instanceof PhpTypeInterface) {
139
-            $qualifiedName = $qualifiedName->getQualifiedName();
140
-        }
138
+		if ($qualifiedName instanceof PhpTypeInterface) {
139
+			$qualifiedName = $qualifiedName->getQualifiedName();
140
+		}
141 141
 
142
-        if (TypeUtils::isGlobalQualifiedName($qualifiedName) || TypeUtils::isNativeType($qualifiedName)) {
143
-            return $this;
144
-        }
142
+		if (TypeUtils::isGlobalQualifiedName($qualifiedName) || TypeUtils::isNativeType($qualifiedName)) {
143
+			return $this;
144
+		}
145 145
 
146
-	    if ($qualifiedName === $this->getNamespace()) {
147
-	        return $this;
148
-        }
146
+		if ($qualifiedName === $this->getNamespace()) {
147
+			return $this;
148
+		}
149 149
 		if (!is_string($alias)) {
150 150
 			if (false === strpos($qualifiedName, '\\')) {
151 151
 				$alias = $qualifiedName;
@@ -271,24 +271,24 @@  discard block
 block discarded – undo
271 271
 		$method->setParent($this);
272 272
 		$this->methods->set($method->getName(), $method);
273 273
 		$types = $method->getTypes();
274
-        if ($types) {
275
-            foreach ($types as $type) {
276
-                $this->addUseStatement($type);
277
-                $method->addType($type);
278
-            }
279
-        }
280
-
281
-        foreach ($method->getParameters() as $parameter) {
282
-            $types = $parameter->getTypes();
283
-            if ($types) {
284
-                foreach ($types as $type) {
285
-                    $this->addUseStatement($type);
286
-                    $parameter->addType($type);
287
-                }
288
-            }
289
-        }
290
-
291
-        return $this;
274
+		if ($types) {
275
+			foreach ($types as $type) {
276
+				$this->addUseStatement($type);
277
+				$method->addType($type);
278
+			}
279
+		}
280
+
281
+		foreach ($method->getParameters() as $parameter) {
282
+			$types = $parameter->getTypes();
283
+			if ($types) {
284
+				foreach ($types as $type) {
285
+					$this->addUseStatement($type);
286
+					$parameter->addType($type);
287
+				}
288
+			}
289
+		}
290
+
291
+		return $this;
292 292
 	}
293 293
 
294 294
 	/**
Please login to merge, or discard this patch.
src/model/PhpFunction.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -93,8 +93,8 @@
 block discarded – undo
93 93
 		$this->setQualifiedName($name);
94 94
 		$this->docblock = new Docblock();
95 95
 		$this->initParameters();
96
-        $this->initTypes();
97
-    }
96
+		$this->initTypes();
97
+	}
98 98
 
99 99
 	/**
100 100
 	 * @inheritDoc
Please login to merge, or discard this patch.
src/model/AbstractModel.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,8 +33,8 @@
 block discarded – undo
33 33
 			$description = implode("\n", $description);
34 34
 		}
35 35
 		if ($description) {
36
-            $this->description = $description;
37
-        }
36
+			$this->description = $description;
37
+		}
38 38
 		return $this;
39 39
 	}
40 40
 
Please login to merge, or discard this patch.
src/model/PhpTypeInterface.php 3 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,8 +2,7 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
Doc Comments   +12 added lines patch added patch discarded remove patch
@@ -4,12 +4,24 @@
 block discarded – undo
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
 
15 27
     public function __toString(): string;
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -4,13 +4,13 @@
 block discarded – undo
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
 
15
-    public function __toString(): string;
15
+	public function __toString(): string;
16 16
 }
Please login to merge, or discard this patch.
src/model/PhpParameter.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
 	 */
56 56
 	public function __construct($name = null) {
57 57
 		$this->setName($name);
58
-        $this->initTypes();
59
-    }
58
+		$this->initTypes();
59
+	}
60 60
 
61 61
 	/**
62 62
 	 * Sets whether this parameter is passed by reference
@@ -85,16 +85,16 @@  discard block
 block discarded – undo
85 85
 	 * @return ParamTag
86 86
 	 */
87 87
 	public function getDocblockTag(): ParamTag {
88
-        $type = '';
89
-        if ($this->getNullable()) {
90
-            $type = 'null';
91
-        }
92
-        if ($this->getTypes()) {
93
-            if ($type) {
94
-                $type .= '|';
95
-            }
96
-            $type .= TypeUtils::typesToExpression($this->getTypes());
97
-        }
88
+		$type = '';
89
+		if ($this->getNullable()) {
90
+			$type = 'null';
91
+		}
92
+		if ($this->getTypes()) {
93
+			if ($type) {
94
+				$type .= '|';
95
+			}
96
+			$type .= TypeUtils::typesToExpression($this->getTypes());
97
+		}
98 98
 		return ParamTag::create()
99 99
 			->setType($type)
100 100
 			->setVariable($this->getName())
Please login to merge, or discard this patch.