Skip to content

Commit 0f4b686

Browse files
committed
Remove support for dumping methods
We can use properties solely.
1 parent d4fded0 commit 0f4b686

File tree

31 files changed

+2
-1055
lines changed

31 files changed

+2
-1055
lines changed

src/Config.php

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ private function __construct(
2424
public string $outputDir,
2525
public string $namespace,
2626
public string $client,
27-
public bool $dumpMethods,
2827
public bool $dumpOrThrows,
2928
public bool $dumpDefinition,
3029
public bool $useNodeNameForEdgeNodes,
@@ -61,7 +60,6 @@ public static function create(
6160
false,
6261
false,
6362
false,
64-
false,
6563
[],
6664
[],
6765
[],
@@ -78,36 +76,6 @@ public static function create(
7876
);
7977
}
8078

81-
public function enableDumpMethods() : self
82-
{
83-
// TODO Replace with clone with https://wiki.php.net/rfc/clone_with_v2 when on PHP 8.5
84-
return new self(
85-
$this->schema,
86-
$this->projectDir,
87-
$this->queriesDir,
88-
$this->outputDir,
89-
$this->namespace,
90-
$this->client,
91-
true,
92-
$this->dumpOrThrows,
93-
$this->dumpDefinition,
94-
$this->useNodeNameForEdgeNodes,
95-
$this->scalars,
96-
$this->inputObjectTypes,
97-
$this->objectTypes,
98-
$this->enumTypes,
99-
$this->ignoreTypes,
100-
$this->typeInitializers,
101-
$this->useConnectionNameForConnections,
102-
$this->useEdgeNameForEdges,
103-
$this->addNodesOnConnections,
104-
$this->addSymfonyExcludeAttribute,
105-
$this->indexByDirective,
106-
$this->addUnknownCaseToEnums,
107-
$this->dumpEnumIsMethods,
108-
);
109-
}
110-
11179
public function enableDumpOrThrows() : self
11280
{
11381
return new self(
@@ -117,7 +85,6 @@ public function enableDumpOrThrows() : self
11785
$this->outputDir,
11886
$this->namespace,
11987
$this->client,
120-
$this->dumpMethods,
12188
true,
12289
$this->dumpDefinition,
12390
$this->useNodeNameForEdgeNodes,
@@ -146,7 +113,6 @@ public function enableDumpDefinition() : self
146113
$this->outputDir,
147114
$this->namespace,
148115
$this->client,
149-
$this->dumpMethods,
150116
$this->dumpOrThrows,
151117
true,
152118
$this->useNodeNameForEdgeNodes,
@@ -175,7 +141,6 @@ public function enableUseNodeNameForEdgeNodes() : self
175141
$this->outputDir,
176142
$this->namespace,
177143
$this->client,
178-
$this->dumpMethods,
179144
$this->dumpOrThrows,
180145
$this->dumpDefinition,
181146
true,
@@ -204,7 +169,6 @@ public function enableUseConnectionNameForConnections() : self
204169
$this->outputDir,
205170
$this->namespace,
206171
$this->client,
207-
$this->dumpMethods,
208172
$this->dumpOrThrows,
209173
$this->dumpDefinition,
210174
$this->useNodeNameForEdgeNodes,
@@ -233,7 +197,6 @@ public function enableUseEdgeNameForEdges() : self
233197
$this->outputDir,
234198
$this->namespace,
235199
$this->client,
236-
$this->dumpMethods,
237200
$this->dumpOrThrows,
238201
$this->dumpDefinition,
239202
$this->useNodeNameForEdgeNodes,
@@ -262,7 +225,6 @@ public function enableAddNodesOnConnections() : self
262225
$this->outputDir,
263226
$this->namespace,
264227
$this->client,
265-
$this->dumpMethods,
266228
$this->dumpOrThrows,
267229
$this->dumpDefinition,
268230
$this->useNodeNameForEdgeNodes,
@@ -291,7 +253,6 @@ public function enableAddSymfonyExcludeAttribute() : self
291253
$this->outputDir,
292254
$this->namespace,
293255
$this->client,
294-
$this->dumpMethods,
295256
$this->dumpOrThrows,
296257
$this->dumpDefinition,
297258
$this->useNodeNameForEdgeNodes,
@@ -320,7 +281,6 @@ public function enableIndexByDirective() : self
320281
$this->outputDir,
321282
$this->namespace,
322283
$this->client,
323-
$this->dumpMethods,
324284
$this->dumpOrThrows,
325285
$this->dumpDefinition,
326286
$this->useNodeNameForEdgeNodes,
@@ -349,7 +309,6 @@ public function enableAddUnknownCaseToEnums() : self
349309
$this->outputDir,
350310
$this->namespace,
351311
$this->client,
352-
$this->dumpMethods,
353312
$this->dumpOrThrows,
354313
$this->dumpDefinition,
355314
$this->useNodeNameForEdgeNodes,
@@ -378,7 +337,6 @@ public function enableDumpEnumIsMethods() : self
378337
$this->outputDir,
379338
$this->namespace,
380339
$this->client,
381-
$this->dumpMethods,
382340
$this->dumpOrThrows,
383341
$this->dumpDefinition,
384342
$this->useNodeNameForEdgeNodes,
@@ -410,7 +368,6 @@ public function withScalar(string $name, Type $type, ?Type $payloadType = null)
410368
$this->outputDir,
411369
$this->namespace,
412370
$this->client,
413-
$this->dumpMethods,
414371
$this->dumpOrThrows,
415372
$this->dumpDefinition,
416373
$this->useNodeNameForEdgeNodes,
@@ -442,7 +399,6 @@ public function withInputObjectType(string $name, Type $type) : self
442399
$this->outputDir,
443400
$this->namespace,
444401
$this->client,
445-
$this->dumpMethods,
446402
$this->dumpOrThrows,
447403
$this->dumpDefinition,
448404
$this->useNodeNameForEdgeNodes,
@@ -474,7 +430,6 @@ public function withObjectType(string $name, Type $payloadShape, Type $payloadTy
474430
$this->outputDir,
475431
$this->namespace,
476432
$this->client,
477-
$this->dumpMethods,
478433
$this->dumpOrThrows,
479434
$this->dumpDefinition,
480435
$this->useNodeNameForEdgeNodes,
@@ -506,7 +461,6 @@ public function withEnumType(string $name, Type $type) : self
506461
$this->outputDir,
507462
$this->namespace,
508463
$this->client,
509-
$this->dumpMethods,
510464
$this->dumpOrThrows,
511465
$this->dumpDefinition,
512466
$this->useNodeNameForEdgeNodes,
@@ -538,7 +492,6 @@ public function withIgnoreType(string $type) : self
538492
$this->outputDir,
539493
$this->namespace,
540494
$this->client,
541-
$this->dumpMethods,
542495
$this->dumpOrThrows,
543496
$this->dumpDefinition,
544497
$this->useNodeNameForEdgeNodes,
@@ -570,7 +523,6 @@ public function withTypeInitializer(TypeInitializer\TypeInitializer $typeInitial
570523
$this->outputDir,
571524
$this->namespace,
572525
$this->client,
573-
$this->dumpMethods,
574526
$this->dumpOrThrows,
575527
$this->dumpDefinition,
576528
$this->useNodeNameForEdgeNodes,

src/Generator/AbstractGenerator.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,4 @@ protected function getNakedType(Type $type) : Type
145145

146146
return $type;
147147
}
148-
149-
protected function getterMethod(string $name) : string
150-
{
151-
if (preg_match('/^(as|is)[A-Z]/', lcfirst($name)) === 1) {
152-
return lcfirst($name);
153-
}
154-
155-
return sprintf('get%s', ucfirst($name));
156-
}
157148
}

src/Generator/DataClassGenerator.php

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -490,99 +490,6 @@ function () use ($parentType, $nodesType, $possibleTypes, $fields, $isData, $pay
490490
} else {
491491
yield ') {}';
492492
}
493-
494-
if ($this->config->dumpMethods && $fields instanceof ArrayShapeType) {
495-
foreach ($fields->getShape() as $fieldName => $fieldValue) {
496-
Assert::string($fieldName);
497-
498-
if ($fieldName === '__typename') {
499-
continue;
500-
}
501-
502-
// Get the field type and check if it's optional
503-
$fieldType = $fieldValue['type'];
504-
$optional = $fieldValue['optional'];
505-
506-
// Check if field is optional in payloadShape
507-
$optional = $optional || isset($optionalFields[$fieldName]);
508-
509-
// For optional fields, make the return type nullable if it isn't already
510-
$dumpMethodType = $optional && ! ($fieldType instanceof SymfonyType\NullableType)
511-
? SymfonyType::nullable($fieldType)
512-
: $fieldType;
513-
514-
yield '';
515-
516-
if ($this->getNakedType($dumpMethodType) instanceof SymfonyType\CollectionType) {
517-
yield from $generator->docComment(sprintf(
518-
'@return %s',
519-
$this->dumpPHPDocType($dumpMethodType, $generator->import(...)),
520-
));
521-
}
522-
523-
yield sprintf(
524-
'public function %s() : %s',
525-
$this->getterMethod($fieldName),
526-
$this->dumpPHPType($dumpMethodType, $generator->import(...)),
527-
);
528-
yield '{';
529-
yield $generator->indent(function () use ($fieldName) {
530-
yield sprintf('return $this->%s;', $fieldName);
531-
});
532-
yield '}';
533-
534-
if ($this->config->dumpOrThrows && $dumpMethodType instanceof SymfonyType\NullableType) {
535-
$unwrappedType = $dumpMethodType->getWrappedType();
536-
537-
yield '';
538-
yield from $generator->docComment(function () use ($unwrappedType, $generator) {
539-
if ($this->getNakedType($unwrappedType) instanceof SymfonyType\CollectionType) {
540-
yield sprintf(
541-
'@return %s',
542-
$this->dumpPHPDocType($unwrappedType, $generator->import(...)),
543-
);
544-
}
545-
546-
yield sprintf('@throws %s', $generator->import($this->fullyQualified('NodeNotFoundException')));
547-
});
548-
yield sprintf(
549-
'public function %sOrThrow() : %s',
550-
$this->getterMethod($fieldName),
551-
$this->dumpPHPType($unwrappedType, $generator->import(...)),
552-
);
553-
yield '{';
554-
yield $generator->indent(function () use ($fieldName) {
555-
yield sprintf('return $this->%sOrThrow;', $fieldName);
556-
});
557-
yield '}';
558-
}
559-
}
560-
}
561-
562-
if ($isData && $this->config->dumpMethods) {
563-
yield '';
564-
yield from $generator->docComment('@return list<Error>');
565-
yield 'public function getErrors() : array';
566-
yield '{';
567-
yield $generator->indent(function () {
568-
yield 'return $this->errors;';
569-
});
570-
yield '}';
571-
}
572-
573-
if ($nodesType !== null && $this->config->dumpMethods) {
574-
yield '';
575-
yield from $generator->docComment(sprintf(
576-
'@return %s',
577-
$this->dumpPHPDocType($nodesType, $generator->import(...)),
578-
));
579-
yield 'public function getNodes() : array';
580-
yield '{';
581-
yield $generator->indent(function () {
582-
yield 'return $this->nodes;';
583-
});
584-
yield '}';
585-
}
586493
},
587494
);
588495
yield '}';

src/Generator/EnumTypeGenerator.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function generate(EnumClassPlan $plan) : string
4444
yield 'case Unknown__ = \'unknown__\';';
4545
}
4646

47-
if ($this->config->dumpMethods || $this->config->dumpEnumIsMethods) {
47+
if ($this->config->dumpEnumIsMethods) {
4848
$numberOfValues = count($plan->values);
4949
foreach ($plan->values as $value) {
5050
yield '';
@@ -62,19 +62,6 @@ public function generate(EnumClassPlan $plan) : string
6262
);
6363
});
6464
yield '}';
65-
66-
if ($this->config->dumpMethods) {
67-
yield '';
68-
yield sprintf(
69-
'public static function create%s() : self',
70-
u($value['value'])->lower()->pascal()->toString(),
71-
);
72-
yield '{';
73-
yield $generator->indent(function () use ($value) {
74-
yield sprintf('return self::%s;', u($value['value'])->lower()->pascal()->toString());
75-
});
76-
yield '}';
77-
}
7865
}
7966
}
8067
});

0 commit comments

Comments
 (0)