Skip to content

Commit d47b25e

Browse files
committed
CS: Follow rector rule changes
1 parent 133a466 commit d47b25e

16 files changed

Lines changed: 55 additions & 61 deletions

rector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
1212
use Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector;
1313
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
14+
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
1415
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector;
1516
use Rector\ValueObject\PhpVersion;
1617

@@ -35,6 +36,7 @@
3536
ParamTypeByMethodCallTypeRector::class => [
3637
__DIR__ . '/src/Serializer.php',
3738
],
39+
ClassPropertyAssignToConstructorPromotionRector::class,
3840
])
3941
->withPreparedSets(
4042
deadCode: true,

src/Analysers/ComposerAutoloaderScanner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function scan(array $namespaces): array
2929
if ($autoloader = static::getComposerAutoloader()) {
3030
foreach (array_keys($autoloader->getClassMap()) as $unit) {
3131
foreach ($namespaces as $namespace) {
32-
if (0 === strpos($unit, $namespace)) {
32+
if (str_starts_with($unit, $namespace)) {
3333
$units[] = $unit;
3434
break;
3535
}

src/Analysers/DocBlockAnnotationFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ public function build(\Reflector $reflector, Context $context): array
4141
$aliases = $this->generator ? $this->generator->getAliases() : [];
4242

4343
if (method_exists($reflector, 'getShortName') && method_exists($reflector, 'getName')) {
44-
$aliases[strtolower($reflector->getShortName())] = $reflector->getName();
44+
$aliases[strtolower((string) $reflector->getShortName())] = $reflector->getName();
4545
}
4646

4747
if ($context->with('scanned')) {
4848
$details = $context->scanned;
4949
foreach ($details['uses'] as $alias => $name) {
50-
$aliasKey = strtolower($alias);
50+
$aliasKey = strtolower((string) $alias);
5151
if ($name != $alias && !array_key_exists($aliasKey, $aliases)) {
5252
// real aliases only
53-
$aliases[strtolower($alias)] = $name;
53+
$aliases[strtolower((string) $alias)] = $name;
5454
}
5555
}
5656
}

src/Analysers/TokenScanner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function collect_stmts(array $stmts, string $namespace): array
7171
};
7272
$result = [];
7373
foreach ($stmts as $stmt) {
74-
switch (get_class($stmt)) {
74+
switch ($stmt::class) {
7575
case Use_::class:
7676
$uses += $this->collect_uses($stmt);
7777
break;

src/Annotations/AbstractAnnotation.php

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public function mergeProperties($object): void
237237
if (Generator::isDefault($value)) {
238238
continue;
239239
}
240-
$identity = method_exists($object, 'identity') ? $object->identity() : get_class($object);
240+
$identity = method_exists($object, 'identity') ? $object->identity() : $object::class;
241241
$context1 = $this->_context;
242242
$context2 = property_exists($object, '_context') ? $object->_context : 'unknown';
243243
if ($this->{$property} instanceof AbstractAnnotation) {
@@ -449,13 +449,13 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
449449
}
450450

451451
/** @var class-string<AbstractAnnotation> $class */
452-
$class = get_class($annotation);
452+
$class = $annotation::class;
453453
if ($details = $this->matchNested($annotation)) {
454454
$property = $details->value;
455455
if (is_array($property)) {
456-
$this->_context->logger->warning('Only one ' . static::shorten(get_class($annotation)) . '() allowed for ' . $this->identity() . ' multiple found, skipped: ' . $annotation->_context);
456+
$this->_context->logger->warning('Only one ' . static::shorten($annotation::class) . '() allowed for ' . $this->identity() . ' multiple found, skipped: ' . $annotation->_context);
457457
} else {
458-
$this->_context->logger->warning('Only one ' . static::shorten(get_class($annotation)) . '() allowed for ' . $this->identity() . " multiple found in:\n Using: " . $this->{$property}->_context . "\n Skipped: " . $annotation->_context);
458+
$this->_context->logger->warning('Only one ' . static::shorten($annotation::class) . '() allowed for ' . $this->identity() . " multiple found in:\n Using: " . $this->{$property}->_context . "\n Skipped: " . $annotation->_context);
459459
}
460460
} elseif ($annotation instanceof AbstractAnnotation) {
461461
$message = 'Unexpected ' . $annotation->identity();
@@ -493,7 +493,7 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
493493
}
494494

495495
if (property_exists($this, 'ref') && !Generator::isDefault($this->ref) && is_string($this->ref)) {
496-
if (substr($this->ref, 0, 2) === '#/' && $stack !== [] && $stack[0] instanceof OpenApi) {
496+
if (str_starts_with($this->ref, '#/') && $stack !== [] && $stack[0] instanceof OpenApi) {
497497
// Internal reference
498498
try {
499499
$stack[0]->ref($this->ref);
@@ -540,7 +540,7 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
540540
$this->_context->logger->warning($this->identity() . '->' . $property . ' "' . $value . '" is invalid, expecting "' . implode('", "', $type) . '" in ' . $this->_context);
541541
}
542542
} else {
543-
throw new OpenApiException('Invalid ' . get_class($this) . '::$_types[' . $property . ']');
543+
throw new OpenApiException('Invalid ' . static::class . '::$_types[' . $property . ']');
544544
}
545545
}
546546
$stack[] = $this;
@@ -599,7 +599,7 @@ private static function _validate($fields, array $stack, array $skip, string $ba
599599
*/
600600
public function identity(): string
601601
{
602-
$class = get_class($this);
602+
$class = static::class;
603603
$properties = [];
604604
/** @var class-string<AbstractAnnotation> $parent */
605605
foreach (static::$_parents as $parent) {
@@ -640,10 +640,10 @@ public function matchNested($other)
640640
*/
641641
public function getRoot(): string
642642
{
643-
$class = get_class($this);
643+
$class = static::class;
644644

645645
do {
646-
if (0 === strpos($class, 'OpenApi\\Annotations\\')) {
646+
if (str_starts_with($class, 'OpenApi\\Annotations\\')) {
647647
break;
648648
}
649649
} while ($class = get_parent_class($class));
@@ -658,7 +658,7 @@ public function getRoot(): string
658658
*/
659659
public function isRoot(string $rootClass): bool
660660
{
661-
return get_class($this) === $rootClass || $this->getRoot() === $rootClass;
661+
return static::class === $rootClass || $this->getRoot() === $rootClass;
662662
}
663663

664664
/**
@@ -674,7 +674,7 @@ protected function _identity(array $properties): string
674674
}
675675
}
676676

677-
return static::shorten(get_class($this)) . '(' . implode(',', $fields) . ')';
677+
return static::shorten(static::class) . '(' . implode(',', $fields) . ')';
678678
}
679679

680680
/**
@@ -685,7 +685,7 @@ protected function _identity(array $properties): string
685685
*/
686686
private function validateType(string $type, $value): bool
687687
{
688-
if (substr($type, 0, 1) === '[' && substr($type, -1) === ']') { // Array of a specified type?
688+
if (str_starts_with($type, '[') && str_ends_with($type, ']')) { // Array of a specified type?
689689
if ($this->validateType('array', $value) === false) {
690690
return false;
691691
}
@@ -725,24 +725,16 @@ private function validateDefaultTypes(string $type, $value): bool
725725
return false;
726726
}
727727

728-
switch ($type) {
729-
case 'string':
730-
return is_string($value);
731-
case 'boolean':
732-
return is_bool($value);
733-
case 'integer':
734-
return is_int($value);
735-
case 'number':
736-
return is_numeric($value);
737-
case 'object':
738-
return is_object($value);
739-
case 'array':
740-
return $this->validateArrayType($value);
741-
case 'scheme':
742-
return in_array($value, ['http', 'https', 'ws', 'wss'], true);
743-
default:
744-
throw new OpenApiException('Invalid type "' . $type . '"');
745-
}
728+
return match ($type) {
729+
'string' => is_string($value),
730+
'boolean' => is_bool($value),
731+
'integer' => is_int($value),
732+
'number' => is_numeric($value),
733+
'object' => is_object($value),
734+
'array' => $this->validateArrayType($value),
735+
'scheme' => in_array($value, ['http', 'https', 'ws', 'wss'], true),
736+
default => throw new OpenApiException('Invalid type "' . $type . '"'),
737+
};
746738
}
747739

748740
/**

src/Annotations/OpenApi.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function saveAs(string $filename, string $format = 'auto'): void
192192
*/
193193
public function ref(string $ref)
194194
{
195-
if (substr($ref, 0, 2) !== '#/') {
195+
if (!str_starts_with($ref, '#/')) {
196196
// @todo Add support for external (http) refs?
197197
throw new OpenApiException('Unsupported $ref "' . $ref . '", it should start with "#/"');
198198
}
@@ -219,7 +219,7 @@ private static function resolveRef(string $ref, string $resolved, $container, ar
219219

220220
if (is_object($container)) {
221221
// support use x-* in ref
222-
$xKey = strpos($property, 'x-') === 0 ? substr($property, 2) : null;
222+
$xKey = str_starts_with($property, 'x-') ? substr($property, 2) : null;
223223
if ($xKey) {
224224
if (!is_array($container->x) || !array_key_exists($xKey, $container->x)) {
225225
$xKey = null;

src/Context.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* @property string|null $version The OpenAPI version in use
4444
*/
4545
#[\AllowDynamicProperties]
46-
class Context
46+
class Context implements \Stringable
4747
{
4848
/**
4949
* Prototypical inheritance for properties.

src/Generator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ protected function normaliseConfig(array $config): array
158158
$normalised = [];
159159
foreach ($config as $key => $value) {
160160
if (is_numeric($key)) {
161-
$token = explode('=', $value);
161+
$token = explode('=', (string) $value);
162162
if (2 == count($token)) {
163163
// 'operationId.hash=false'
164164
[$key, $value] = $token;
@@ -169,7 +169,7 @@ protected function normaliseConfig(array $config): array
169169
$value = 'true' == $value;
170170
}
171171

172-
if ($isList = ('[]' === substr($key, -2))) {
172+
if ($isList = (str_ends_with($key, '[]'))) {
173173
$key = substr($key, 0, -2);
174174
}
175175
$token = explode('.', $key);

src/Pipeline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function insert(callable $pipe, $matcher): Pipeline
7171
{
7272
if (is_string($matcher)) {
7373
$before = $matcher;
74-
$matcher = function (array $pipes) use ($before) {
74+
$matcher = function (array $pipes) use ($before): int|string|null {
7575
foreach ($pipes as $ii => $current) {
7676
if ($current instanceof $before) {
7777
return $ii;

src/Processors/AugmentProperties.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ protected function isNullable(string $typeDescription): bool
170170

171171
protected function stripNull(string $typeDescription): string
172172
{
173-
if (strpos($typeDescription, '|') === false) {
173+
if (!str_contains($typeDescription, '|')) {
174174
return $typeDescription;
175175
}
176176
$types = [];

0 commit comments

Comments
 (0)