diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..51d04f0 --- /dev/null +++ b/.php_cs @@ -0,0 +1,8 @@ +2.0.0-alpha" diff --git a/src/Generator/GeneratorFactory.php b/src/Generator/GeneratorFactory.php index 9457372..6fde717 100644 --- a/src/Generator/GeneratorFactory.php +++ b/src/Generator/GeneratorFactory.php @@ -19,7 +19,7 @@ class GeneratorFactory { - static public function build() + public static function build() { if (class_exists('PhpParser\ParserFactory')) { $parserFactory = new ParserFactory(); diff --git a/src/Generator/InputGeneratorTrait.php b/src/Generator/InputGeneratorTrait.php index 31e5daf..875b4e0 100644 --- a/src/Generator/InputGeneratorTrait.php +++ b/src/Generator/InputGeneratorTrait.php @@ -263,7 +263,8 @@ protected function createHeaderStatements(Operation $operation, $queryParamVaria $headers = [ new Expr\ArrayItem( - new Scalar\String_($operation->getHost()), new Scalar\String_('Host') + new Scalar\String_($operation->getHost()), + new Scalar\String_('Host') ), ]; @@ -272,32 +273,33 @@ protected function createHeaderStatements(Operation $operation, $queryParamVaria if ($produces && in_array("application/json", $produces)) { $headers[] = new Expr\ArrayItem( - new Expr\Array_( - [ + new Expr\Array_( + [ new Expr\ArrayItem( new Scalar\String_("application/json") ), - ] - ), - new Scalar\String_('Accept') - ); + ] + ), + new Scalar\String_('Accept') + ); } $consumes = $operation->getOperation()->getProduces(); if ($operation->getOperation()->getParameters() && $consumes) { $bodyParameters = array_filter( - $operation->getOperation()->getParameters(), function ($parameter) { - return $parameter instanceof BodyParameter; - } + $operation->getOperation()->getParameters(), + function ($parameter) { + return $parameter instanceof BodyParameter; + } ); if (count($bodyParameters) > 0 && in_array("application/json", $consumes)) { $headers[] = new Expr\ArrayItem( - new Scalar\String_("application/json"), - new Scalar\String_('Content-Type') - ); + new Scalar\String_("application/json"), + new Scalar\String_('Content-Type') + ); } } diff --git a/src/Generator/OperationGenerator.php b/src/Generator/OperationGenerator.php index 4d0138e..516fb5e 100644 --- a/src/Generator/OperationGenerator.php +++ b/src/Generator/OperationGenerator.php @@ -60,7 +60,8 @@ public function generate($name, Operation $operation, Context $context) // $request = $this->messageFactory->createRequest('method', $url, $headers, $body); new Expr\Assign(new Expr\Variable('request'), new Expr\MethodCall( new Expr\PropertyFetch(new Expr\Variable('this'), 'messageFactory'), - 'createRequest', [ + 'createRequest', + [ new Arg(new Scalar\String_($operation->getMethod())), new Arg($urlVariable), new Arg($headerVariable), @@ -75,7 +76,8 @@ public function generate($name, Operation $operation, Context $context) )), // if ($fetch === self::FETCH_PROMISE) { return $promise } new Stmt\If_( - new Expr\BinaryOp\Identical(new Expr\ConstFetch(new Name('self::FETCH_PROMISE')), new Expr\Variable('fetch')), [ + new Expr\BinaryOp\Identical(new Expr\ConstFetch(new Name('self::FETCH_PROMISE')), new Expr\Variable('fetch')), + [ 'stmts' => [ new Stmt\Return_(new Expr\Variable('promise')) ] @@ -110,7 +112,8 @@ public function generate($name, Operation $operation, Context $context) if (!empty($outputStatements)) { $statements[] = new Stmt\If_( - new Expr\BinaryOp\Equal(new Expr\ConstFetch(new Name('self::FETCH_OBJECT')), new Expr\Variable('fetch')), [ + new Expr\BinaryOp\Equal(new Expr\ConstFetch(new Name('self::FETCH_OBJECT')), new Expr\Variable('fetch')), + [ 'stmts' => $outputStatements ] ); @@ -118,7 +121,8 @@ public function generate($name, Operation $operation, Context $context) // return $response $statements[] = new Stmt\Return_(new Expr\Variable('response')); - $documentation = array_merge([ + $documentation = array_merge( + [ '/**', sprintf(" * %s", $operation->getOperation()->getDescription()), ' *', diff --git a/src/Generator/OutputGeneratorTrait.php b/src/Generator/OutputGeneratorTrait.php index bb9e212..2b4bcd2 100644 --- a/src/Generator/OutputGeneratorTrait.php +++ b/src/Generator/OutputGeneratorTrait.php @@ -54,7 +54,8 @@ protected function createResponseDenormalizationStatement($status, $schema, Cont new Expr\BinaryOp\Equal( new Scalar\String_($status), new Expr\MethodCall(new Expr\Variable('response'), 'getStatusCode') - ), [ + ), + [ 'stmts' => [ new Stmt\Return_(new Expr\MethodCall( new Expr\PropertyFetch(new Expr\Variable('this'), 'serializer'), diff --git a/src/Generator/Parameter/FormDataParameterGenerator.php b/src/Generator/Parameter/FormDataParameterGenerator.php index 1a1578e..4cc1d4f 100644 --- a/src/Generator/Parameter/FormDataParameterGenerator.php +++ b/src/Generator/Parameter/FormDataParameterGenerator.php @@ -20,5 +20,4 @@ public function generateQueryParamStatements($parameter, Expr $queryParamVariabl return $statements; } - } diff --git a/src/JaneOpenApi.php b/src/JaneOpenApi.php index 9818890..4a085dd 100644 --- a/src/JaneOpenApi.php +++ b/src/JaneOpenApi.php @@ -90,8 +90,7 @@ public function __construct( ClientGenerator $clientGenerator, PrettyPrinterAbstract $prettyPrinter, ConfigInterface $fixerConfig = null - ) - { + ) { $this->schemaParser = $schemaParser; $this->clientGenerator = $clientGenerator; $this->prettyPrinter = $prettyPrinter; diff --git a/src/Naming/OperationUrlNaming.php b/src/Naming/OperationUrlNaming.php index 5fa2b29..bae4d52 100644 --- a/src/Naming/OperationUrlNaming.php +++ b/src/Naming/OperationUrlNaming.php @@ -38,11 +38,13 @@ public function generateFunctionName(Operation $operation) $part = $matches['part'][$index]; if (preg_match_all('/{(?P[^{}]+)}/', $part, $parameterMatches)) { - foreach($parameterMatches[0] as $parameterIndex => $parameterMatch) { + foreach ($parameterMatches[0] as $parameterIndex => $parameterMatch) { $withoutSnakes = preg_replace_callback( - '/(^|_|\.)+(.)/', function ($match) { - return ('.' === $match[1] ? '_' : '') . strtoupper($match[2]); - }, $parameterMatches['parameter'][ $parameterIndex ] + '/(^|_|\.)+(.)/', + function ($match) { + return ('.' === $match[1] ? '_' : '') . strtoupper($match[2]); + }, + $parameterMatches['parameter'][ $parameterIndex ] ); $methodNameParts[] = 'By' . ucfirst($withoutSnakes); diff --git a/src/SchemaParser/SchemaParser.php b/src/SchemaParser/SchemaParser.php index faebfee..3b28502 100644 --- a/src/SchemaParser/SchemaParser.php +++ b/src/SchemaParser/SchemaParser.php @@ -47,9 +47,10 @@ public function parseSchema($openApiSpec) try { $schema = $this->serializer->deserialize( - $openApiSpecContents, $schemaClass, self::CONTENT_TYPE_JSON + $openApiSpecContents, + $schemaClass, + self::CONTENT_TYPE_JSON ); - } catch (\Exception $exception) { $jsonException = $exception; } @@ -57,7 +58,9 @@ public function parseSchema($openApiSpec) if (!$schema) { try { $schema = $this->serializer->deserialize( - $openApiSpecContents, $schemaClass, self::CONTENT_TYPE_YAML + $openApiSpecContents, + $schemaClass, + self::CONTENT_TYPE_YAML ); } catch (\Exception $exception) { $yamlException = $exception;