Skip to content

Commit dcac7e5

Browse files
committed
Using readonly public poperties instead of private properties with setters
1 parent 4bf2817 commit dcac7e5

27 files changed

Lines changed: 438 additions & 630 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=8.1",
15+
"php": ">=8.2",
1616
"infinityloop-dev/graphpinator-tokenizer": "^1.3",
1717
"infinityloop-dev/graphpinator-common": "^2.0",
1818
"infinityloop-dev/utils": "^2.0"

src/Directive/Directive.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,12 @@
66

77
use Graphpinator\Parser\Value\ArgumentValueSet;
88

9-
final class Directive
9+
final readonly class Directive
1010
{
1111
public function __construct(
12-
private string $name,
13-
private ?ArgumentValueSet $arguments,
12+
public string $name,
13+
public ?ArgumentValueSet $arguments,
1414
)
1515
{
1616
}
17-
18-
public function getName() : string
19-
{
20-
return $this->name;
21-
}
22-
23-
public function getArguments() : ?ArgumentValueSet
24-
{
25-
return $this->arguments;
26-
}
2717
}

src/Field/Field.php

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,15 @@
77
use Graphpinator\Parser\Directive\DirectiveSet;
88
use Graphpinator\Parser\Value\ArgumentValueSet;
99

10-
final class Field
10+
final readonly class Field
1111
{
1212
public function __construct(
13-
private string $name,
14-
private ?string $alias = null,
15-
private ?FieldSet $children = null,
16-
private ?ArgumentValueSet $arguments = null,
17-
private ?DirectiveSet $directives = null,
13+
public string $name,
14+
public ?string $alias = null,
15+
public ?FieldSet $children = null,
16+
public ?ArgumentValueSet $arguments = null,
17+
public ?DirectiveSet $directives = null,
1818
)
1919
{
2020
}
21-
22-
public function getName() : string
23-
{
24-
return $this->name;
25-
}
26-
27-
public function getAlias() : ?string
28-
{
29-
return $this->alias;
30-
}
31-
32-
public function getFields() : ?FieldSet
33-
{
34-
return $this->children;
35-
}
36-
37-
public function getArguments() : ?ArgumentValueSet
38-
{
39-
return $this->arguments;
40-
}
41-
42-
public function getDirectives() : ?DirectiveSet
43-
{
44-
return $this->directives;
45-
}
4621
}

src/Fragment/Fragment.php

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,14 @@
88
use Graphpinator\Parser\Field\FieldSet;
99
use Graphpinator\Parser\TypeRef\NamedTypeRef;
1010

11-
final class Fragment
11+
final readonly class Fragment
1212
{
1313
public function __construct(
14-
private string $name,
15-
private NamedTypeRef $typeCond,
16-
private DirectiveSet $directives,
17-
private FieldSet $fields,
14+
public string $name,
15+
public NamedTypeRef $typeCond,
16+
public DirectiveSet $directives,
17+
public FieldSet $fields,
1818
)
1919
{
2020
}
21-
22-
public function getName() : string
23-
{
24-
return $this->name;
25-
}
26-
27-
public function getFields() : FieldSet
28-
{
29-
return $this->fields;
30-
}
31-
32-
public function getTypeCond() : NamedTypeRef
33-
{
34-
return $this->typeCond;
35-
}
36-
37-
public function getDirectives() : DirectiveSet
38-
{
39-
return $this->directives;
40-
}
4121
}

src/Fragment/FragmentSet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ final class FragmentSet extends ImplicitObjectMap
1717
#[\Override]
1818
protected function getKey(object $object) : string
1919
{
20-
return $object->getName(); // @phpstan-ignore method.notFound
20+
return $object->name; // @phpstan-ignore property.notFound
2121
}
2222
}

src/FragmentSpread/InlineFragmentSpread.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,13 @@
88
use Graphpinator\Parser\Field\FieldSet;
99
use Graphpinator\Parser\TypeRef\NamedTypeRef;
1010

11-
final class InlineFragmentSpread implements FragmentSpread
11+
final readonly class InlineFragmentSpread implements FragmentSpread
1212
{
13-
private DirectiveSet $directives;
14-
1513
public function __construct(
16-
private FieldSet $fields,
17-
?DirectiveSet $directives = null,
18-
private ?NamedTypeRef $typeCond = null,
14+
public FieldSet $fields,
15+
public DirectiveSet $directives = new DirectiveSet(),
16+
public ?NamedTypeRef $typeCond = null,
1917
)
2018
{
21-
$this->directives = $directives
22-
?? new DirectiveSet();
23-
}
24-
25-
public function getFields() : FieldSet
26-
{
27-
return $this->fields;
28-
}
29-
30-
public function getDirectives() : DirectiveSet
31-
{
32-
return $this->directives;
33-
}
34-
35-
public function getTypeCond() : ?NamedTypeRef
36-
{
37-
return $this->typeCond;
3819
}
3920
}

src/FragmentSpread/NamedFragmentSpread.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,16 @@
66

77
use Graphpinator\Parser\Directive\DirectiveSet;
88

9-
final class NamedFragmentSpread implements FragmentSpread
9+
final readonly class NamedFragmentSpread implements FragmentSpread
1010
{
11-
private DirectiveSet $directives;
11+
public readonly DirectiveSet $directives;
1212

1313
public function __construct(
14-
private string $name,
14+
public string $name,
1515
?DirectiveSet $directives = null,
1616
)
1717
{
1818
$this->directives = $directives
1919
?? new DirectiveSet();
2020
}
21-
22-
public function getName() : string
23-
{
24-
return $this->name;
25-
}
26-
27-
public function getDirectives() : DirectiveSet
28-
{
29-
return $this->directives;
30-
}
3121
}

src/Operation/Operation.php

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,15 @@
99
use Graphpinator\Parser\OperationType;
1010
use Graphpinator\Parser\Variable\VariableSet;
1111

12-
final class Operation
12+
final readonly class Operation
1313
{
14-
private VariableSet $variables;
15-
private DirectiveSet $directives;
16-
1714
public function __construct(
18-
private OperationType $type,
19-
private ?string $name,
20-
?VariableSet $variables,
21-
?DirectiveSet $directives,
22-
private FieldSet $children,
15+
public OperationType $type,
16+
public FieldSet $children,
17+
public ?string $name = null,
18+
public VariableSet $variables = new VariableSet(),
19+
public DirectiveSet $directives = new DirectiveSet(),
2320
)
2421
{
25-
$this->variables = $variables
26-
?? new VariableSet();
27-
$this->directives = $directives
28-
?? new DirectiveSet();
29-
}
30-
31-
public function getType() : OperationType
32-
{
33-
return $this->type;
34-
}
35-
36-
public function getName() : ?string
37-
{
38-
return $this->name;
39-
}
40-
41-
public function getFields() : FieldSet
42-
{
43-
return $this->children;
44-
}
45-
46-
public function getVariables() : VariableSet
47-
{
48-
return $this->variables;
49-
}
50-
51-
public function getDirectives() : DirectiveSet
52-
{
53-
return $this->directives;
5422
}
5523
}

src/Operation/OperationSet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class OperationSet extends ImplicitObjectMap
1717
#[\Override]
1818
protected function getKey(object $object) : string
1919
{
20-
return $object->getName() // @phpstan-ignore method.notFound
20+
return $object->name // @phpstan-ignore property.notFound
2121
?? '';
2222
}
2323
}

src/ParsedRequest.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,12 @@
77
use Graphpinator\Parser\Fragment\FragmentSet;
88
use Graphpinator\Parser\Operation\OperationSet;
99

10-
final class ParsedRequest
10+
final readonly class ParsedRequest
1111
{
1212
public function __construct(
13-
private OperationSet $operations,
14-
private FragmentSet $fragments,
13+
public OperationSet $operations,
14+
public FragmentSet $fragments,
1515
)
1616
{
1717
}
18-
19-
public function getOperations() : OperationSet
20-
{
21-
return $this->operations;
22-
}
23-
24-
public function getFragments() : FragmentSet
25-
{
26-
return $this->fragments;
27-
}
2818
}

0 commit comments

Comments
 (0)