diff --git a/src/Generator/Client.php b/src/Generator/Client.php index 25ff0e1..ad86b9c 100644 --- a/src/Generator/Client.php +++ b/src/Generator/Client.php @@ -59,15 +59,7 @@ public static function generate(Configuration $configuration, string $pathPrefix $factory = new BuilderFactory(); $stmt = $factory->namespace(trim($configuration->namespace->source, '\\')); - $class = $factory->class('Client')->implement(new Node\Name('ClientInterface'))->makeFinal()->addStmt( - $factory->property('authentication')->setType('\\' . AuthenticationInterface::class)->makeReadonly()->makePrivate(), - )->addStmt( - $factory->property('browser')->setType('\\' . Browser::class)->makeReadonly()->makePrivate(), - )->addStmt( - $factory->property('requestSchemaValidator')->setType('\League\OpenAPIValidation\Schema\SchemaValidator')->makeReadonly()->makePrivate(), - )->addStmt( - $factory->property('responseSchemaValidator')->setType('\League\OpenAPIValidation\Schema\SchemaValidator')->makeReadonly()->makePrivate(), - ); + $class = $factory->class('Client')->implement(new Node\Name('ClientInterface'))->makeFinal(); if ($configuration->entryPoints->call) { $class->addStmt( @@ -88,20 +80,10 @@ public static function generate(Configuration $configuration, string $pathPrefix } $class->addStmt( - $factory->property('hydrators')->setType('Hydrators')->makeReadonly()->makePrivate(), - )->addStmt( $factory->property('routers')->setType('Routers')->makeReadonly()->makePrivate(), )->addStmt( $factory->method('__construct')->makePublic()->addParam( (new Param('authentication'))->setType('\\' . AuthenticationInterface::class), - )->addStmt( - new Node\Expr\Assign( - new Node\Expr\PropertyFetch( - new Node\Expr\Variable('this'), - 'authentication', - ), - new Node\Expr\Variable('authentication'), - ), )->addParam( (new Param('browser'))->setType('\\' . Browser::class), )->addStmt((static function (Representation\Client $client): Node\Expr { @@ -119,24 +101,21 @@ public static function generate(Configuration $configuration, string $pathPrefix ); } - return new Node\Expr\Assign(new Node\Expr\PropertyFetch( - new Node\Expr\Variable('this'), - 'browser', - ), new Node\Expr\MethodCall( - $assignExpr, - 'withFollowRedirects', - [ - new Arg( - new Node\Expr\ConstFetch(new Node\Name('false')), - ), - ], - )); + return new Node\Expr\Assign( + new Node\Expr\Variable('browser'), + new Node\Expr\MethodCall( + $assignExpr, + 'withFollowRedirects', + [ + new Arg( + new Node\Expr\ConstFetch(new Node\Name('false')), + ), + ], + ), + ); })($client))->addStmt( new Node\Expr\Assign( - new Node\Expr\PropertyFetch( - new Node\Expr\Variable('this'), - 'requestSchemaValidator', - ), + new Node\Expr\Variable('requestSchemaValidator'), new Node\Expr\New_( new Node\Name('\League\OpenAPIValidation\Schema\SchemaValidator'), [ @@ -149,10 +128,7 @@ public static function generate(Configuration $configuration, string $pathPrefix ), )->addStmt( new Node\Expr\Assign( - new Node\Expr\PropertyFetch( - new Node\Expr\Variable('this'), - 'responseSchemaValidator', - ), + new Node\Expr\Variable('responseSchemaValidator'), new Node\Expr\New_( new Node\Name('\League\OpenAPIValidation\Schema\SchemaValidator'), [ @@ -165,10 +141,7 @@ public static function generate(Configuration $configuration, string $pathPrefix ), )->addStmt( new Node\Expr\Assign( - new Node\Expr\PropertyFetch( - new Node\Expr\Variable('this'), - 'hydrators', - ), + new Node\Expr\Variable('hydrators'), new Node\Expr\New_( new Node\Name('Hydrators'), [], @@ -185,50 +158,35 @@ public static function generate(Configuration $configuration, string $pathPrefix new Node\Name('Operations'), [ new Arg( - new Node\Expr\PropertyFetch( - new Node\Expr\Variable('this'), - 'browser', - ), + new Node\Expr\Variable('browser'), false, false, [], new Node\Identifier('browser'), ), new Arg( - new Node\Expr\PropertyFetch( - new Node\Expr\Variable('this'), - 'authentication', - ), + new Node\Expr\Variable('authentication'), false, false, [], new Node\Identifier('authentication'), ), new Arg( - new Node\Expr\PropertyFetch( - new Node\Expr\Variable('this'), - 'requestSchemaValidator', - ), + new Node\Expr\Variable('requestSchemaValidator'), false, false, [], new Node\Identifier('requestSchemaValidator'), ), new Arg( - new Node\Expr\PropertyFetch( - new Node\Expr\Variable('this'), - 'responseSchemaValidator', - ), + new Node\Expr\Variable('responseSchemaValidator'), false, false, [], new Node\Identifier('responseSchemaValidator'), ), new Arg( - new Node\Expr\PropertyFetch( - new Node\Expr\Variable('this'), - 'hydrators', - ), + new Node\Expr\Variable('hydrators'), false, false, [], diff --git a/tests/app/etc/openapi-client-generator.state b/tests/app/etc/openapi-client-generator.state index 3a44a75..9388a81 100644 --- a/tests/app/etc/openapi-client-generator.state +++ b/tests/app/etc/openapi-client-generator.state @@ -204,7 +204,7 @@ }, { "name": ".\/tests\/app\/src\/\/Client.php", - "hash": "6ff122e2242b2a6e4485e102494cb16e" + "hash": "ee4a2025a9354a33e9bb90bf8bc01f4b" }, { "name": ".\/tests\/app\/src\/\/Router\/Get\/Pets.php", diff --git a/tests/app/src/Client.php b/tests/app/src/Client.php index e18faaf..539255d 100644 --- a/tests/app/src/Client.php +++ b/tests/app/src/Client.php @@ -15,22 +15,16 @@ use ApiClients\Contracts; final class Client implements ClientInterface { - private readonly \ApiClients\Contracts\HTTP\Headers\AuthenticationInterface $authentication; - private readonly \React\Http\Browser $browser; - private readonly \League\OpenAPIValidation\Schema\SchemaValidator $requestSchemaValidator; - private readonly \League\OpenAPIValidation\Schema\SchemaValidator $responseSchemaValidator; private array $router = array(); private readonly OperationsInterface $operations; - private readonly Hydrators $hydrators; private readonly Routers $routers; public function __construct(\ApiClients\Contracts\HTTP\Headers\AuthenticationInterface $authentication, \React\Http\Browser $browser) { - $this->authentication = $authentication; - $this->browser = $browser->withBase('http://petstore.swagger.io/v1')->withFollowRedirects(false); - $this->requestSchemaValidator = new \League\OpenAPIValidation\Schema\SchemaValidator(\League\OpenAPIValidation\Schema\SchemaValidator::VALIDATE_AS_REQUEST); - $this->responseSchemaValidator = new \League\OpenAPIValidation\Schema\SchemaValidator(\League\OpenAPIValidation\Schema\SchemaValidator::VALIDATE_AS_RESPONSE); - $this->hydrators = new Hydrators(); - $this->operations = new Operations(browser: $this->browser, authentication: $this->authentication, requestSchemaValidator: $this->requestSchemaValidator, responseSchemaValidator: $this->responseSchemaValidator, hydrators: $this->hydrators); + $browser = $browser->withBase('http://petstore.swagger.io/v1')->withFollowRedirects(false); + $requestSchemaValidator = new \League\OpenAPIValidation\Schema\SchemaValidator(\League\OpenAPIValidation\Schema\SchemaValidator::VALIDATE_AS_REQUEST); + $responseSchemaValidator = new \League\OpenAPIValidation\Schema\SchemaValidator(\League\OpenAPIValidation\Schema\SchemaValidator::VALIDATE_AS_RESPONSE); + $hydrators = new Hydrators(); + $this->operations = new Operations(browser: $browser, authentication: $authentication, requestSchemaValidator: $requestSchemaValidator, responseSchemaValidator: $responseSchemaValidator, hydrators: $hydrators); $this->routers = new Routers(browser: $this->browser, authentication: $this->authentication, requestSchemaValidator: $this->requestSchemaValidator, responseSchemaValidator: $this->responseSchemaValidator, hydrators: $this->hydrators); } // phpcs:disable