Skip to content

Commit 59dce49

Browse files
committed
refactor: code style fix
1 parent 6dd57fc commit 59dce49

File tree

16 files changed

+159
-100
lines changed

16 files changed

+159
-100
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ docs
1010
vendor
1111
node_modules
1212
.php-cs-fixer.cache
13+
.context
14+
mcp-*.log
15+
runtime

composer.json

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,61 @@
11
{
2-
"name": "spiral/json-schema-generator",
3-
"description": "Provides the ability to generate JSON schemas from Data Transfer Object (DTO) classes",
4-
"keywords": [],
5-
"homepage": "https://github.com/spiral/json-schema-generator",
6-
"license": "MIT",
7-
"authors": [
8-
{
9-
"name": "Anton Titov (wolfy-j)",
10-
"email": "[email protected]"
11-
},
12-
{
13-
"name": "Pavel Buchnev (butschster)",
14-
"email": "[email protected]"
15-
},
16-
{
17-
"name": "Aleksei Gagarin (roxblnfk)",
18-
"email": "[email protected]"
19-
},
20-
{
21-
"name": "Maksim Smakouz (msmakouz)",
22-
"email": "[email protected]"
23-
}
24-
],
25-
"require": {
26-
"php": ">=8.3",
27-
"symfony/property-info": "^7.2.0 || ^8.0.0",
28-
"phpstan/phpdoc-parser": "^1.33 | ^2.1",
29-
"phpdocumentor/reflection-docblock": "^5.3"
2+
"name": "spiral/json-schema-generator",
3+
"description": "Provides the ability to generate JSON schemas from Data Transfer Object (DTO) classes",
4+
"keywords": [],
5+
"homepage": "https://github.com/spiral/json-schema-generator",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Anton Titov (wolfy-j)",
10+
"email": "[email protected]"
3011
},
31-
"require-dev": {
32-
"phpunit/phpunit": "^10.5.45",
33-
"spiral/code-style": "^2.2.2",
34-
"vimeo/psalm": "^5.26.1 || ^6.10"
12+
{
13+
"name": "Pavel Buchnev (butschster)",
14+
"email": "[email protected]"
3515
},
36-
"autoload": {
37-
"psr-4": {
38-
"Spiral\\JsonSchemaGenerator\\": "src"
39-
}
16+
{
17+
"name": "Aleksei Gagarin (roxblnfk)",
18+
"email": "[email protected]"
4019
},
41-
"autoload-dev": {
42-
"psr-4": {
43-
"Spiral\\JsonSchemaGenerator\\Tests\\": "tests"
44-
}
45-
},
46-
"scripts": {
47-
"cs:fix": "php-cs-fixer fix -v",
48-
"test": "phpunit",
49-
"psalm": "psalm",
50-
"psalm:baseline": "psalm --set-baseline=psalm-baseline.xml"
51-
},
52-
"config": {
53-
"sort-packages": true
54-
},
55-
"minimum-stability": "dev",
56-
"prefer-stable": true
20+
{
21+
"name": "Maksim Smakouz (msmakouz)",
22+
"email": "[email protected]"
23+
}
24+
],
25+
"require": {
26+
"php": ">=8.3",
27+
"symfony/property-info": "^7.2.0 || ^8.0.0",
28+
"phpstan/phpdoc-parser": "^1.33 | ^2.1",
29+
"phpdocumentor/reflection-docblock": "^5.3"
30+
},
31+
"require-dev": {
32+
"phpunit/phpunit": "^10.5.45",
33+
"spiral/code-style": "^2.2.2",
34+
"vimeo/psalm": "^6.10",
35+
"rector/rector": "^2.0"
36+
},
37+
"autoload": {
38+
"psr-4": {
39+
"Spiral\\JsonSchemaGenerator\\": "src"
40+
}
41+
},
42+
"autoload-dev": {
43+
"psr-4": {
44+
"Spiral\\JsonSchemaGenerator\\Tests\\": "tests"
45+
}
46+
},
47+
"scripts": {
48+
"cs:fix": "php-cs-fixer fix -v",
49+
"psalm": "psalm",
50+
"refactor": "rector process --config=rector.php",
51+
"refactor:ci": "rector process --config=rector.php --dry-run --ansi",
52+
"test": "phpunit",
53+
"test-coverage": "phpunit --coverage",
54+
"psalm:baseline": "psalm --set-baseline=psalm-baseline.xml"
55+
},
56+
"config": {
57+
"sort-packages": true
58+
},
59+
"minimum-stability": "dev",
60+
"prefer-stable": true
5761
}

context.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
$schema: 'https://raw.githubusercontent.com/context-hub/generator/refs/heads/main/json-schema.json'
2+
3+
tools:
4+
- id: run-tests
5+
description: 'Run tests'
6+
type: run
7+
commands:
8+
- cmd: vendor/bin/phpunit
9+
10+
documents:
11+
- description: 'Project structure overview'
12+
outputPath: project-structure.md
13+
sources:
14+
- type: tree
15+
sourcePaths:
16+
- src
17+
showCharCount: true
18+
19+
- description: Source code
20+
outputPath: source-code.md
21+
sources:
22+
- type: file
23+
sourcePaths:
24+
- src
25+
- tests/Unit

rector.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector;
7+
use Rector\Set\ValueObject\LevelSetList;
8+
use Rector\Set\ValueObject\SetList;
9+
10+
return static function (RectorConfig $rectorConfig): void {
11+
$rectorConfig->paths([
12+
__DIR__ . '/src',
13+
__DIR__ . '/tests',
14+
]);
15+
16+
// Register rules for PHP 8.4 migration
17+
$rectorConfig->sets([
18+
SetList::PHP_83,
19+
LevelSetList::UP_TO_PHP_83,
20+
]);
21+
22+
// Skip vendor directories
23+
$rectorConfig->skip([
24+
__DIR__ . '/vendor',
25+
AddOverrideAttributeToOverriddenMethodsRector::class,
26+
]);
27+
};

src/Parser/Property.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
/**
88
* @internal
99
*/
10-
final class Property implements PropertyInterface
10+
final readonly class Property implements PropertyInterface
1111
{
1212
public function __construct(
13-
private readonly \ReflectionProperty $property,
14-
private readonly Type $type,
15-
private readonly bool $hasDefaultValue,
16-
private readonly mixed $defaultValue = null,
13+
private \ReflectionProperty $property,
14+
private Type $type,
15+
private bool $hasDefaultValue,
16+
private mixed $defaultValue = null,
1717
) {}
1818

1919
/**

src/Parser/SimpleType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* @internal
1111
*/
12-
final class SimpleType implements TypeInterface
12+
final readonly class SimpleType implements TypeInterface
1313
{
1414
/**
1515
* @var class-string|SchemaType
@@ -22,9 +22,9 @@ final class SimpleType implements TypeInterface
2222
*/
2323
public function __construct(
2424
string $name,
25-
private readonly bool $builtin,
26-
private readonly ?Type $collectionType = null,
27-
private readonly ?array $enum = null,
25+
private bool $builtin,
26+
private ?Type $collectionType = null,
27+
private ?array $enum = null,
2828
) {
2929
/** @psalm-suppress PropertyTypeCoercion */
3030
$this->name = $this->builtin ? SchemaType::fromBuiltIn($name) : $name;

src/Parser/Type.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
/**
1010
* @internal
1111
*/
12-
final class Type
12+
final readonly class Type
1313
{
1414
/**
1515
* @param list<SimpleType> $types
1616
*/
1717
public function __construct(
18-
public readonly array $types,
18+
public array $types,
1919
) {}
2020

2121
public function allowsNull(): bool

src/Schema/Definition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(
2424
throw new DefinitionException(\sprintf(
2525
'Property `%s` is not an instance of `%s`.',
2626
// type name or class name
27-
\is_object($property) ? \get_class($property) : \gettype($property),
27+
\get_debug_type($property),
2828
Property::class,
2929
));
3030
}

src/Schema/Property.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44

55
namespace Spiral\JsonSchemaGenerator\Schema;
66

7-
final class Property implements \JsonSerializable
7+
final readonly class Property implements \JsonSerializable
88
{
99
/**
1010
* @param list<PropertyType> $types
1111
*/
1212
public function __construct(
13-
public readonly array $types,
14-
public readonly string $title = '',
15-
public readonly string $description = '',
16-
public readonly bool $required = false,
17-
public readonly mixed $default = null,
18-
public readonly ?Format $format = null,
13+
public array $types,
14+
public string $title = '',
15+
public string $description = '',
16+
public bool $required = false,
17+
public mixed $default = null,
18+
public ?Format $format = null,
1919
) {}
2020

2121
public function jsonSerialize(): array

src/Schema/PropertyOption.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
/**
1010
* @internal
1111
*/
12-
final class PropertyOption
12+
final readonly class PropertyOption
1313
{
1414
/**
1515
* @param Type|class-string $value
1616
*/
1717
public function __construct(
18-
public readonly Type|string $value,
18+
public Type|string $value,
1919
) {
2020
if (\is_string($this->value) && !\class_exists($this->value)) {
2121
throw new InvalidTypeException('Invalid property option definition.');

0 commit comments

Comments
 (0)