Skip to content

Commit e3ade14

Browse files
romalytvynenkogithub-actions[bot]
authored andcommitted
Fix styling
1 parent b41adad commit e3ade14

21 files changed

+25
-50
lines changed

src/Support/ComplexTypeHandler/JsonResourceHandler.php

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

55
use Dedoc\Scramble\Support\ClassAstHelper;
66
use Dedoc\Scramble\Support\Generator\Types\OpenApiTypeHelper;
7-
use Dedoc\Scramble\Support\Infer\Handler\ReturnTypeGettingExtensions;
8-
use Dedoc\Scramble\Support\ResponseExtractor\ModelInfo;
97
use Dedoc\Scramble\Support\Type\Identifier;
108
use Dedoc\Scramble\Support\Type\ObjectType;
119
use Dedoc\Scramble\Support\Type\Type;
12-
use Dedoc\Scramble\Support\TypeHandlers\TypeHandlers;
13-
use Illuminate\Database\Eloquent\Model;
1410
use Illuminate\Http\Resources\Json\JsonResource;
1511
use Illuminate\Http\Resources\Json\ResourceCollection;
16-
use Illuminate\Support\Str;
1712
use PhpParser\Node\Expr\Array_;
18-
use Symfony\Component\Yaml\Yaml;
1913

2014
class JsonResourceHandler
2115
{

src/Support/Generator/Types/ObjectType.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public function toArray()
4141
$result = parent::toArray();
4242

4343
try {
44-
4544
if (count($this->properties)) {
4645
$properties = [];
4746
foreach ($this->properties as $name => $property) {

src/Support/Generator/Types/OpenApiTypeHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public static function fromType(\Dedoc\Scramble\Support\Type\AbstractType $type)
6161
if (! $item->isOptional) {
6262
$requiredKeys[] = $item->key;
6363
}
64+
6465
return [
6566
$item->key => static::fromType($item),
6667
];
@@ -86,7 +87,7 @@ public static function fromType(\Dedoc\Scramble\Support\Type\AbstractType $type)
8687
}
8788
} elseif ($type instanceof Union) {
8889
if (count($type->types) === 2 && collect($type->types)->contains(fn ($t) => $t instanceof \Dedoc\Scramble\Support\Type\NullType)) {
89-
$notNullType = collect($type->types)->first(fn ($t) => !($t instanceof \Dedoc\Scramble\Support\Type\NullType));
90+
$notNullType = collect($type->types)->first(fn ($t) => ! ($t instanceof \Dedoc\Scramble\Support\Type\NullType));
9091
if ($notNullType) {
9192
$openApiType = static::fromType($notNullType)->nullable(true);
9293
} else {

src/Support/Infer/Handler/ArrayHandler.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Dedoc\Scramble\Support\Infer\Handler;
44

5-
use Dedoc\Scramble\Support\Type\ArrayItemType_;
65
use Dedoc\Scramble\Support\Type\ArrayType;
7-
use Dedoc\Scramble\Support\Type\UnknownType;
86
use PhpParser\Node;
97

108
class ArrayHandler

src/Support/Infer/Handler/FunctionLikeHandler.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Dedoc\Scramble\Support\Infer\Handler;
44

55
use Dedoc\Scramble\Support\Infer\Scope\Scope;
6-
use Dedoc\Scramble\Support\Infer\Scope\ScopeContext;
76
use Dedoc\Scramble\Support\Type\FunctionLikeType;
87
use Dedoc\Scramble\Support\Type\FunctionType;
98
use Dedoc\Scramble\Support\Type\TypeHelper;

src/Support/Infer/Handler/NewHandler.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,8 @@
22

33
namespace Dedoc\Scramble\Support\Infer\Handler;
44

5-
use Dedoc\Scramble\Support\Infer\Scope\Scope;
6-
use Dedoc\Scramble\Support\Type\FunctionLikeType;
7-
use Dedoc\Scramble\Support\Type\FunctionType;
8-
use Dedoc\Scramble\Support\Type\Identifier;
9-
use Dedoc\Scramble\Support\Type\IntegerType;
105
use Dedoc\Scramble\Support\Type\ObjectType;
11-
use Dedoc\Scramble\Support\Type\StringType;
12-
use Dedoc\Scramble\Support\Type\Union;
136
use PhpParser\Node;
14-
use PhpParser\Node\FunctionLike;
15-
use PhpParser\NodeFinder;
167

178
class NewHandler
189
{

src/Support/Infer/Handler/ReturnTypeGettingExtensions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class ReturnTypeGettingExtensions
88
{
9-
static $extensions = [];
9+
public static $extensions = [];
1010

1111
public function shouldHandle($node)
1212
{
@@ -22,6 +22,7 @@ function ($acc, $extensionClass) use ($node) {
2222
if ($type) {
2323
return $type;
2424
}
25+
2526
return $acc;
2627
},
2728
);

src/Support/Infer/Handler/ScalarHandler.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@
22

33
namespace Dedoc\Scramble\Support\Infer\Handler;
44

5-
use Dedoc\Scramble\Support\Infer\Scope\Scope;
6-
use Dedoc\Scramble\Support\Type\FunctionLikeType;
7-
use Dedoc\Scramble\Support\Type\FunctionType;
85
use Dedoc\Scramble\Support\Type\IntegerType;
96
use Dedoc\Scramble\Support\Type\StringType;
10-
use Dedoc\Scramble\Support\Type\Union;
117
use PhpParser\Node;
12-
use PhpParser\Node\FunctionLike;
13-
use PhpParser\NodeFinder;
148

159
class ScalarHandler
1610
{
@@ -23,11 +17,13 @@ public function leave(Node\Scalar $node)
2317
{
2418
if ($node instanceof Node\Scalar\String_) {
2519
$node->setAttribute('type', new StringType());
20+
2621
return;
2722
}
2823

2924
if ($node instanceof Node\Scalar\LNumber) {
3025
$node->setAttribute('type', new IntegerType());
26+
3127
return;
3228
}
3329
}

src/Support/Infer/Scope/Scope.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(ScopeContext $context, callable $namesResolver, ?Sco
2121

2222
public function isInClass()
2323
{
24-
return !!$this->context->class;
24+
return (bool) $this->context->class;
2525
}
2626

2727
public function class(): ?ObjectType

src/Support/Infer/Scope/ScopeContext.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class ScopeContext
1111
public function setClass(?ObjectType $class): ScopeContext
1212
{
1313
$this->class = $class;
14+
1415
return $this;
1516
}
1617
}

src/Support/Infer/TypeInferringVisitor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ private function getOrCreateScope()
9292
if (! isset($this->scope)) {
9393
$this->scope = new Scope(new ScopeContext, $this->namesResolver);
9494
}
95+
9596
return $this->scope;
9697
}
9798
}

src/Support/InferExtensions/JsonResourceTypeInfer.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class JsonResourceTypeInfer
2222
{
23-
static $jsonResourcesModelTypesCache = [];
23+
public static $jsonResourcesModelTypesCache = [];
2424

2525
public function getNodeReturnType(Node $node, Scope $scope)
2626
{
@@ -43,28 +43,28 @@ public function getNodeReturnType(Node $node, Scope $scope)
4343
* $this->mergeWhen()
4444
*/
4545
if ($this->isMethodCallToThis($node, ['merge', 'mergeWhen'])) {
46-
if(! $type = $node->args[count($node->args) - 1]->value->getAttribute('type') ?? null) {
46+
if (! $type = $node->args[count($node->args) - 1]->value->getAttribute('type') ?? null) {
4747
return null;
4848
}
4949

5050
if ($type instanceof FunctionType) {
5151
$type = $type->getReturnType();
5252
}
5353

54-
return (new Generic(
54+
return new Generic(
5555
new Identifier(MergeValue::class),
5656
[
5757
$node->name->name === 'merge' ? new LiteralBooleanType(true) : new BooleanType(),
58-
$type
58+
$type,
5959
],
60-
));
60+
);
6161
}
6262

6363
/*
6464
* $this->when()
6565
*/
6666
if ($this->isMethodCallToThis($node, ['when'])) {
67-
if(! $type = $node->args[count($node->args) - 1]->value->getAttribute('type') ?? null) {
67+
if (! $type = $node->args[count($node->args) - 1]->value->getAttribute('type') ?? null) {
6868
return null;
6969
}
7070

@@ -115,7 +115,6 @@ private static function modelType(ObjectType $jsonClass, Scope $scope): Type
115115
return static::$jsonResourcesModelTypesCache[$jsonClass->name] = $modelType;
116116
}
117117

118-
119118
private static function getModelName(string $jsonResourceClassName, \ReflectionClass $reflectionClass, callable $getFqName)
120119
{
121120
$phpDoc = $reflectionClass->getDocComment() ?: '';

src/Support/ResponseExtractor/ResponsesExtractor.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
use Dedoc\Scramble\Support\Generator\Response;
88
use Dedoc\Scramble\Support\Generator\Schema;
99
use Dedoc\Scramble\Support\RouteInfo;
10-
use Dedoc\Scramble\Support\Type\Generic;
11-
use Dedoc\Scramble\Support\Type\Type;
12-
use Dedoc\Scramble\Support\TypeHandlers\TypeHandlers;
1310
use Illuminate\Support\Arr;
1411

1512
class ResponsesExtractor
@@ -24,7 +21,7 @@ public function __construct(RouteInfo $routeInfo)
2421
public function __invoke()
2522
{
2623
return collect(Arr::wrap([$this->routeInfo->getHandledReturnType()]))
27-
->filter(fn ($t) => !! $t[1])
24+
->filter(fn ($t) => (bool) $t[1])
2825
->map(function ($type) {
2926
$type = $type[1];
3027

src/Support/RouteInfo.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Dedoc\Scramble\Support\ComplexTypeHandler\ComplexTypeHandlers;
66
use Dedoc\Scramble\Support\Infer\TypeInferringVisitor;
77
use Dedoc\Scramble\Support\Type\FunctionLikeType;
8-
use Dedoc\Scramble\Support\Type\Identifier;
98
use Dedoc\Scramble\Support\TypeHandlers\PhpDocTypeWalker;
109
use Dedoc\Scramble\Support\TypeHandlers\ResolveFqnPhpDocTypeVisitor;
1110
use Dedoc\Scramble\Support\TypeHandlers\TypeHandlers;
@@ -85,7 +84,6 @@ public function phpDoc(): PhpDocNode
8584
}
8685
}
8786

88-
8987
return $this->phpDoc;
9088
}
9189

src/Support/Type/ArrayItemType_.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ class ArrayItemType_ extends AbstractType
88
{
99
/** @var string|int|null */
1010
public $key;
11+
1112
public Type $value;
13+
1214
public bool $isOptional;
1315

1416
public function __construct(
1517
$key,
1618
Type $value,
1719
bool $isOptional = false
18-
)
19-
{
20+
) {
2021
$this->key = $key;
2122
$this->value = $value;
2223
$this->isOptional = $isOptional;

src/Support/Type/ArrayType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function isSame(Type $type)
2222
public function toString(): string
2323
{
2424
$numIndex = 0;
25+
2526
return sprintf(
2627
'array{%s}',
2728
implode(', ', array_map(function (ArrayItemType_ $item) use (&$numIndex) {

src/Support/Type/FunctionType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function __construct(
1919
public function setReturnType(Type $type): self
2020
{
2121
$this->returnType = $type;
22+
2223
return $this;
2324
}
2425

src/Support/Type/ObjectType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class ObjectType extends AbstractType
1414
public function __construct(
1515
string $name,
1616
array $properties = []
17-
)
18-
{
17+
) {
1918
$this->name = $name;
2019
$this->properties = $properties;
2120
}

src/Support/TypeHandlers/PhpDocTypeWalker.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Dedoc\Scramble\Support\TypeHandlers;
44

5-
use Dedoc\Scramble\Support\Type\ArrayType;
65
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeItemNode;
76
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode;
87
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;

tests/InferTypesTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<?php
22

33
use Dedoc\Scramble\Support\ClassAstHelper;
4-
use Dedoc\Scramble\Support\Generator\Types\OpenApiTypeHelper;
4+
use Illuminate\Foundation\Testing\RefreshDatabase;
55
use Illuminate\Http\Resources\Json\JsonResource;
66
use PhpParser\Node\Stmt\ClassMethod;
7-
use Illuminate\Foundation\Testing\RefreshDatabase;
87
use function Spatie\Snapshots\assertMatchesTextSnapshot;
98

109
uses(RefreshDatabase::class);
@@ -28,7 +27,7 @@ class InferTypesTest_SampleClass
2827
{
2928
public function wow($request)
3029
{
31-
return (new BrandEdge($request));
30+
return new BrandEdge($request);
3231
}
3332
}
3433

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public function getEnvironmentSetUp($app)
3434

3535
protected function defineDatabaseMigrations()
3636
{
37-
$this->loadMigrationsFrom(__DIR__ . '/migrations');
37+
$this->loadMigrationsFrom(__DIR__.'/migrations');
3838
}
3939
}

0 commit comments

Comments
 (0)