Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modernize code #85

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.4"
"phpunit/phpunit": "^9.4",
"rector/rector": "^1.2"
},
"autoload": {
"psr-4": {
Expand Down
36 changes: 36 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\EarlyReturn\Rector\If_\ChangeOrIfContinueToMultiContinueRector;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\Php80\Rector\Ternary\GetDebugTypeRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\DataProviderArrayItemsNewLinedRector;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictSetUpRector;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withPhpSets()
->withPreparedSets(
deadCode: true,
typeDeclarations: true,
privatization: true,
earlyReturn: true,
phpunitCodeQuality: true,
)
->withRules([
ClassPropertyAssignToConstructorPromotionRector::class,
])
->withSkip([
GetDebugTypeRector::class,
ChangeOrIfContinueToMultiContinueRector::class,
YieldDataProviderRector::class,
DataProviderArrayItemsNewLinedRector::class
]);
101 changes: 0 additions & 101 deletions src/Model/GeneratorConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ public function __construct()
/**
* Add an additional filter
*
* @param FilterInterface ...$additionalFilter
*
* @return $this
*
* @throws Exception
* @throws InvalidFilterException
*/
Expand Down Expand Up @@ -103,11 +99,6 @@ public function addFilter(FilterInterface ...$additionalFilter): self

/**
* Add an additional format
*
* @param string $formatKey
* @param FormatValidatorInterface $format
*
* @return $this
*/
public function addFormat(string $formatKey, FormatValidatorInterface $format): self
{
Expand All @@ -116,20 +107,12 @@ public function addFormat(string $formatKey, FormatValidatorInterface $format):
return $this;
}

/**
* @param string $formatKey
*
* @return FormatValidatorInterface|null
*/
public function getFormat(string $formatKey): ?FormatValidatorInterface
{
return $this->formats[$formatKey] ?? null;
}

/**
* @param array $callback
* @param string $message
*
* @throws InvalidFilterException
*/
private function validateFilterCallback(array $callback, string $message): void
Expand All @@ -145,209 +128,125 @@ private function validateFilterCallback(array $callback, string $message): void

/**
* Get a filter by the given token
*
* @param string $token
*
* @return FilterInterface|null
*/
public function getFilter(string $token): ?FilterInterface
{
return $this->filter[$token] ?? null;
}

/**
* @return ClassNameGeneratorInterface
*/
public function getClassNameGenerator(): ClassNameGeneratorInterface
{
return $this->classNameGenerator;
}

/**
* @param ClassNameGeneratorInterface $classNameGenerator
*
* @return $this
*/
public function setClassNameGenerator(ClassNameGeneratorInterface $classNameGenerator): self
{
$this->classNameGenerator = $classNameGenerator;

return $this;
}

/**
* @return string
*/
public function getNamespacePrefix(): string
{
return $this->namespacePrefix;
}

/**
* @param string $namespacePrefix
*
* @return $this
*/
public function setNamespacePrefix(string $namespacePrefix): self
{
$this->namespacePrefix = trim($namespacePrefix, '\\');

return $this;
}

/**
* @return bool
*/
public function isDefaultArraysToEmptyArrayEnabled(): bool
{
return $this->defaultArraysToEmptyArray;
}

/**
* @param bool $defaultArraysToEmptyArray
*
* @return GeneratorConfiguration
*/
public function setDefaultArraysToEmptyArray(bool $defaultArraysToEmptyArray): self
{
$this->defaultArraysToEmptyArray = $defaultArraysToEmptyArray;

return $this;
}

/**
* @return bool
*/
public function isImmutable(): bool
{
return $this->immutable;
}

/**
* @param bool $immutable
*
* @return GeneratorConfiguration
*/
public function setImmutable(bool $immutable): self
{
$this->immutable = $immutable;

return $this;
}

/**
* @return bool
*/
public function denyAdditionalProperties(): bool
{
return $this->denyAdditionalProperties;
}

/**
* @param bool $denyAdditionalProperties
*
* @return $this
*/
public function setDenyAdditionalProperties(bool $denyAdditionalProperties): self
{
$this->denyAdditionalProperties = $denyAdditionalProperties;

return $this;
}

/**
* @return bool
*/
public function hasSerializationEnabled(): bool
{
return $this->serialization;
}

/**
* @param bool $serialization
*
* @return $this
*/
public function setSerialization(bool $serialization): self
{
$this->serialization = $serialization;

return $this;
}

/**
* @param bool $outputEnabled
*
* @return $this
*/
public function setOutputEnabled(bool $outputEnabled): self
{
$this->outputEnabled = $outputEnabled;

return $this;
}

/**
* @return bool
*/
public function isOutputEnabled(): bool
{
return $this->outputEnabled;
}

/**
* @return bool
*/
public function collectErrors(): bool
{
return $this->collectErrors;
}

/**
* @param bool $collectErrors
*
* @return GeneratorConfiguration
*/
public function setCollectErrors(bool $collectErrors): self
{
$this->collectErrors = $collectErrors;

return $this;
}

/**
* @return string
*/
public function getErrorRegistryClass(): string
{
return $this->errorRegistryClass;
}

/**
* @param string $errorRegistryClass
*
* @return GeneratorConfiguration
*/
public function setErrorRegistryClass(string $errorRegistryClass): self
{
$this->errorRegistryClass = $errorRegistryClass;

return $this;
}

/**
* @return bool
*/
public function isImplicitNullAllowed(): bool
{
return $this->allowImplicitNull;
}

/**
* @param bool $allowImplicitNull
*
* @return GeneratorConfiguration
*/
public function setImplicitNull(bool $allowImplicitNull): self
{
$this->allowImplicitNull = $allowImplicitNull;
Expand Down
2 changes: 0 additions & 2 deletions src/Model/MethodInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ interface MethodInterface
{
/**
* Returns the code of the method including the function signature
*
* @return string
*/
public function getCode(): string;
}
17 changes: 3 additions & 14 deletions src/Model/Property/AbstractProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,18 @@ abstract class AbstractProperty implements PropertyInterface
{
use JsonSchemaTrait, ResolvableTrait;

/** @var string */
protected $name = '';
/** @var string */
protected $attribute = '';
protected string $attribute;

/**
* Property constructor.
*
* @param string $name
* @param JsonSchema $jsonSchema
*
* @throws SchemaException
*/
public function __construct(string $name, JsonSchema $jsonSchema)
public function __construct(protected string $name, JsonSchema $jsonSchema)
{
$this->name = $name;
$this->jsonSchema = $jsonSchema;

$this->attribute = $this->processAttributeName($name);
$this->attribute = $this->processAttributeName($this->name);
}

/**
Expand All @@ -63,10 +56,6 @@ public function getAttribute(bool $variableName = false): string
/**
* Convert a name of a JSON-field into a valid PHP variable name to be used as class attribute
*
* @param string $name
*
* @return string
*
* @throws SchemaException
*/
protected function processAttributeName(string $name): string
Expand Down
8 changes: 1 addition & 7 deletions src/Model/Property/CompositionPropertyDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ class CompositionPropertyDecorator extends PropertyProxy
/**
* CompositionPropertyDecorator constructor.
*
* @param string $propertyName
* @param JsonSchema $jsonSchema
* @param PropertyInterface $property
*
* @throws SchemaException
*/
public function __construct(string $propertyName, JsonSchema $jsonSchema, PropertyInterface $property)
Expand All @@ -50,10 +46,8 @@ public function __construct(string $propertyName, JsonSchema $jsonSchema, Proper

/**
* Append an object property which is affected by the composition validator
*
* @param PropertyInterface $property
*/
public function appendAffectedObjectProperty(PropertyInterface $property)
public function appendAffectedObjectProperty(PropertyInterface $property): void
{
$this->affectedObjectProperties[] = $property;
}
Expand Down
Loading