Skip to content

Commit a5c73d2

Browse files
committed
modernize code
1 parent 9247674 commit a5c73d2

File tree

131 files changed

+475
-2382
lines changed

Some content is hidden

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

131 files changed

+475
-2382
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"ext-mbstring": "*"
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit": "^9.4"
23+
"phpunit/phpunit": "^9.4",
24+
"rector/rector": "^1.2"
2425
},
2526
"autoload": {
2627
"psr-4": {

rector.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\EarlyReturn\Rector\If_\ChangeOrIfContinueToMultiContinueRector;
7+
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
8+
use Rector\Php80\Rector\Ternary\GetDebugTypeRector;
9+
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
10+
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\DataProviderArrayItemsNewLinedRector;
11+
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
12+
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;
13+
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictSetUpRector;
14+
15+
return RectorConfig::configure()
16+
->withPaths([
17+
__DIR__ . '/src',
18+
__DIR__ . '/tests',
19+
])
20+
->withPhpSets()
21+
->withPreparedSets(
22+
deadCode: true,
23+
typeDeclarations: true,
24+
privatization: true,
25+
earlyReturn: true,
26+
phpunitCodeQuality: true,
27+
)
28+
->withRules([
29+
ClassPropertyAssignToConstructorPromotionRector::class,
30+
])
31+
->withSkip([
32+
GetDebugTypeRector::class,
33+
ChangeOrIfContinueToMultiContinueRector::class,
34+
YieldDataProviderRector::class,
35+
DataProviderArrayItemsNewLinedRector::class
36+
]);

src/Model/GeneratorConfiguration.php

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ public function __construct()
6565
/**
6666
* Add an additional filter
6767
*
68-
* @param FilterInterface ...$additionalFilter
69-
*
70-
* @return $this
71-
*
7268
* @throws Exception
7369
* @throws InvalidFilterException
7470
*/
@@ -103,11 +99,6 @@ public function addFilter(FilterInterface ...$additionalFilter): self
10399

104100
/**
105101
* Add an additional format
106-
*
107-
* @param string $formatKey
108-
* @param FormatValidatorInterface $format
109-
*
110-
* @return $this
111102
*/
112103
public function addFormat(string $formatKey, FormatValidatorInterface $format): self
113104
{
@@ -116,20 +107,12 @@ public function addFormat(string $formatKey, FormatValidatorInterface $format):
116107
return $this;
117108
}
118109

119-
/**
120-
* @param string $formatKey
121-
*
122-
* @return FormatValidatorInterface|null
123-
*/
124110
public function getFormat(string $formatKey): ?FormatValidatorInterface
125111
{
126112
return $this->formats[$formatKey] ?? null;
127113
}
128114

129115
/**
130-
* @param array $callback
131-
* @param string $message
132-
*
133116
* @throws InvalidFilterException
134117
*/
135118
private function validateFilterCallback(array $callback, string $message): void
@@ -145,209 +128,125 @@ private function validateFilterCallback(array $callback, string $message): void
145128

146129
/**
147130
* Get a filter by the given token
148-
*
149-
* @param string $token
150-
*
151-
* @return FilterInterface|null
152131
*/
153132
public function getFilter(string $token): ?FilterInterface
154133
{
155134
return $this->filter[$token] ?? null;
156135
}
157136

158-
/**
159-
* @return ClassNameGeneratorInterface
160-
*/
161137
public function getClassNameGenerator(): ClassNameGeneratorInterface
162138
{
163139
return $this->classNameGenerator;
164140
}
165141

166-
/**
167-
* @param ClassNameGeneratorInterface $classNameGenerator
168-
*
169-
* @return $this
170-
*/
171142
public function setClassNameGenerator(ClassNameGeneratorInterface $classNameGenerator): self
172143
{
173144
$this->classNameGenerator = $classNameGenerator;
174145

175146
return $this;
176147
}
177148

178-
/**
179-
* @return string
180-
*/
181149
public function getNamespacePrefix(): string
182150
{
183151
return $this->namespacePrefix;
184152
}
185153

186-
/**
187-
* @param string $namespacePrefix
188-
*
189-
* @return $this
190-
*/
191154
public function setNamespacePrefix(string $namespacePrefix): self
192155
{
193156
$this->namespacePrefix = trim($namespacePrefix, '\\');
194157

195158
return $this;
196159
}
197160

198-
/**
199-
* @return bool
200-
*/
201161
public function isDefaultArraysToEmptyArrayEnabled(): bool
202162
{
203163
return $this->defaultArraysToEmptyArray;
204164
}
205165

206-
/**
207-
* @param bool $defaultArraysToEmptyArray
208-
*
209-
* @return GeneratorConfiguration
210-
*/
211166
public function setDefaultArraysToEmptyArray(bool $defaultArraysToEmptyArray): self
212167
{
213168
$this->defaultArraysToEmptyArray = $defaultArraysToEmptyArray;
214169

215170
return $this;
216171
}
217172

218-
/**
219-
* @return bool
220-
*/
221173
public function isImmutable(): bool
222174
{
223175
return $this->immutable;
224176
}
225177

226-
/**
227-
* @param bool $immutable
228-
*
229-
* @return GeneratorConfiguration
230-
*/
231178
public function setImmutable(bool $immutable): self
232179
{
233180
$this->immutable = $immutable;
234181

235182
return $this;
236183
}
237184

238-
/**
239-
* @return bool
240-
*/
241185
public function denyAdditionalProperties(): bool
242186
{
243187
return $this->denyAdditionalProperties;
244188
}
245189

246-
/**
247-
* @param bool $denyAdditionalProperties
248-
*
249-
* @return $this
250-
*/
251190
public function setDenyAdditionalProperties(bool $denyAdditionalProperties): self
252191
{
253192
$this->denyAdditionalProperties = $denyAdditionalProperties;
254193

255194
return $this;
256195
}
257196

258-
/**
259-
* @return bool
260-
*/
261197
public function hasSerializationEnabled(): bool
262198
{
263199
return $this->serialization;
264200
}
265201

266-
/**
267-
* @param bool $serialization
268-
*
269-
* @return $this
270-
*/
271202
public function setSerialization(bool $serialization): self
272203
{
273204
$this->serialization = $serialization;
274205

275206
return $this;
276207
}
277208

278-
/**
279-
* @param bool $outputEnabled
280-
*
281-
* @return $this
282-
*/
283209
public function setOutputEnabled(bool $outputEnabled): self
284210
{
285211
$this->outputEnabled = $outputEnabled;
286212

287213
return $this;
288214
}
289215

290-
/**
291-
* @return bool
292-
*/
293216
public function isOutputEnabled(): bool
294217
{
295218
return $this->outputEnabled;
296219
}
297220

298-
/**
299-
* @return bool
300-
*/
301221
public function collectErrors(): bool
302222
{
303223
return $this->collectErrors;
304224
}
305225

306-
/**
307-
* @param bool $collectErrors
308-
*
309-
* @return GeneratorConfiguration
310-
*/
311226
public function setCollectErrors(bool $collectErrors): self
312227
{
313228
$this->collectErrors = $collectErrors;
314229

315230
return $this;
316231
}
317232

318-
/**
319-
* @return string
320-
*/
321233
public function getErrorRegistryClass(): string
322234
{
323235
return $this->errorRegistryClass;
324236
}
325237

326-
/**
327-
* @param string $errorRegistryClass
328-
*
329-
* @return GeneratorConfiguration
330-
*/
331238
public function setErrorRegistryClass(string $errorRegistryClass): self
332239
{
333240
$this->errorRegistryClass = $errorRegistryClass;
334241

335242
return $this;
336243
}
337244

338-
/**
339-
* @return bool
340-
*/
341245
public function isImplicitNullAllowed(): bool
342246
{
343247
return $this->allowImplicitNull;
344248
}
345249

346-
/**
347-
* @param bool $allowImplicitNull
348-
*
349-
* @return GeneratorConfiguration
350-
*/
351250
public function setImplicitNull(bool $allowImplicitNull): self
352251
{
353252
$this->allowImplicitNull = $allowImplicitNull;

src/Model/MethodInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ interface MethodInterface
88
{
99
/**
1010
* Returns the code of the method including the function signature
11-
*
12-
* @return string
1311
*/
1412
public function getCode(): string;
1513
}

src/Model/Property/AbstractProperty.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,18 @@ abstract class AbstractProperty implements PropertyInterface
1919
{
2020
use JsonSchemaTrait, ResolvableTrait;
2121

22-
/** @var string */
23-
protected $name = '';
24-
/** @var string */
25-
protected $attribute = '';
22+
protected string $attribute;
2623

2724
/**
2825
* Property constructor.
2926
*
30-
* @param string $name
31-
* @param JsonSchema $jsonSchema
32-
*
3327
* @throws SchemaException
3428
*/
35-
public function __construct(string $name, JsonSchema $jsonSchema)
29+
public function __construct(protected string $name, JsonSchema $jsonSchema)
3630
{
37-
$this->name = $name;
3831
$this->jsonSchema = $jsonSchema;
3932

40-
$this->attribute = $this->processAttributeName($name);
33+
$this->attribute = $this->processAttributeName($this->name);
4134
}
4235

4336
/**
@@ -63,10 +56,6 @@ public function getAttribute(bool $variableName = false): string
6356
/**
6457
* Convert a name of a JSON-field into a valid PHP variable name to be used as class attribute
6558
*
66-
* @param string $name
67-
*
68-
* @return string
69-
*
7059
* @throws SchemaException
7160
*/
7261
protected function processAttributeName(string $name): string

src/Model/Property/CompositionPropertyDecorator.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ class CompositionPropertyDecorator extends PropertyProxy
2828
/**
2929
* CompositionPropertyDecorator constructor.
3030
*
31-
* @param string $propertyName
32-
* @param JsonSchema $jsonSchema
33-
* @param PropertyInterface $property
34-
*
3531
* @throws SchemaException
3632
*/
3733
public function __construct(string $propertyName, JsonSchema $jsonSchema, PropertyInterface $property)
@@ -50,10 +46,8 @@ public function __construct(string $propertyName, JsonSchema $jsonSchema, Proper
5046

5147
/**
5248
* Append an object property which is affected by the composition validator
53-
*
54-
* @param PropertyInterface $property
5549
*/
56-
public function appendAffectedObjectProperty(PropertyInterface $property)
50+
public function appendAffectedObjectProperty(PropertyInterface $property): void
5751
{
5852
$this->affectedObjectProperties[] = $property;
5953
}

0 commit comments

Comments
 (0)