Skip to content
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
9 changes: 7 additions & 2 deletions src/Plugin/Generator/ProtoGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ private function generateOneof(
->addComment('@api')
->addComment('@phpstan-sealed (')
->addComment(implode(" |\n", array_map(
static fn(Parser\FieldDescriptor $variant) => \sprintf(' %s%s', $interfaceName, Naming::pascalCase($variant->name)),
static fn(Parser\FieldDescriptor $variant) => \sprintf(' %s', self::oneofVariantName($oneof->name, $variant->name)),
$variants,
)))
->addComment(')');
Expand All @@ -381,7 +381,7 @@ private function generateOneofVariant(
Parser\FieldDescriptor $variant,
): iterable {
$interfaceName = Naming::pascalCase($oneof->name);
$className = \sprintf('%s%s', $interfaceName, Naming::pascalCase($variant->name));
$className = self::oneofVariantName($oneof->name, $variant->name);

$descriptor = new Parser\MessageDescriptor(
name: $className,
Expand Down Expand Up @@ -448,4 +448,9 @@ private function parseDefaultValue(
default => null,
};
}

private static function oneofVariantName(string $oneof, string $variant): string
{
return Naming::pascalCase("{$oneof} {$variant}");
}
}
44 changes: 44 additions & 0 deletions tests/fixtures/sealed_interface/underscore_collision/test.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
syntax = "proto3";

package pg_query;

message Node {
oneof node {
Integer integer = 263 [json_name="Integer"];
Float float = 264 [json_name="Float"];
Boolean boolean = 265 [json_name="Boolean"];
String string = 266 [json_name="String"];
BitString bit_string = 267 [json_name="BitString"];
List list = 268 [json_name="List"];
}
}

message Integer
{
int32 ival = 1;
}

message Float
{
string fval = 1;
}

message Boolean
{
bool boolval = 1;
}

message String
{
string sval = 1;
}

message BitString
{
string bsval = 1;
}

message List
{
repeated Node items = 1;
}
26 changes: 26 additions & 0 deletions tests/snapshots/sealed_interface/PgQuery/BitString.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.x-dev
* protoc — v6.32.1
* Source: underscore_collision/test.proto
*/

declare(strict_types=1);

namespace PgQuery;

use Thesis\Protobuf\Reflection;

/**
* @api
*/
final readonly class BitString
{
public function __construct(
#[Reflection\Field(1, Reflection\StringT::T)]
public string $bsval = '',
) {}
}
26 changes: 26 additions & 0 deletions tests/snapshots/sealed_interface/PgQuery/Boolean.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.x-dev
* protoc — v6.32.1
* Source: underscore_collision/test.proto
*/

declare(strict_types=1);

namespace PgQuery;

use Thesis\Protobuf\Reflection;

/**
* @api
*/
final readonly class Boolean
{
public function __construct(
#[Reflection\Field(1, Reflection\BoolT::T)]
public bool $boolval = false,
) {}
}
26 changes: 26 additions & 0 deletions tests/snapshots/sealed_interface/PgQuery/Float_.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.x-dev
* protoc — v6.32.1
* Source: underscore_collision/test.proto
*/

declare(strict_types=1);

namespace PgQuery;

use Thesis\Protobuf\Reflection;

/**
* @api
*/
final readonly class Float_
{
public function __construct(
#[Reflection\Field(1, Reflection\StringT::T)]
public string $fval = '',
) {}
}
26 changes: 26 additions & 0 deletions tests/snapshots/sealed_interface/PgQuery/Integer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.x-dev
* protoc — v6.32.1
* Source: underscore_collision/test.proto
*/

declare(strict_types=1);

namespace PgQuery;

use Thesis\Protobuf\Reflection;

/**
* @api
*/
final readonly class Integer
{
public function __construct(
#[Reflection\Field(1, Reflection\Int32T::T)]
public int $ival = 0,
) {}
}
29 changes: 29 additions & 0 deletions tests/snapshots/sealed_interface/PgQuery/List_.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.x-dev
* protoc — v6.32.1
* Source: underscore_collision/test.proto
*/

declare(strict_types=1);

namespace PgQuery;

use Thesis\Protobuf\Reflection;

/**
* @api
*/
final readonly class List_
{
/**
* @param list<\PgQuery\Node> $items
*/
public function __construct(
#[Reflection\Field(1, new Reflection\ListT(new Reflection\ObjectT(\PgQuery\Node::class)))]
public array $items = [],
) {}
}
33 changes: 33 additions & 0 deletions tests/snapshots/sealed_interface/PgQuery/Node.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.x-dev
* protoc — v6.32.1
* Source: underscore_collision/test.proto
*/

declare(strict_types=1);

namespace PgQuery;

use Thesis\Protobuf\Reflection;

/**
* @api
*/
final readonly class Node
{
public function __construct(
#[Reflection\OneOf([
\PgQuery\Node\NodeInteger::class,
\PgQuery\Node\NodeFloat::class,
\PgQuery\Node\NodeBoolean::class,
\PgQuery\Node\NodeString::class,
\PgQuery\Node\NodeBitString::class,
\PgQuery\Node\NodeList::class,
])]
public ?\PgQuery\Node\Node $node = null,
) {}
}
26 changes: 26 additions & 0 deletions tests/snapshots/sealed_interface/PgQuery/Node/Node.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.x-dev
* protoc — v6.32.1
* Source: underscore_collision/test.proto
*/

declare(strict_types=1);

namespace PgQuery\Node;

/**
* @api
* @phpstan-sealed (
* NodeInteger |
* NodeFloat |
* NodeBoolean |
* NodeString |
* NodeBitString |
* NodeList
* )
*/
interface Node {}
26 changes: 26 additions & 0 deletions tests/snapshots/sealed_interface/PgQuery/Node/NodeBitString.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.x-dev
* protoc — v6.32.1
* Source: underscore_collision/test.proto
*/

declare(strict_types=1);

namespace PgQuery\Node;

use Thesis\Protobuf\Reflection;

/**
* @api
*/
final readonly class NodeBitString implements \PgQuery\Node\Node
{
public function __construct(
#[Reflection\Field(267, new Reflection\ObjectT(\PgQuery\BitString::class))]
public ?\PgQuery\BitString $BitString = null,
) {}
}
26 changes: 26 additions & 0 deletions tests/snapshots/sealed_interface/PgQuery/Node/NodeBoolean.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.x-dev
* protoc — v6.32.1
* Source: underscore_collision/test.proto
*/

declare(strict_types=1);

namespace PgQuery\Node;

use Thesis\Protobuf\Reflection;

/**
* @api
*/
final readonly class NodeBoolean implements \PgQuery\Node\Node
{
public function __construct(
#[Reflection\Field(265, new Reflection\ObjectT(\PgQuery\Boolean::class))]
public ?\PgQuery\Boolean $Boolean = null,
) {}
}
26 changes: 26 additions & 0 deletions tests/snapshots/sealed_interface/PgQuery/Node/NodeFloat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.x-dev
* protoc — v6.32.1
* Source: underscore_collision/test.proto
*/

declare(strict_types=1);

namespace PgQuery\Node;

use Thesis\Protobuf\Reflection;

/**
* @api
*/
final readonly class NodeFloat implements \PgQuery\Node\Node
{
public function __construct(
#[Reflection\Field(264, new Reflection\ObjectT(\PgQuery\Float_::class))]
public ?\PgQuery\Float_ $Float = null,
) {}
}
26 changes: 26 additions & 0 deletions tests/snapshots/sealed_interface/PgQuery/Node/NodeInteger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* Code generated by thesis/protoc-plugin. DO NOT EDIT.
* Versions:
* thesis/protoc-plugin — v0.1.x-dev
* protoc — v6.32.1
* Source: underscore_collision/test.proto
*/

declare(strict_types=1);

namespace PgQuery\Node;

use Thesis\Protobuf\Reflection;

/**
* @api
*/
final readonly class NodeInteger implements \PgQuery\Node\Node
{
public function __construct(
#[Reflection\Field(263, new Reflection\ObjectT(\PgQuery\Integer::class))]
public ?\PgQuery\Integer $Integer = null,
) {}
}
Loading
Loading