Skip to content

Commit 8ee97b2

Browse files
authored
Merge pull request #194 from php-api-clients/drop-match-route-match-tracking-and-always-something-is-returned-or-throw
Drop match route match tracking and always something is returned or throw
2 parents 60e8dd2 + f4f6926 commit 8ee97b2

File tree

14 files changed

+25
-126
lines changed

14 files changed

+25
-126
lines changed

src/Generator/Client.php

Lines changed: 7 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,6 @@ public static function generate(Configuration $configuration, string $pathPrefix
372372
new Node\Scalar\LNumber($chunkCount),
373373
),
374374
[
375-
new Node\Stmt\Expression(
376-
new Node\Expr\Assign(
377-
new Node\Expr\Variable('matched'),
378-
new Expr\ConstFetch(
379-
new Node\Name('true'),
380-
),
381-
),
382-
),
383375
new Node\Stmt\If_(
384376
new Node\Expr\BinaryOp\Equal(
385377
new Node\Expr\FuncCall(
@@ -632,30 +624,11 @@ public static function generate(Configuration $configuration, string $pathPrefix
632624
],
633625
),
634626
),
635-
)->addStmt(
636-
new Node\Expr\Assign(
637-
new Node\Expr\Variable('matched'),
638-
new Expr\ConstFetch(
639-
new Node\Name('false'),
640-
),
641-
),
642627
)->addStmt($operationsIf)->addStmt(
643-
new Node\Stmt\If_(
644-
new Expr\BinaryOp\Identical(
645-
new Node\Expr\Variable('matched'),
646-
new Expr\ConstFetch(
647-
new Node\Name('false'),
648-
),
628+
new Node\Stmt\Throw_(
629+
new Node\Expr\New_(
630+
new Node\Name('\InvalidArgumentException'),
649631
),
650-
[
651-
'stmts' => [
652-
new Node\Stmt\Throw_(
653-
new Node\Expr\New_(
654-
new Node\Name('\InvalidArgumentException'),
655-
),
656-
),
657-
],
658-
],
659632
),
660633
),
661634
);
@@ -872,14 +845,6 @@ private static function callOperation(Routers $routers, Representation\Operation
872845
$returnType,
873846
Operation::getDocBlockResultTypeFromOperation($operation),
874847
[
875-
new Node\Stmt\Expression(
876-
new Node\Expr\Assign(
877-
new Node\Expr\Variable('matched'),
878-
new Expr\ConstFetch(
879-
new Node\Name('true'),
880-
),
881-
),
882-
),
883848
...(count($operation->parameters) > 0 ? [
884849
new Node\Stmt\Expression(new Node\Expr\Assign(
885850
new Node\Expr\Variable('arguments'),
@@ -1038,14 +1003,6 @@ private static function callOperation(Routers $routers, Representation\Operation
10381003
$returnOrExpression = $returnType === 'void' ? Node\Stmt\Expression::class : Node\Stmt\Return_::class;
10391004

10401005
return [
1041-
new Node\Stmt\Expression(
1042-
new Node\Expr\Assign(
1043-
new Node\Expr\Variable('matched'),
1044-
new Expr\ConstFetch(
1045-
new Node\Name('true'),
1046-
),
1047-
),
1048-
),
10491006
new Node\Stmt\If_(
10501007
new Node\Expr\BinaryOp\Equal(
10511008
new Node\Expr\FuncCall(
@@ -1250,30 +1207,11 @@ private static function createRouterChunkSize(string $pathPrefix, string $namesp
12501207
'params' => 'array',
12511208
'pathChunks' => 'array',
12521209
]),
1253-
])->addStmt(
1254-
new Node\Expr\Assign(
1255-
new Node\Expr\Variable('matched'),
1256-
new Expr\ConstFetch(
1257-
new Node\Name('false'),
1258-
),
1259-
),
1260-
)->addStmts($chunkCount->nodes)->addStmt(
1261-
new Node\Stmt\If_(
1262-
new Expr\BinaryOp\Identical(
1263-
new Node\Expr\Variable('matched'),
1264-
new Expr\ConstFetch(
1265-
new Node\Name('false'),
1266-
),
1210+
])->addStmts($chunkCount->nodes)->addStmt(
1211+
new Node\Stmt\Throw_(
1212+
new Node\Expr\New_(
1213+
new Node\Name('\InvalidArgumentException'),
12671214
),
1268-
[
1269-
'stmts' => [
1270-
new Node\Stmt\Throw_(
1271-
new Node\Expr\New_(
1272-
new Node\Name('\InvalidArgumentException'),
1273-
),
1274-
),
1275-
],
1276-
],
12771215
),
12781216
);
12791217

tests/app/etc/openapi-client-generator.state

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,47 +204,47 @@
204204
},
205205
{
206206
"name": ".\/tests\/app\/src\/\/Client.php",
207-
"hash": "9293562fe84f77ab4ea129c82fd1e43f"
207+
"hash": "719d8221d11509ec31f017f2bd54cb1e"
208208
},
209209
{
210210
"name": ".\/tests\/app\/src\/\/Router\/Get\/Pets.php",
211-
"hash": "1fd2d2789f74f5cc247877c9a7076641"
211+
"hash": "68179fe011002d1b456b8f3598380a67"
212212
},
213213
{
214214
"name": ".\/tests\/app\/src\/\/Router\/Get\/PetsList.php",
215-
"hash": "3c6413f1a6bdd8f509ed0b27bb3405af"
215+
"hash": "61aa5045f5b53d6edfd8eded49fcde80"
216216
},
217217
{
218218
"name": ".\/tests\/app\/src\/\/Router\/List\/Pets.php",
219-
"hash": "aa71bff5fc6f1a06f10075ca6de99741"
219+
"hash": "5bc8638e735e4e3a16359b144b03b640"
220220
},
221221
{
222222
"name": ".\/tests\/app\/src\/\/Router\/List\/PetsList.php",
223-
"hash": "7094cde20b9f6de276d1dbbb4dbd2baf"
223+
"hash": "2e4dc5732c808e2d2047203c6f881c05"
224224
},
225225
{
226226
"name": ".\/tests\/app\/src\/\/Router\/Post\/Pets.php",
227-
"hash": "51b996123dc285755f528f680d5d75d3"
227+
"hash": "e25d1cae2ac66fc5c4081ac3655fb413"
228228
},
229229
{
230230
"name": ".\/tests\/app\/src\/\/Router\/Get\/Two.php",
231-
"hash": "5d568f67586671f63d3be287c88fceb8"
231+
"hash": "a0e0ed35a37774016b138af026b36f77"
232232
},
233233
{
234234
"name": ".\/tests\/app\/src\/\/Router\/Get\/Three.php",
235-
"hash": "1b533c4496a7a58b1c3626110e7455b5"
235+
"hash": "fe90c28538f6f8e8e7844ffc1cee7d0c"
236236
},
237237
{
238238
"name": ".\/tests\/app\/src\/\/Router\/List\/Two.php",
239-
"hash": "0a13bba21af357741a0a0cfbb3eb2da1"
239+
"hash": "acfddb57c7bfe66131602af16078e64e"
240240
},
241241
{
242242
"name": ".\/tests\/app\/src\/\/Router\/List\/Three.php",
243-
"hash": "68b44592ee664f942e50253a7ba18640"
243+
"hash": "25ba6590befb6bee1dbf71b48ddbb81b"
244244
},
245245
{
246246
"name": ".\/tests\/app\/src\/\/Router\/Post\/Two.php",
247-
"hash": "8b6bf0563afd6c79e6df2398463a411d"
247+
"hash": "609aaf14d32b8bc5bb9cef46fe7e3a93"
248248
},
249249
{
250250
"name": ".\/tests\/app\/src\/\/OperationsInterface.php",
@@ -284,7 +284,7 @@
284284
},
285285
{
286286
"name": ".\/tests\/app\/src\/\/Router\/Get.php",
287-
"hash": "4acce87dd62158f7e04dfc3f3c525c33"
287+
"hash": "64270922a47a8ea29f38370be61608bc"
288288
}
289289
]
290290
},

tests/app/src/Client.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,47 +41,39 @@ public function call(string $call, array $params = array()) : iterable|\ApiClien
4141
[$method, $path] = explode(' ', $call);
4242
$pathChunks = explode('/', $path);
4343
$pathChunksCount = count($pathChunks);
44-
$matched = false;
4544
if ($method === 'GET') {
4645
if ($pathChunksCount === 2) {
47-
$matched = true;
4846
if (\array_key_exists(Router\Get\Two::class, $this->router) == false) {
4947
$this->router[Router\Get\Two::class] = new Router\Get\Two(browser: $this->browser, authentication: $this->authentication, requestSchemaValidator: $this->requestSchemaValidator, responseSchemaValidator: $this->responseSchemaValidator, hydrators: $this->hydrators);
5048
}
5149
return $this->router[Router\Get\Two::class]->call($call, $params, $pathChunks);
5250
} elseif ($pathChunksCount === 3) {
53-
$matched = true;
5451
if (\array_key_exists(Router\Get\Three::class, $this->router) == false) {
5552
$this->router[Router\Get\Three::class] = new Router\Get\Three(browser: $this->browser, authentication: $this->authentication, requestSchemaValidator: $this->requestSchemaValidator, responseSchemaValidator: $this->responseSchemaValidator, hydrators: $this->hydrators);
5653
}
5754
return $this->router[Router\Get\Three::class]->call($call, $params, $pathChunks);
5855
}
5956
} elseif ($method === 'LIST') {
6057
if ($pathChunksCount === 2) {
61-
$matched = true;
6258
if (\array_key_exists(Router\List\Two::class, $this->router) == false) {
6359
$this->router[Router\List\Two::class] = new Router\List\Two(browser: $this->browser, authentication: $this->authentication, requestSchemaValidator: $this->requestSchemaValidator, responseSchemaValidator: $this->responseSchemaValidator, hydrators: $this->hydrators);
6460
}
6561
return $this->router[Router\List\Two::class]->call($call, $params, $pathChunks);
6662
} elseif ($pathChunksCount === 3) {
67-
$matched = true;
6863
if (\array_key_exists(Router\List\Three::class, $this->router) == false) {
6964
$this->router[Router\List\Three::class] = new Router\List\Three(browser: $this->browser, authentication: $this->authentication, requestSchemaValidator: $this->requestSchemaValidator, responseSchemaValidator: $this->responseSchemaValidator, hydrators: $this->hydrators);
7065
}
7166
return $this->router[Router\List\Three::class]->call($call, $params, $pathChunks);
7267
}
7368
} elseif ($method === 'POST') {
7469
if ($pathChunksCount === 2) {
75-
$matched = true;
7670
if (\array_key_exists(Router\Post\Two::class, $this->router) == false) {
7771
$this->router[Router\Post\Two::class] = new Router\Post\Two(browser: $this->browser, authentication: $this->authentication, requestSchemaValidator: $this->requestSchemaValidator, responseSchemaValidator: $this->responseSchemaValidator, hydrators: $this->hydrators);
7872
}
7973
return $this->router[Router\Post\Two::class]->call($call, $params, $pathChunks);
8074
}
8175
}
82-
if ($matched === false) {
83-
throw new \InvalidArgumentException();
84-
}
76+
throw new \InvalidArgumentException();
8577
}
8678
public function operations() : OperationsInterface
8779
{

tests/app/src/Router/Get.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function __construct(private \League\OpenAPIValidation\Schema\SchemaValid
2727
*/
2828
public function showPetById(array $params) : \ApiClients\Client\PetStore\Schema\Cat|\ApiClients\Client\PetStore\Schema\Dog|\ApiClients\Client\PetStore\Schema\Bird|\ApiClients\Client\PetStore\Schema\Fish|array
2929
{
30-
$matched = true;
3130
if (\array_key_exists(Hydrator\Operation\Pets\PetId::class, $this->hydrator) == false) {
3231
$this->hydrator[Hydrator\Operation\Pets\PetId::class] = $this->hydrators->getObjectMapperOperation🌀Pets🌀PetId();
3332
}

tests/app/src/Router/Get/Pets.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function __construct(private \League\OpenAPIValidation\Schema\SchemaValid
2727
*/
2828
public function list(array $params) : iterable
2929
{
30-
$matched = true;
3130
$arguments = array();
3231
if (array_key_exists('per_page', $params) === false) {
3332
throw new \InvalidArgumentException('Missing mandatory field: per_page');
@@ -50,7 +49,6 @@ public function list(array $params) : iterable
5049
*/
5150
public function names(array $params) : iterable
5251
{
53-
$matched = true;
5452
$arguments = array();
5553
if (array_key_exists('per_page', $params) === false) {
5654
throw new \InvalidArgumentException('Missing mandatory field: per_page');

tests/app/src/Router/Get/PetsList.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function __construct(private \League\OpenAPIValidation\Schema\SchemaValid
2727
*/
2828
public function gatos(array $params) : iterable
2929
{
30-
$matched = true;
3130
$arguments = array();
3231
if (array_key_exists('per_page', $params) === false) {
3332
throw new \InvalidArgumentException('Missing mandatory field: per_page');

tests/app/src/Router/Get/Three.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,24 @@ public function __construct(private \League\OpenAPIValidation\Schema\SchemaValid
2424
*/
2525
public function call(string $call, array $params, array $pathChunks) : iterable|\ApiClients\Client\PetStore\Schema\Cat|\ApiClients\Client\PetStore\Schema\Dog|\ApiClients\Client\PetStore\Schema\Bird|\ApiClients\Client\PetStore\Schema\Fish
2626
{
27-
$matched = false;
2827
if ($pathChunks[0] == '') {
2928
if ($pathChunks[1] == 'pets') {
3029
if ($pathChunks[2] == 'gatos') {
3130
if ($call == 'GET /pets/gatos') {
32-
$matched = true;
3331
if (\array_key_exists(Router\Get\PetsList::class, $this->router) == false) {
3432
$this->router[Router\Get\PetsList::class] = new Router\Get\PetsList($this->requestSchemaValidator, $this->responseSchemaValidator, $this->hydrators, $this->browser, $this->authentication);
3533
}
3634
return $this->router[Router\Get\PetsList::class]->Gatos($params);
3735
}
3836
} elseif ($pathChunks[2] == 'names') {
3937
if ($call == 'GET /pets/names') {
40-
$matched = true;
4138
if (\array_key_exists(Router\Get\Pets::class, $this->router) == false) {
4239
$this->router[Router\Get\Pets::class] = new Router\Get\Pets($this->requestSchemaValidator, $this->responseSchemaValidator, $this->hydrators, $this->browser, $this->authentication);
4340
}
4441
return $this->router[Router\Get\Pets::class]->Names($params);
4542
}
4643
} elseif ($pathChunks[2] == '{petId}') {
4744
if ($call == 'GET /pets/{petId}') {
48-
$matched = true;
4945
if (\array_key_exists(Router\Get::class, $this->router) == false) {
5046
$this->router[Router\Get::class] = new Router\Get($this->requestSchemaValidator, $this->responseSchemaValidator, $this->hydrators, $this->browser, $this->authentication);
5147
}
@@ -54,8 +50,6 @@ public function call(string $call, array $params, array $pathChunks) : iterable|
5450
}
5551
}
5652
}
57-
if ($matched === false) {
58-
throw new \InvalidArgumentException();
59-
}
53+
throw new \InvalidArgumentException();
6054
}
6155
}

tests/app/src/Router/Get/Two.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,16 @@ public function __construct(private \League\OpenAPIValidation\Schema\SchemaValid
2424
*/
2525
public function call(string $call, array $params, array $pathChunks) : iterable
2626
{
27-
$matched = false;
2827
if ($pathChunks[0] == '') {
2928
if ($pathChunks[1] == 'pets') {
3029
if ($call == 'GET /pets') {
31-
$matched = true;
3230
if (\array_key_exists(Router\Get\Pets::class, $this->router) == false) {
3331
$this->router[Router\Get\Pets::class] = new Router\Get\Pets($this->requestSchemaValidator, $this->responseSchemaValidator, $this->hydrators, $this->browser, $this->authentication);
3432
}
3533
return $this->router[Router\Get\Pets::class]->List($params);
3634
}
3735
}
3836
}
39-
if ($matched === false) {
40-
throw new \InvalidArgumentException();
41-
}
37+
throw new \InvalidArgumentException();
4238
}
4339
}

tests/app/src/Router/List/Pets.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function __construct(private \League\OpenAPIValidation\Schema\SchemaValid
2727
*/
2828
public function listListing(array $params) : iterable
2929
{
30-
$matched = true;
3130
$arguments = array();
3231
if (array_key_exists('per_page', $params) === false) {
3332
throw new \InvalidArgumentException('Missing mandatory field: per_page');
@@ -55,7 +54,6 @@ public function listListing(array $params) : iterable
5554
*/
5655
public function namesListing(array $params) : iterable
5756
{
58-
$matched = true;
5957
$arguments = array();
6058
if (array_key_exists('per_page', $params) === false) {
6159
throw new \InvalidArgumentException('Missing mandatory field: per_page');

tests/app/src/Router/List/PetsList.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function __construct(private \League\OpenAPIValidation\Schema\SchemaValid
2727
*/
2828
public function gatosListing(array $params) : iterable
2929
{
30-
$matched = true;
3130
$arguments = array();
3231
if (array_key_exists('per_page', $params) === false) {
3332
throw new \InvalidArgumentException('Missing mandatory field: per_page');

0 commit comments

Comments
 (0)