From f39d878fe78832c9ed1d6eeb2fa169193d08f6b0 Mon Sep 17 00:00:00 2001 From: Mikael Pajunen Date: Mon, 27 Apr 2015 20:43:18 +0300 Subject: [PATCH] Change coding style to match PSR-2 - PHP CS Fixer run using level psr2 - Use PSR-4 for tests --- Examples/petstore.swagger.io/ApiResponse.php | 4 +- .../controllers/PetController.php | 38 +++++++-------- .../controllers/StoreController.php | 20 ++++---- .../controllers/UserController.php | 32 ++++++------- .../petstore.swagger.io/models/Category.php | 4 +- Examples/petstore.swagger.io/models/Order.php | 4 +- Examples/petstore.swagger.io/models/Pet.php | 3 +- Examples/petstore.swagger.io/models/Tag.php | 4 +- Examples/petstore.swagger.io/models/User.php | 4 +- Examples/petstore.swagger.io/security.php | 2 +- Examples/petstore.swagger.io/swagger-v2.php | 2 +- Examples/petstore.swagger.io/tags.php | 2 +- .../petstore-simple/SimplePet.php | 4 +- .../petstore-simple/SimplePetsController.php | 20 ++++---- Examples/swagger-spec/petstore-simple/api.php | 1 - .../controllers/PetWithDocsController.php | 24 +++++----- .../petstore-with-external-docs/docs.php | 5 +- .../models/ErrorModel.php | 3 +- .../models/Pet.php | 4 +- Examples/swagger-spec/petstore/Pet.php | 6 +-- .../swagger-spec/petstore/PetsController.php | 10 ++-- Examples/swagger-spec/petstore/api.php | 1 - composer.json | 5 ++ phpunit.xml.dist | 2 +- src/Annotations/AbstractAnnotation.php | 47 ++++++++++++------- src/Annotations/Contact.php | 4 +- src/Annotations/Definition.php | 4 +- src/Annotations/Delete.php | 4 +- src/Annotations/ExternalDocumentation.php | 4 +- src/Annotations/Get.php | 4 +- src/Annotations/Header.php | 4 +- src/Annotations/Info.php | 4 +- src/Annotations/Items.php | 7 +-- src/Annotations/License.php | 4 +- src/Annotations/Operation.php | 10 ++-- src/Annotations/Parameter.php | 10 ++-- src/Annotations/Patch.php | 4 +- src/Annotations/Path.php | 4 +- src/Annotations/Post.php | 4 +- src/Annotations/Property.php | 4 +- src/Annotations/Put.php | 4 +- src/Annotations/Response.php | 8 ++-- src/Annotations/Schema.php | 6 +-- src/Annotations/SecurityScheme.php | 8 ++-- src/Annotations/Swagger.php | 10 ++-- src/Annotations/Tag.php | 4 +- src/Annotations/Xml.php | 4 +- src/Context.php | 37 ++++++++++----- src/Logger.php | 16 ++++--- src/Parser.php | 37 +++++++++------ src/Processing.php | 18 ++++--- src/Processors/AugmentParameter.php | 7 +-- src/Processors/BuildPaths.php | 7 +-- src/Processors/ClassProperties.php | 12 +++-- src/Processors/InheritProperties.php | 21 +++++---- src/Processors/MergeSwagger.php | 7 +-- src/functions.php | 3 +- tests/AbstractAnnotationTest.php | 34 +++++++++----- tests/AugmentParameterTest.php | 7 +-- tests/BuildPathsTest.php | 10 ++-- tests/ClassPropertiesTest.php | 7 +-- tests/CommandlineInterfaceTest.php | 16 ++++--- tests/ContextTest.php | 12 +++-- tests/ExamplesTest.php | 10 ++-- tests/Fixtures/Child.php | 5 +- tests/Fixtures/Customer.php | 6 ++- tests/Fixtures/GrandParent.php | 15 +++--- tests/Fixtures/ThirdPartyAnnotations.php | 7 +-- tests/Fixtures/UsingRefs.php | 14 +++--- tests/Fixtures/routes.php | 2 +- tests/InheritPropertiesTest.php | 13 +++-- tests/ParserTest.php | 19 +++++--- tests/ProcessingTest.php | 7 +-- tests/ResponseTest.php | 10 ++-- tests/SwaggerTestCase.php | 34 +++++++++----- tests/ValidateRelationsTest.php | 13 +++-- tests/bootstrap.php | 3 -- 77 files changed, 442 insertions(+), 337 deletions(-) delete mode 100644 tests/bootstrap.php diff --git a/Examples/petstore.swagger.io/ApiResponse.php b/Examples/petstore.swagger.io/ApiResponse.php index d73c0c971..326a8c7d5 100644 --- a/Examples/petstore.swagger.io/ApiResponse.php +++ b/Examples/petstore.swagger.io/ApiResponse.php @@ -7,7 +7,8 @@ * @SWG\Xml(name="##default") * ) */ -class ApiResponse { +class ApiResponse +{ /** * @SWG\Property(format="int32") @@ -26,5 +27,4 @@ class ApiResponse { * @var string */ public $message; - } diff --git a/Examples/petstore.swagger.io/controllers/PetController.php b/Examples/petstore.swagger.io/controllers/PetController.php index 60040b915..92a03e0c2 100644 --- a/Examples/petstore.swagger.io/controllers/PetController.php +++ b/Examples/petstore.swagger.io/controllers/PetController.php @@ -2,7 +2,8 @@ namespace PetstoreIO; -class PetController { +class PetController +{ /** * @SWG\Get( @@ -41,8 +42,8 @@ class PetController { * } * ) */ - function findByTags() { - + public function findByTags() + { } /** @@ -82,8 +83,8 @@ function findByTags() { * } * ) */ - function findByStatus() { - + public function findByStatus() + { } /** @@ -126,8 +127,8 @@ function findByStatus() { * } * ) */ - function getPetById() { - + public function getPetById() + { } /** @@ -153,8 +154,8 @@ function getPetById() { * security={{"petstore_auth":{"write:pets", "read:pets"}}} * ) */ - function addPet() { - + public function addPet() + { } /** @@ -188,8 +189,8 @@ function addPet() { * security={{"petstore_auth":{"write:pets", "read:pets"}}} * ) */ - function updatePet() { - + public function updatePet() + { } /** @@ -223,8 +224,8 @@ function updatePet() { * security={{"petstore_auth":{"write:pets", "read:pets"}}} * ) */ - function deletePet() { - + public function deletePet() + { } /** @@ -263,8 +264,8 @@ function deletePet() { * }} * ) */ - function updatePetWithForm() { - + public function updatePetWithForm() + { } /** @@ -308,15 +309,14 @@ function updatePetWithForm() { * "write:pets" * } * } - * }, + * }, * summary="uploads an image", * tags={ * "pet" * } * ) * */ - function uploadFile() { - + public function uploadFile() + { } - } diff --git a/Examples/petstore.swagger.io/controllers/StoreController.php b/Examples/petstore.swagger.io/controllers/StoreController.php index eb99bfcbe..98c25e4d7 100644 --- a/Examples/petstore.swagger.io/controllers/StoreController.php +++ b/Examples/petstore.swagger.io/controllers/StoreController.php @@ -2,7 +2,8 @@ namespace PetstoreIO; -class StoreController { +class StoreController +{ /** * @SWG\Get(path="/store/inventory", @@ -28,8 +29,8 @@ class StoreController { * }} * ) */ - function getInventory() { - + public function getInventory() + { } /** @@ -54,8 +55,8 @@ function getInventory() { * @SWG\Response(response=400, description="Invalid Order") * ) */ - function placeOrder() { - + public function placeOrder() + { } /** @@ -83,8 +84,8 @@ function placeOrder() { * @SWG\Response(response=404, description="Order not found") * ) */ - function getOrderById() { - + public function getOrderById() + { } /** @@ -105,8 +106,7 @@ function getOrderById() { * @SWG\Response(response=404, description="Order not found") * ) */ - function deleteOrder() { - + public function deleteOrder() + { } - } diff --git a/Examples/petstore.swagger.io/controllers/UserController.php b/Examples/petstore.swagger.io/controllers/UserController.php index ad410f1cc..b270dcfdb 100644 --- a/Examples/petstore.swagger.io/controllers/UserController.php +++ b/Examples/petstore.swagger.io/controllers/UserController.php @@ -2,7 +2,8 @@ namespace PetstoreIO; -class UserController { +class UserController +{ /** * @SWG\Post(path="/user", @@ -21,8 +22,8 @@ class UserController { * @SWG\Response(response="default", description="successful operation") * ) */ - function createUser() { - + public function createUser() + { } /** @@ -45,8 +46,8 @@ function createUser() { * @SWG\Response(response="default", description="successful operation") * ) */ - function createUsersWithArrayInput() { - + public function createUsersWithArrayInput() + { } /** @@ -111,8 +112,8 @@ function createUsersWithArrayInput() { * @SWG\Response(response=400, description="Invalid username/password supplied") * ) */ - function loginUser() { - + public function loginUser() + { } /** @@ -126,8 +127,8 @@ function loginUser() { * @SWG\Response(response="default", description="successful operation") * ) */ - function logoutUser() { - + public function logoutUser() + { } /** @@ -149,8 +150,8 @@ function logoutUser() { * @SWG\Response(response=404, description="User not found") * ) */ - function getUserByName($username) { - + public function getUserByName($username) + { } /** @@ -178,8 +179,8 @@ function getUserByName($username) { * @SWG\Response(response=404, description="User not found") * ) */ - function updateUser() { - + public function updateUser() + { } /** @@ -200,8 +201,7 @@ function updateUser() { * @SWG\Response(response=404, description="User not found") * ) */ - function deleteUser() { - + public function deleteUser() + { } - } diff --git a/Examples/petstore.swagger.io/models/Category.php b/Examples/petstore.swagger.io/models/Category.php index 853114d41..cebee73ab 100644 --- a/Examples/petstore.swagger.io/models/Category.php +++ b/Examples/petstore.swagger.io/models/Category.php @@ -7,7 +7,8 @@ * @SWG\Xml(name="Category") * ) */ -class Category { +class Category +{ /** * @SWG\Property(format="int64") @@ -20,5 +21,4 @@ class Category { * @var string */ public $name; - } diff --git a/Examples/petstore.swagger.io/models/Order.php b/Examples/petstore.swagger.io/models/Order.php index d0fce288d..6c116a7ef 100644 --- a/Examples/petstore.swagger.io/models/Order.php +++ b/Examples/petstore.swagger.io/models/Order.php @@ -5,7 +5,8 @@ /** * @SWG\Definition(@SWG\Xml(name="Order")) */ -class Order { +class Order +{ /** * @SWG\Property(format="int64") @@ -43,5 +44,4 @@ class Order { * @SWG\Property(enum={"placed","approved","delivered"}) */ public $status; - } diff --git a/Examples/petstore.swagger.io/models/Pet.php b/Examples/petstore.swagger.io/models/Pet.php index 7b0f77f90..c0a60f716 100644 --- a/Examples/petstore.swagger.io/models/Pet.php +++ b/Examples/petstore.swagger.io/models/Pet.php @@ -5,7 +5,8 @@ /** * @SWG\Definition(required={"name", "photoUrls"}, @SWG\Xml(name="Pet")) */ -class Pet { +class Pet +{ /** * @SWG\Property(format="int64") diff --git a/Examples/petstore.swagger.io/models/Tag.php b/Examples/petstore.swagger.io/models/Tag.php index 26b5033e5..503a36ffa 100644 --- a/Examples/petstore.swagger.io/models/Tag.php +++ b/Examples/petstore.swagger.io/models/Tag.php @@ -7,7 +7,8 @@ * @SWG\Xml(name="Tag") * ) */ -class Tag { +class Tag +{ /** * @SWG\Property(format="int64") @@ -20,5 +21,4 @@ class Tag { * @var string */ public $name; - } diff --git a/Examples/petstore.swagger.io/models/User.php b/Examples/petstore.swagger.io/models/User.php index 5ff921e35..579f2b407 100644 --- a/Examples/petstore.swagger.io/models/User.php +++ b/Examples/petstore.swagger.io/models/User.php @@ -5,7 +5,8 @@ /** * @SWG\Definition(@SWG\Xml(name="User")) */ -class User { +class User +{ /** * @SWG\Property(format="int64") @@ -55,5 +56,4 @@ class User { * @SWG\Property(format="int32") */ public $userStatus; - } diff --git a/Examples/petstore.swagger.io/security.php b/Examples/petstore.swagger.io/security.php index a7979a334..b5239bff1 100644 --- a/Examples/petstore.swagger.io/security.php +++ b/Examples/petstore.swagger.io/security.php @@ -19,4 +19,4 @@ * "write:pets": "modify pets in your account" * } * ) - */ \ No newline at end of file + */ diff --git a/Examples/petstore.swagger.io/swagger-v2.php b/Examples/petstore.swagger.io/swagger-v2.php index 89720853f..fe3ab5c9d 100644 --- a/Examples/petstore.swagger.io/swagger-v2.php +++ b/Examples/petstore.swagger.io/swagger-v2.php @@ -23,4 +23,4 @@ * url="http://swagger.io" * ) * ) - */ \ No newline at end of file + */ diff --git a/Examples/petstore.swagger.io/tags.php b/Examples/petstore.swagger.io/tags.php index f8e488365..f7d11136c 100644 --- a/Examples/petstore.swagger.io/tags.php +++ b/Examples/petstore.swagger.io/tags.php @@ -21,4 +21,4 @@ * url="http://swagger.io" * ) * ) - */ \ No newline at end of file + */ diff --git a/Examples/swagger-spec/petstore-simple/SimplePet.php b/Examples/swagger-spec/petstore-simple/SimplePet.php index 716767d2f..95828dd46 100644 --- a/Examples/swagger-spec/petstore-simple/SimplePet.php +++ b/Examples/swagger-spec/petstore-simple/SimplePet.php @@ -5,7 +5,8 @@ /** * @SWG\Definition(definition="pet", required={"id", "name"}) */ -class SimplePet { +class SimplePet +{ /** * @SWG\Property(format="int64") @@ -24,5 +25,4 @@ class SimplePet { * @SWG\Property() */ public $tag; - } diff --git a/Examples/swagger-spec/petstore-simple/SimplePetsController.php b/Examples/swagger-spec/petstore-simple/SimplePetsController.php index 90d0c6354..5e03a55af 100644 --- a/Examples/swagger-spec/petstore-simple/SimplePetsController.php +++ b/Examples/swagger-spec/petstore-simple/SimplePetsController.php @@ -2,7 +2,8 @@ namespace Petstore; -class SimplePetsController { +class SimplePetsController +{ /** * @SWG\Get( @@ -44,8 +45,8 @@ class SimplePetsController { * ) * ) */ - function findPets() { - + public function findPets() + { } /** @@ -79,8 +80,8 @@ function findPets() { * ) * ) */ - function findPetById() { - + public function findPetById() + { } /** @@ -122,8 +123,8 @@ function findPetById() { * } * ) */ - function addPet() { - + public function addPet() + { } /** @@ -150,8 +151,7 @@ function addPet() { * ) * ) */ - function deletePet() { - + public function deletePet() + { } - } diff --git a/Examples/swagger-spec/petstore-simple/api.php b/Examples/swagger-spec/petstore-simple/api.php index 74523a8c8..03a22b8f8 100644 --- a/Examples/swagger-spec/petstore-simple/api.php +++ b/Examples/swagger-spec/petstore-simple/api.php @@ -30,4 +30,3 @@ * ) * ) */ - diff --git a/Examples/swagger-spec/petstore-with-external-docs/controllers/PetWithDocsController.php b/Examples/swagger-spec/petstore-with-external-docs/controllers/PetWithDocsController.php index 3c2cad65b..0aca7d2a2 100644 --- a/Examples/swagger-spec/petstore-with-external-docs/controllers/PetWithDocsController.php +++ b/Examples/swagger-spec/petstore-with-external-docs/controllers/PetWithDocsController.php @@ -1,9 +1,10 @@ _context = $properties['_context']; unset($properties['_context']); - } else if (Parser::$context) { + } elseif (Parser::$context) { $this->_context = Parser::$context; } else { $this->_context = Context::detect(1); @@ -115,12 +117,14 @@ public function __construct($properties) { } } - public function __get($property) { + public function __get($property) + { $properties = get_object_vars($this); Logger::notice('Property "' . $property . '" doesn\'t exist in a ' . $this->identity() . ', exising properties: "' . implode('", "', array_keys($properties)) . '" in ' . $this->_context); } - public function __set($property, $value) { + public function __set($property, $value) + { $fields = get_object_vars($this); foreach (static::$_blacklist as $_property) { unset($fields[$_property]); @@ -135,7 +139,8 @@ public function __set($property, $value) { * * @param AbstractAnnotation[] $annotations */ - public function merge(Array $annotations) { + public function merge(Array $annotations) + { foreach ($annotations as $annotation) { $found = false; foreach (static::$_nested as $class => $property) { @@ -166,7 +171,8 @@ public function merge(Array $annotations) { * * @param object $object */ - public function mergeProperties($object) { + public function mergeProperties($object) + { $defaultValues = get_class_vars(get_class($this)); $currentValues = get_object_vars($this); foreach ($object as $property => $value) { @@ -196,11 +202,13 @@ public function mergeProperties($object) { } } - public function __toString() { + public function __toString() + { return json_encode($this, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); } - public function __debugInfo() { + public function __debugInfo() + { $properties = []; foreach (get_object_vars($this) as $property => $value) { if ($value !== UNDEFINED) { @@ -214,7 +222,8 @@ public function __debugInfo() { * Customize the way json_encode() renders the annotations. * @return array */ - public function jsonSerialize() { + public function jsonSerialize() + { $data = new stdClass(); // Strip undefined and null values. $classVars = get_class_vars(get_class($this)); @@ -274,7 +283,8 @@ public function jsonSerialize() { * @return boolean * @throws Exception */ - public function validate($skip = []) { + public function validate($skip = []) + { if (in_array($this, $skip, true)) { return true; } @@ -375,7 +385,8 @@ public function validate($skip = []) { * @param array [$skip] Array with objects which are already validated * @return boolean */ - private static function _validate($fields, $skip) { + private static function _validate($fields, $skip) + { $valid = true; if (is_object($fields)) { if (in_array($fields, $skip, true)) { @@ -407,7 +418,8 @@ private static function _validate($fields, $skip) { * Example: "@SWG\Get(path="/pets")" * @return string */ - public function identity() { + public function identity() + { return $this->_identity([]); } @@ -416,7 +428,8 @@ public function identity() { * @param array $properties * @return string */ - protected function _identity($properties) { + protected function _identity($properties) + { $fields = []; foreach ($properties as $property) { $value = $this->$property; @@ -427,8 +440,9 @@ protected function _identity($properties) { return '@' . str_replace('Swagger\\Annotations\\', 'SWG\\', get_class($this)) . '(' . implode(',', $fields) . ')'; } - private function validateType($type, $value) { - if (substr($type, 0, 1) === '[' && substr($type, -1) === ']') { // Array of a specified type? + private function validateType($type, $value) + { + if (substr($type, 0, 1) === '[' && substr($type, -1) === ']') { // Array of a specified type? if ($this->validateType('array', $value) === false) { return false; } @@ -474,5 +488,4 @@ private function validateType($type, $value) { throw new Exception('Invalid type "' . $type . '"'); } } - } diff --git a/src/Annotations/Contact.php b/src/Annotations/Contact.php index 811f1cf7b..cfde80489 100644 --- a/src/Annotations/Contact.php +++ b/src/Annotations/Contact.php @@ -12,7 +12,8 @@ * * A Swagger "Contact Object": https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#contactObject */ -class Contact extends AbstractAnnotation { +class Contact extends AbstractAnnotation +{ /** * The identifying name of the contact person/organization. @@ -43,5 +44,4 @@ class Contact extends AbstractAnnotation { public static $_parents = [ 'Swagger\Annotations\Info' ]; - } diff --git a/src/Annotations/Definition.php b/src/Annotations/Definition.php index 1ea32f4d2..577dbd899 100644 --- a/src/Annotations/Definition.php +++ b/src/Annotations/Definition.php @@ -9,7 +9,8 @@ /** * @Annotation */ -class Definition extends Schema { +class Definition extends Schema +{ /** * The key into Swagger->definitions array. @@ -29,5 +30,4 @@ class Definition extends Schema { 'Swagger\Annotations\Definition', 'Swagger\Annotations\Property', ]; - } diff --git a/src/Annotations/Delete.php b/src/Annotations/Delete.php index 6e552953c..fdca6fd1d 100644 --- a/src/Annotations/Delete.php +++ b/src/Annotations/Delete.php @@ -9,7 +9,8 @@ /** * @Annotation */ -class Delete extends Operation { +class Delete extends Operation +{ /** @inheritdoc */ public $method = 'delete'; @@ -18,5 +19,4 @@ class Delete extends Operation { public static $_parents = [ 'Swagger\Annotations\Path' ]; - } diff --git a/src/Annotations/ExternalDocumentation.php b/src/Annotations/ExternalDocumentation.php index 577c299e6..b369aa591 100644 --- a/src/Annotations/ExternalDocumentation.php +++ b/src/Annotations/ExternalDocumentation.php @@ -12,7 +12,8 @@ * * A Swagger "External Documentation Object": * https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#external-documentation-object */ -class ExternalDocumentation extends AbstractAnnotation { +class ExternalDocumentation extends AbstractAnnotation +{ /** * A short description of the target documentation. GFM syntax can be used for rich text representation. @@ -49,5 +50,4 @@ class ExternalDocumentation extends AbstractAnnotation { 'Swagger\Annotations\Delete', 'Swagger\Annotations\Patch', ]; - } diff --git a/src/Annotations/Get.php b/src/Annotations/Get.php index 6b1ebc00e..258bb5fa9 100644 --- a/src/Annotations/Get.php +++ b/src/Annotations/Get.php @@ -9,7 +9,8 @@ /** * @Annotation */ -class Get extends Operation { +class Get extends Operation +{ /** @inheritdoc */ public $method = 'get'; @@ -18,5 +19,4 @@ class Get extends Operation { public static $_parents = [ 'Swagger\Annotations\Path' ]; - } diff --git a/src/Annotations/Header.php b/src/Annotations/Header.php index 8c30dc0e4..4442dac22 100644 --- a/src/Annotations/Header.php +++ b/src/Annotations/Header.php @@ -11,7 +11,8 @@ * * A Swagger "Header Object" https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#headerObject */ -class Header extends AbstractAnnotation { +class Header extends AbstractAnnotation +{ /** * @var string @@ -150,5 +151,4 @@ class Header extends AbstractAnnotation { public static $_parents = [ 'Swagger\Annotations\Response' ]; - } diff --git a/src/Annotations/Info.php b/src/Annotations/Info.php index bec4d9086..753f2357e 100644 --- a/src/Annotations/Info.php +++ b/src/Annotations/Info.php @@ -11,7 +11,8 @@ * * A Swagger "Info Object": https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#infoObject */ -class Info extends AbstractAnnotation { +class Info extends AbstractAnnotation +{ /** * The title of the application. @@ -69,5 +70,4 @@ class Info extends AbstractAnnotation { public static $_parents = [ 'Swagger\Annotations\Swagger' ]; - } diff --git a/src/Annotations/Items.php b/src/Annotations/Items.php index a2666bf39..1c693d499 100644 --- a/src/Annotations/Items.php +++ b/src/Annotations/Items.php @@ -14,7 +14,8 @@ * * A Swagger "Items Object": https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#itemsObject */ -class Items extends AbstractAnnotation { +class Items extends AbstractAnnotation +{ /** * $ref See http://json-schema.org/latest/json-schema-core.html#rfc.section.7 @@ -158,7 +159,8 @@ class Items extends AbstractAnnotation { 'Swagger\Annotations\Items' ]; - public function validate($skip = []) { + public function validate($skip = []) + { if (in_array($this, $skip, true)) { return true; } @@ -169,5 +171,4 @@ public function validate($skip = []) { } return $valid; } - } diff --git a/src/Annotations/License.php b/src/Annotations/License.php index bf799071f..5880dd4c4 100644 --- a/src/Annotations/License.php +++ b/src/Annotations/License.php @@ -12,7 +12,8 @@ * * A Swagger "License Object": https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#licenseObject */ -class License extends AbstractAnnotation { +class License extends AbstractAnnotation +{ /** * The license name used for the API. @@ -39,5 +40,4 @@ class License extends AbstractAnnotation { public static $_parents = [ 'Swagger\Annotations\Info' ]; - } diff --git a/src/Annotations/Operation.php b/src/Annotations/Operation.php index 13b5aeb73..41c88c68e 100644 --- a/src/Annotations/Operation.php +++ b/src/Annotations/Operation.php @@ -14,7 +14,8 @@ * * A Swagger "Operation Object": https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#operationObject */ -abstract class Operation extends AbstractAnnotation { +abstract class Operation extends AbstractAnnotation +{ /** * key in the Swagger "Paths Object" for this operation @@ -142,14 +143,16 @@ abstract class Operation extends AbstractAnnotation { ]; /** @inheritdoc */ - public function jsonSerialize() { + public function jsonSerialize() + { $data = parent::jsonSerialize(); unset($data->method); unset($data->path); return $data; } - public function validate($skip = array()) { + public function validate($skip = array()) + { if (in_array($this, $skip, true)) { return true; } @@ -163,5 +166,4 @@ public function validate($skip = array()) { } return $valid; } - } diff --git a/src/Annotations/Parameter.php b/src/Annotations/Parameter.php index f90a143ef..e8ae97c41 100644 --- a/src/Annotations/Parameter.php +++ b/src/Annotations/Parameter.php @@ -14,7 +14,8 @@ * * A Swagger "Parameter Object": https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#parameterObject */ -class Parameter extends AbstractAnnotation { +class Parameter extends AbstractAnnotation +{ /** * $ref See http://json-schema.org/latest/json-schema-core.html#rfc.section.7 @@ -201,7 +202,8 @@ class Parameter extends AbstractAnnotation { 'Swagger\Annotations\Swagger' ]; - public function validate($skip = []) { + public function validate($skip = []) + { if (in_array($this, $skip, true)) { return true; } @@ -230,8 +232,8 @@ public function validate($skip = []) { } /** @inheritdoc */ - public function identity() { + public function identity() + { return parent::_identity(['name', 'in']); } - } diff --git a/src/Annotations/Patch.php b/src/Annotations/Patch.php index 2c1208983..302b5c63a 100644 --- a/src/Annotations/Patch.php +++ b/src/Annotations/Patch.php @@ -9,7 +9,8 @@ /** * @Annotation */ -class Patch extends Operation { +class Patch extends Operation +{ /** @inheritdoc */ public $method = 'patch'; @@ -18,5 +19,4 @@ class Patch extends Operation { public static $_parents = [ 'Swagger\Annotations\Path' ]; - } diff --git a/src/Annotations/Path.php b/src/Annotations/Path.php index 001cbf668..df7269b46 100644 --- a/src/Annotations/Path.php +++ b/src/Annotations/Path.php @@ -14,7 +14,8 @@ * * A Swagger "Path Item Object": https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#path-item-object- */ -class Path extends AbstractAnnotation { +class Path extends AbstractAnnotation +{ /** * key in the Swagger "Paths Object" for this path. @@ -89,5 +90,4 @@ class Path extends AbstractAnnotation { public static $_parents = [ 'Swagger\Annotations\Swagger' ]; - } diff --git a/src/Annotations/Post.php b/src/Annotations/Post.php index dbb6016da..d84f0fbef 100644 --- a/src/Annotations/Post.php +++ b/src/Annotations/Post.php @@ -9,7 +9,8 @@ /** * @Annotation */ -class Post extends Operation { +class Post extends Operation +{ /** @inheritdoc */ public $method = 'post'; @@ -18,5 +19,4 @@ class Post extends Operation { public static $_parents = [ 'Swagger\Annotations\Path' ]; - } diff --git a/src/Annotations/Property.php b/src/Annotations/Property.php index ef4bd11f4..a2c522607 100644 --- a/src/Annotations/Property.php +++ b/src/Annotations/Property.php @@ -9,7 +9,8 @@ /** * @Annotation */ -class Property extends Schema { +class Property extends Schema +{ /** * The key into Schema->properties array. @@ -23,5 +24,4 @@ class Property extends Schema { 'Swagger\Annotations\Schema', 'Swagger\Annotations\Property', ]; - } diff --git a/src/Annotations/Put.php b/src/Annotations/Put.php index dd9328aca..e1e02b821 100644 --- a/src/Annotations/Put.php +++ b/src/Annotations/Put.php @@ -9,7 +9,8 @@ /** * @Annotation */ -class Put extends Operation { +class Put extends Operation +{ /** @inheritdoc */ public $method = 'put'; @@ -18,5 +19,4 @@ class Put extends Operation { public static $_parents = [ 'Swagger\Annotations\Path' ]; - } diff --git a/src/Annotations/Response.php b/src/Annotations/Response.php index 3663f2907..a565498c5 100644 --- a/src/Annotations/Response.php +++ b/src/Annotations/Response.php @@ -11,7 +11,8 @@ * * A Swagger "Response Object": https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#responseObject */ -class Response extends AbstractAnnotation { +class Response extends AbstractAnnotation +{ /** * $ref See http://json-schema.org/latest/json-schema-core.html#rfc.section.7 @@ -21,8 +22,8 @@ class Response extends AbstractAnnotation { /** * The key into Operations->responses array. - * - * @var string a HTTP Status Code or "default" + * + * @var string a HTTP Status Code or "default" */ public $response; @@ -74,5 +75,4 @@ class Response extends AbstractAnnotation { 'Swagger\Annotations\Delete', 'Swagger\Annotations\Swagger' ]; - } diff --git a/src/Annotations/Schema.php b/src/Annotations/Schema.php index 64ff36b4f..6c35d0b5f 100644 --- a/src/Annotations/Schema.php +++ b/src/Annotations/Schema.php @@ -18,7 +18,8 @@ * A Swagger "Schema Object": https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#schemaObject * JSON Schema: http://json-schema.org/latest/json-schema-validation.html */ -class Schema extends AbstractAnnotation { +class Schema extends AbstractAnnotation +{ /** * $ref See http://json-schema.org/latest/json-schema-core.html#rfc.section.7 @@ -212,7 +213,7 @@ class Schema extends AbstractAnnotation { /** * An instance validates successfully against this property if it validates successfully against exactly one schema defined by this property's value. - * @var type + * @var type */ public $oneOf; @@ -272,5 +273,4 @@ class Schema extends AbstractAnnotation { 'Swagger\Annotations\Response', 'Swagger\Annotations\Parameter', ]; - } diff --git a/src/Annotations/SecurityScheme.php b/src/Annotations/SecurityScheme.php index de2275d0a..9987ba309 100644 --- a/src/Annotations/SecurityScheme.php +++ b/src/Annotations/SecurityScheme.php @@ -10,7 +10,8 @@ * @Annotation * A Swagger "Security Scheme Object": https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#securitySchemeObject */ -class SecurityScheme extends AbstractAnnotation { +class SecurityScheme extends AbstractAnnotation +{ /** * The key into Swagger->securityDefinitions array. @@ -43,8 +44,8 @@ class SecurityScheme extends AbstractAnnotation { public $in; /** - * The flow used by the OAuth2 security scheme. - * @var + * The flow used by the OAuth2 security scheme. + * @var */ public $flow; @@ -82,5 +83,4 @@ class SecurityScheme extends AbstractAnnotation { public static $_parents = [ 'Swagger\Annotations\Swagger', ]; - } diff --git a/src/Annotations/Swagger.php b/src/Annotations/Swagger.php index 36bec533b..a39272efa 100644 --- a/src/Annotations/Swagger.php +++ b/src/Annotations/Swagger.php @@ -16,7 +16,8 @@ * * A Swagger "Swagger Object": https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#swagger-object- */ -class Swagger extends AbstractAnnotation { +class Swagger extends AbstractAnnotation +{ /** * Specifies the Swagger Specification version being used. It can be used by the Swagger UI and other clients to interpret the API listing. @@ -139,7 +140,8 @@ class Swagger extends AbstractAnnotation { * @param string|array $exclude * @throws Exception */ - public function crawl($directory, $exclude = null) { + public function crawl($directory, $exclude = null) + { // Setup Finder if (is_object($directory)) { $finder = $directory; @@ -179,10 +181,10 @@ public function crawl($directory, $exclude = null) { * @param string $filename * @throws Exception */ - public function saveAs($filename) { + public function saveAs($filename) + { if (file_put_contents($filename, $this) === false) { throw new Exception('Failed to saveAs("' . $filename . '")'); } } - } diff --git a/src/Annotations/Tag.php b/src/Annotations/Tag.php index d7f2043e3..adc62d7d9 100644 --- a/src/Annotations/Tag.php +++ b/src/Annotations/Tag.php @@ -11,7 +11,8 @@ * * A Swagger "Tag Object": https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#tagObject */ -class Tag extends AbstractAnnotation { +class Tag extends AbstractAnnotation +{ /** * The name of the tag. @@ -49,5 +50,4 @@ class Tag extends AbstractAnnotation { public static $_nested = [ 'Swagger\Annotations\ExternalDocumentation' => 'externalDocs' ]; - } diff --git a/src/Annotations/Xml.php b/src/Annotations/Xml.php index 57438bc85..35c61fa04 100644 --- a/src/Annotations/Xml.php +++ b/src/Annotations/Xml.php @@ -11,7 +11,8 @@ * * A Swagger "XML Object": https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#xmlObject */ -class Xml extends AbstractAnnotation { +class Xml extends AbstractAnnotation +{ /** * Replaces the name of the element/attribute used for the described schema property. When defined within the Items Object (items), it will affect the name of the individual XML elements within the list. When defined alongside type being array (outside the items), it will affect the wrapping element and only if wrapped is true. If wrapped is false, it will be ignored. @@ -58,5 +59,4 @@ class Xml extends AbstractAnnotation { 'Swagger\Annotations\Property', 'Swagger\Annotations\Definition' ]; - } diff --git a/src/Context.php b/src/Context.php index 062c781a4..19a9084e3 100644 --- a/src/Context.php +++ b/src/Context.php @@ -33,7 +33,8 @@ * @property string $property * @property Annotations\AbstractAnnotation[] $annotations */ -class Context { +class Context +{ /** * Prototypical inheritance for properties. @@ -45,7 +46,8 @@ class Context { * @param array $properties new properties for this context. * @param Context $parent The parent context */ - public function __construct($properties = [], $parent = null) { + public function __construct($properties = [], $parent = null) + { foreach ($properties as $property => $value) { $this->$property = $value; } @@ -58,7 +60,8 @@ public function __construct($properties = [], $parent = null) { * @param string $type Example: $c->is('method') or $c->is('class') * @return bool */ - public function is($type) { + public function is($type) + { return property_exists($this, $type); } @@ -68,7 +71,8 @@ public function is($type) { * @param string $property * @return boolean|\Swagger\Context */ - public function with($property) { + public function with($property) + { if (property_exists($this, $property)) { return $this; } @@ -81,7 +85,8 @@ public function with($property) { /** * @return \Swagger\Context */ - public function getRootContext() { + public function getRootContext() + { if ($this->_parent) { return $this->_parent->getRootContext(); } @@ -93,7 +98,8 @@ public function getRootContext() { * * @return string Example: "file1.php on line 12" */ - public function getDebugLocation() { + public function getDebugLocation() + { $location = ''; if ($this->class && ($this->method || $this->property)) { $location .= $this->fullyQualifiedName($this->class); @@ -127,25 +133,29 @@ public function getDebugLocation() { * @param string $property * @return mixed */ - public function __get($property) { + public function __get($property) + { if ($this->_parent) { return $this->_parent->$property; } return null; } - public function __toString() { + public function __toString() + { return $this->getDebugLocation(); } - public function __debugInfo() { + public function __debugInfo() + { return ['-' => $this->getDebugLocation()]; } /** * @return string|null */ - public function extractDescription() { + public function extractDescription() + { $lines = explode("\n", $this->comment); unset($lines[0]); $description = ''; @@ -171,7 +181,8 @@ public function extractDescription() { * @param int $index * @return \Swagger\Context */ - static public function detect($index = 0) { + public static function detect($index = 0) + { $context = new Context(); $backtrace = debug_backtrace(); $position = $backtrace[$index]; @@ -205,7 +216,8 @@ static public function detect($index = 0) { * @param string $class The class name * @return string */ - public function fullyQualifiedName($class) { + public function fullyQualifiedName($class) + { if ($this->namespace) { $namespace = str_replace('\\\\', '\\', '\\' . $this->namespace . '\\'); } else { @@ -240,5 +252,4 @@ public function fullyQualifiedName($class) { } return $namespace . $class; } - } diff --git a/src/Logger.php b/src/Logger.php index bb5f7a72f..1aaf000c0 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -12,7 +12,8 @@ /** * Logger reports the parser and validation messages. */ -class Logger { +class Logger +{ /** * Singleton @@ -25,7 +26,8 @@ class Logger { */ public $log; - protected function __construct() { + protected function __construct() + { /** * @param \Exception|string $entry * @param int $type Error type @@ -41,7 +43,8 @@ protected function __construct() { /** * @return Logger */ - public static function getInstance() { + public static function getInstance() + { if (self::$instance === null) { self::$instance = new Logger(); } @@ -52,7 +55,8 @@ public static function getInstance() { * Log a Swagger warning. * @param Exception|string $entry */ - public static function warning($entry) { + public static function warning($entry) + { call_user_func(self::getInstance()->log, $entry, E_USER_WARNING); } @@ -60,8 +64,8 @@ public static function warning($entry) { * Log a Swagger notice. * @param Exception|string $entry */ - public static function notice($entry) { + public static function notice($entry) + { call_user_func(self::getInstance()->log, $entry, E_USER_NOTICE); } - } diff --git a/src/Parser.php b/src/Parser.php index 368881c6e..866261068 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -30,7 +30,8 @@ /** * Swagger\Parser extracts swagger-php annotations from php code. */ -class Parser { +class Parser +{ /** * List of namespaces that should be detected by the doctrine annotation parser. @@ -52,7 +53,8 @@ class Parser { /** * @param string $filename */ - public function __construct($filename = null) { + public function __construct($filename = null) + { if ($filename !== null) { $this->parseFile($filename); } @@ -64,7 +66,8 @@ public function __construct($filename = null) { * @param string $filename Path to a php file. * @return AbstractAnnotation[] */ - public function parseFile($filename) { + public function parseFile($filename) + { $tokens = token_get_all(file_get_contents($filename)); return $this->parseTokens($tokens, new Context(['filename' => $filename])); } @@ -76,7 +79,8 @@ public function parseFile($filename) { * @param Context $context The original location of the contents. * @return AbstractAnnotation[] */ - public function parseContents($contents, $context) { + public function parseContents($contents, $context) + { $tokens = token_get_all($contents); return $this->parseTokens($tokens, $context); } @@ -88,7 +92,8 @@ public function parseContents($contents, $context) { * @param Context $parseContext * @return AbstractAnnotation[] */ - protected function parseTokens($tokens, $parseContext) { + protected function parseTokens($tokens, $parseContext) + { $this->docParser = new DocParser(); $this->docParser->setIgnoreNotImportedAnnotations(true); @@ -232,13 +237,13 @@ protected function parseTokens($tokens, $parseContext) { * @param Context $context * @return string|array The next token (or false) */ - private function nextToken(&$tokens, $context) { + private function nextToken(&$tokens, $context) + { $token = next($tokens); if ($token[0] === T_WHITESPACE) { return $this->nextToken($tokens, $context); } if ($token[0] === T_COMMENT) { - $pos = strpos($token[1], '@SWG\\'); if ($pos) { $line = $context->line ? $context->line + $token[2] : $token[2]; @@ -250,7 +255,8 @@ private function nextToken(&$tokens, $context) { return $token; } - private function parseNamespace(&$tokens, &$token, $parseContext) { + private function parseNamespace(&$tokens, &$token, $parseContext) + { $namespace = ''; while ($token !== false) { $token = $this->nextToken($tokens, $parseContext); @@ -262,7 +268,8 @@ private function parseNamespace(&$tokens, &$token, $parseContext) { return $namespace; } - private function parseUseStatement(&$tokens, &$token, $parseContext) { + private function parseUseStatement(&$tokens, &$token, $parseContext) + { $class = ''; $alias = ''; $statements = []; @@ -273,17 +280,17 @@ private function parseUseStatement(&$tokens, &$token, $parseContext) { if (!$explicitAlias && $isNameToken) { $class .= $token[1]; $alias = $token[1]; - } else if ($explicitAlias && $isNameToken) { + } elseif ($explicitAlias && $isNameToken) { $alias .= $token[1]; - } else if ($token[0] === T_AS) { + } elseif ($token[0] === T_AS) { $explicitAlias = true; $alias = ''; - } else if ($token === ',') { + } elseif ($token === ',') { $statements[$alias] = $class; $class = ''; $alias = ''; $explicitAlias = false; - } else if ($token === ';') { + } elseif ($token === ';') { $statements[$alias] = $class; break; } else { @@ -300,7 +307,8 @@ private function parseUseStatement(&$tokens, &$token, $parseContext) { * @param AbstractAnnotation[] $annotations * @return AbstractAnnotation[] */ - protected function parseContext($context, &$annotations) { + protected function parseContext($context, &$annotations) + { try { self::$context = $context; if ($context->is('annotations') === false) { @@ -333,5 +341,4 @@ protected function parseContext($context, &$annotations) { } return $annotations; } - } diff --git a/src/Processing.php b/src/Processing.php index 24f5f44ed..c254fee12 100644 --- a/src/Processing.php +++ b/src/Processing.php @@ -18,13 +18,15 @@ /** * Registry for the post-processing operations. */ -class Processing { +class Processing +{ /** - * Apply all processors + * Apply all processors * @param Swagger $swagger */ - static function process($swagger) { + public static function process($swagger) + { foreach (self::processors() as $processor) { $processor($swagger); } @@ -39,7 +41,8 @@ static function process($swagger) { * Get direct access to the processors array. * @return array reference */ - static function &processors() { + public static function &processors() + { if (!self::$processors) { // Add default processors. self::$processors = [ @@ -57,7 +60,8 @@ static function &processors() { * Register a processor * @param Closure $processor */ - static function register($processor) { + public static function register($processor) + { array_push(self::processors(), $processor); } @@ -65,7 +69,8 @@ static function register($processor) { * Unregister a processor * @param Closure $processor */ - static function unregister($processor) { + public static function unregister($processor) + { $processors = &self::processors(); $key = array_search($processor, $processors, true); if ($key === false) { @@ -73,5 +78,4 @@ static function unregister($processor) { } unset($processors[$key]); } - } diff --git a/src/Processors/AugmentParameter.php b/src/Processors/AugmentParameter.php index 07695db62..29eaf6497 100644 --- a/src/Processors/AugmentParameter.php +++ b/src/Processors/AugmentParameter.php @@ -11,9 +11,11 @@ /** * Use the parameter->name as keyfield (parameter->parameter) when used in swagger object. */ -class AugmentParameter { +class AugmentParameter +{ - public function __invoke(Swagger $swagger) { + public function __invoke(Swagger $swagger) + { if ($swagger->parameters) { $keys = []; $parametersWithoutKey = []; @@ -32,5 +34,4 @@ public function __invoke(Swagger $swagger) { } } } - } diff --git a/src/Processors/BuildPaths.php b/src/Processors/BuildPaths.php index 467dc33d5..10dafc959 100644 --- a/src/Processors/BuildPaths.php +++ b/src/Processors/BuildPaths.php @@ -15,9 +15,11 @@ /** * Build the swagger->paths using the detected @SWG\Path and @SWG\Operations (like @SWG\Get, @SWG\Post, etc) */ -class BuildPaths { +class BuildPaths +{ - public function __invoke(Swagger $swagger) { + public function __invoke(Swagger $swagger) + { $paths = []; // Merge @SWG\Paths with the same path. foreach ($swagger->paths as $annotation) { @@ -45,5 +47,4 @@ public function __invoke(Swagger $swagger) { } $swagger->paths = array_values($paths); } - } diff --git a/src/Processors/ClassProperties.php b/src/Processors/ClassProperties.php index 47fb1fb9d..5780f443d 100644 --- a/src/Processors/ClassProperties.php +++ b/src/Processors/ClassProperties.php @@ -15,9 +15,10 @@ /** * Use the property context to extract useful information and inject that into the annotation. */ -class ClassProperties { +class ClassProperties +{ - static $types = [ + public static $types = [ 'array' => 'array', 'byte' => ['string', 'byte'], 'boolean' => 'boolean', @@ -35,7 +36,8 @@ class ClassProperties { 'object' => 'object' ]; - public function __invoke(Swagger $swagger) { + public function __invoke(Swagger $swagger) + { $refs = []; // Use the class names for @SWG\Definition() foreach ($swagger->definitions as $definition) { @@ -85,7 +87,8 @@ public function __invoke(Swagger $swagger) { * @param Property $annotation * @param array $refs */ - public function processProperty($annotation, $refs) { + public function processProperty($annotation, $refs) + { $context = $annotation->_context; // Use the property names for @SWG\Property() if ($annotation->property === null) { @@ -130,5 +133,4 @@ public function processProperty($annotation, $refs) { $annotation->description = $context->extractDescription(); } } - } diff --git a/src/Processors/InheritProperties.php b/src/Processors/InheritProperties.php index 3d85c81b1..a1a9477f2 100644 --- a/src/Processors/InheritProperties.php +++ b/src/Processors/InheritProperties.php @@ -13,9 +13,11 @@ /** * Copy the annotated properties from parent classes; */ -class InheritProperties { +class InheritProperties +{ - public function __invoke(Swagger $swagger) { + public function __invoke(Swagger $swagger) + { $children = $this->getChildren($swagger); $definitions = $this->getDefinitions($swagger); @@ -51,7 +53,8 @@ public function __invoke(Swagger $swagger) { * @param Swagger $swagger * @return array '\Namespace\ClassName' => SWG\Definition */ - public function getDefinitions($swagger) { + public function getDefinitions($swagger) + { $definitions = []; foreach ($swagger->definitions as $definition) { if ($definition->_context->is('class')) { @@ -65,7 +68,8 @@ public function getDefinitions($swagger) { * @param Swagger $swagger * @return array '\namespace\ParentClass' => ['\namespace\Child', 'Child2'] */ - public function getChildren($swagger) { + public function getChildren($swagger) + { $extends = []; // '\namespace\class' => '\namespace\parent' foreach ($swagger->definitions as $definition) { $context = $definition->_context; @@ -95,7 +99,8 @@ public function getChildren($swagger) { * @param array $extends '\namespace\class' => '\namespace\parent' * @return array */ - private function getChildrenFor($class, $extends) { + private function getChildrenFor($class, $extends) + { $children = []; foreach ($extends as $child => $parent) { if ($parent === $class) { // A direct descendant? @@ -107,11 +112,12 @@ private function getChildrenFor($class, $extends) { } /** - * + * * @param Definition $definition * @param Property[] $properties */ - private function mergeProperties($definition, $properties) { + private function mergeProperties($definition, $properties) + { if ($definition->properties === null) { $definition->properties = $properties; return; @@ -128,5 +134,4 @@ private function mergeProperties($definition, $properties) { } } } - } diff --git a/src/Processors/MergeSwagger.php b/src/Processors/MergeSwagger.php index 53ac170b9..5fa2d058a 100644 --- a/src/Processors/MergeSwagger.php +++ b/src/Processors/MergeSwagger.php @@ -11,9 +11,11 @@ /** * Merge all @SWG\Swagger annotations into one. */ -class MergeSwagger { +class MergeSwagger +{ - public function __invoke(Swagger $swagger) { + public function __invoke(Swagger $swagger) + { $unmerged = $swagger->_unmerged; foreach ($swagger->_unmerged as $i => $annotation) { if ($annotation instanceof Swagger) { @@ -33,5 +35,4 @@ public function __invoke(Swagger $swagger) { } $swagger->_unmerged = array_values($unmerged); } - } diff --git a/src/functions.php b/src/functions.php index e7345ec83..408aa23b6 100644 --- a/src/functions.php +++ b/src/functions.php @@ -23,7 +23,8 @@ * @param string|array $exclude * @return Swagger */ -function scan($directory, $exclude = null) { +function scan($directory, $exclude = null) +{ $swagger = new Swagger([ '_context' => Context::detect(1) ]); diff --git a/tests/AbstractAnnotationTest.php b/tests/AbstractAnnotationTest.php index 10811f705..8f3d3186b 100644 --- a/tests/AbstractAnnotationTest.php +++ b/tests/AbstractAnnotationTest.php @@ -6,28 +6,33 @@ namespace SwaggerTests; -class AbstractAnnotationTest extends SwaggerTestCase { +class AbstractAnnotationTest extends SwaggerTestCase +{ - function testVendorFields() { + public function testVendorFields() + { $annotations = $this->parseComment('@SWG\Get(x={"internal-id": 123})'); $output = $annotations[0]->jsonSerialize(); $prefixedProperty = 'x-internal-id'; $this->assertSame(123, $output->$prefixedProperty); } - function testInvalidField() { + public function testInvalidField() + { $this->assertSwaggerLogEntryStartsWith('Unexpected field "doesnot" for @SWG\Get(), expecting'); $this->parseComment('@SWG\Get(doesnot="exist")'); } - function testUmergedAnnotation() { + public function testUmergedAnnotation() + { $swagger = $this->createSwaggerWithInfo(); $swagger->merge($this->parseComment('@SWG\Items()')); $this->assertSwaggerLogEntryStartsWith('Unexpected @SWG\Items(), expected to be inside @SWG\\'); $swagger->validate(); } - function testConflictedNesting() { + public function testConflictedNesting() + { $comment = <<validate(); } - function testKey() { + public function testKey() + { $comment = <<assertEquals('{"headers":{"X-CSRF-Token":{"description":"Token to prevent Cross Site Request Forgery"}}}', json_encode($annotations[0])); } - function testConflictingKey() { + public function testConflictingKey() + { $comment = <<validate(); } - function testRequiredFields() { + public function testRequiredFields() + { $annotations = $this->parseComment('@SWG\Info()'); $info = $annotations[0]; $this->assertSwaggerLogEntryStartsWith('Missing required field "title" for @SWG\Info() in '); @@ -72,12 +80,13 @@ function testRequiredFields() { $info->validate(); } - function testTypeValidation() { + public function testTypeValidation() + { $comment = <<assertSwaggerLogEntryStartsWith('@SWG\Parameter(name=123,in="dunno")->type must be "string", "number", "integer", "boolean", "array", "file" when @SWG\Parameter()->in != "body" in '); $parameter->validate(); } - } diff --git a/tests/AugmentParameterTest.php b/tests/AugmentParameterTest.php index f45470588..70de3c7e7 100644 --- a/tests/AugmentParameterTest.php +++ b/tests/AugmentParameterTest.php @@ -6,12 +6,13 @@ namespace SwaggerTests; -class AugmentParameterTest extends SwaggerTestCase { +class AugmentParameterTest extends SwaggerTestCase +{ - function testAugmentParameter() { + public function testAugmentParameter() + { $swagger = \Swagger\scan(__DIR__ . '/Fixtures/UsingRefs.php'); $this->assertCount(1, $swagger->parameters, 'Swagger contains 1 reusable parameter specification'); $this->assertEquals('ItemName', $swagger->parameters[0]->parameter, 'When no @SWG\Parameter()->parameter is specified, use @SWG\Parameter()->name'); } - } diff --git a/tests/BuildPathsTest.php b/tests/BuildPathsTest.php index 5cecc0819..948d4fc7f 100644 --- a/tests/BuildPathsTest.php +++ b/tests/BuildPathsTest.php @@ -12,9 +12,11 @@ use Swagger\Annotations\Get; use Swagger\Annotations\Post; -class BuildPathsTest extends SwaggerTestCase { +class BuildPathsTest extends SwaggerTestCase +{ - function testMergePathsWithSamePath() { + public function testMergePathsWithSamePath() + { $swagger = new Swagger([]); $swagger->paths = [ new Path(['path' => '/comments']), @@ -26,7 +28,8 @@ function testMergePathsWithSamePath() { $this->assertSame('/comments', $swagger->paths[0]->path); } - function testMergeOperationsWithSamePath() { + public function testMergeOperationsWithSamePath() + { $swagger = new Swagger([]); $swagger->_unmerged = [ new Get(['path' => '/comments']), @@ -42,5 +45,4 @@ function testMergeOperationsWithSamePath() { $this->assertInstanceOf('\Swagger\Annotations\Post', $path->post); $this->assertNull($path->put); } - } diff --git a/tests/ClassPropertiesTest.php b/tests/ClassPropertiesTest.php index f49012a14..ff6820221 100644 --- a/tests/ClassPropertiesTest.php +++ b/tests/ClassPropertiesTest.php @@ -9,9 +9,11 @@ use Swagger\Annotations\Swagger; use Swagger\Processors\ClassProperties; -class ClassPropertiesTest extends SwaggerTestCase { +class ClassPropertiesTest extends SwaggerTestCase +{ - function testClassPropertiesProcessor() { + public function testClassPropertiesProcessor() + { $processor = new ClassProperties(); $swagger = new Swagger([]); $swagger->crawl(__DIR__ . '/Fixtures/Customer.php'); @@ -41,5 +43,4 @@ function testClassPropertiesProcessor() { $this->assertSame('array', $friends->type); $this->assertSame('#/definitions/Customer', $friends->items->ref); } - } diff --git a/tests/CommandlineInterfaceTest.php b/tests/CommandlineInterfaceTest.php index 68f895643..396291c8b 100644 --- a/tests/CommandlineInterfaceTest.php +++ b/tests/CommandlineInterfaceTest.php @@ -6,16 +6,19 @@ namespace SwaggerTests; -class CommandlineInterfaceTest extends SwaggerTestCase { +class CommandlineInterfaceTest extends SwaggerTestCase +{ - protected function setUp() { + protected function setUp() + { if (defined('HHVM_VERSION')) { $this->markTestSkipped(); } parent::setUp(); } - public function testStdout() { + public function testStdout() + { exec(__DIR__ . '/../bin/swagger --stdout ' . escapeshellarg(__DIR__ . '/../Examples/swagger-spec/petstore-simple') . ' 2> /dev/null', $output, $retval); $this->assertSame(0, $retval); $json = json_decode(implode("\n", $output)); @@ -23,7 +26,8 @@ public function testStdout() { $this->compareOutput($json); } - public function testOutputTofile() { + public function testOutputTofile() + { $filename = sys_get_temp_dir() . '/swagger-php-clitest.json'; exec(__DIR__ . '/../bin/swagger -o ' . escapeshellarg($filename) . ' ' . escapeshellarg(__DIR__ . '/../Examples/swagger-spec/petstore-simple') . ' 2> /dev/null', $output, $retval); $this->assertSame(0, $retval); @@ -35,11 +39,11 @@ public function testOutputTofile() { $this->compareOutput($json); } - private function compareOutput($actual) { + private function compareOutput($actual) + { $expected = json_decode(file_get_contents(__DIR__ . '/ExamplesOutput/petstore-simple.json')); $expectedJson = json_encode($this->sorted($expected, 'petstore-simple.json'), JSON_PRETTY_PRINT); $actualJson = json_encode($this->sorted($actual, 'Swagger CLI'), JSON_PRETTY_PRINT); $this->assertEquals($expectedJson, $actualJson); } - } diff --git a/tests/ContextTest.php b/tests/ContextTest.php index 660a6fb93..e30156a6a 100644 --- a/tests/ContextTest.php +++ b/tests/ContextTest.php @@ -8,9 +8,11 @@ use Swagger\Context; -class ContextTest extends SwaggerTestCase { +class ContextTest extends SwaggerTestCase +{ - function testDetect() { + public function testDetect() + { $context = Context::detect(); $line = __LINE__ - 1; $this->assertSame('ContextTest', $context->class); @@ -22,10 +24,11 @@ function testDetect() { // $this->assertCount(1, $context->uses); // Context::detect() doesn't pick up USE statements (yet) } - function testFullyQualifiedName() { + public function testFullyQualifiedName() + { $swagger = \Swagger\scan(__DIR__ . '/Fixtures/Customer.php'); $context = $swagger->definitions[0]->_context; - // resolve with namespace + // resolve with namespace $this->assertSame('\FullyQualified', $context->fullyQualifiedName('\FullyQualified')); $this->assertSame('\SwaggerFixures\Unqualified', $context->fullyQualifiedName('Unqualified')); $this->assertSame('\SwaggerFixures\Namespace\Qualified', $context->fullyQualifiedName('Namespace\Qualified')); @@ -37,5 +40,4 @@ function testFullyQualifiedName() { $this->assertSame('\Swagger\Parser', $context->fullyQualifiedName('SwgParser')); $this->assertSame('\Swagger\Annotations\QualifiedAlias', $context->fullyQualifiedName('SWG\QualifiedAlias')); } - } diff --git a/tests/ExamplesTest.php b/tests/ExamplesTest.php index c0e69711b..10231c96a 100644 --- a/tests/ExamplesTest.php +++ b/tests/ExamplesTest.php @@ -6,7 +6,8 @@ namespace SwaggerTests; -class ExamplesTest extends SwaggerTestCase { +class ExamplesTest extends SwaggerTestCase +{ /** * Test the processed Examples against json files in ExamplesOutput. @@ -15,7 +16,8 @@ class ExamplesTest extends SwaggerTestCase { * @param string $example Example path * @param string $output Expected output (path to a json file) */ - public function testExample($example, $output) { + public function testExample($example, $output) + { $swagger = \Swagger\scan(__DIR__ . '/../Examples/' . $example); // die((string) $swagger); $this->assertSwaggerEqualsFile(__DIR__ . '/ExamplesOutput/' . $output, $swagger); @@ -25,7 +27,8 @@ public function testExample($example, $output) { * dataProvider for testExample * @return array */ - public function getExamples() { + public function getExamples() + { return [ ['petstore.swagger.io', 'petstore.swagger.io.json'], ['swagger-spec/petstore', 'petstore.json'], @@ -33,5 +36,4 @@ public function getExamples() { ['swagger-spec/petstore-with-external-docs', 'petstore-with-external-docs.json'], ]; } - } diff --git a/tests/Fixtures/Child.php b/tests/Fixtures/Child.php index 18d8503e2..5597cd9db 100644 --- a/tests/Fixtures/Child.php +++ b/tests/Fixtures/Child.php @@ -1,15 +1,16 @@ createSwaggerWithInfo(); $swagger->crawl([ @@ -26,7 +28,8 @@ function testGetChildren() { $this->assertSame($children['\\SwaggerFixtures\\GrandParent'], ['\\SwaggerFixtures\\Parent', '\\AnotherNamespace\\Child']); } - function testInheritWithoutClassProperties() { + public function testInheritWithoutClassProperties() + { $swagger = $this->createSwaggerWithInfo(); $swagger->crawl([ __DIR__ . '/Fixtures/Child.php', @@ -45,7 +48,8 @@ function testInheritWithoutClassProperties() { $this->assertCount(1, $childDefinition->properties); // Inherited 1 property, but couldn't inherit the property from Parent because it didn't have a name, also missing its own isBaby property. } - function detestInheritProcessor() { + public function detestInheritProcessor() + { $swagger = $this->createSwaggerWithInfo(); $swagger->crawl([ __DIR__ . '/Fixtures/GrandParent.php', @@ -67,5 +71,4 @@ function detestInheritProcessor() { $this->assertCount(2, $parentDefinition->properties); $swagger->validate(); } - } diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 6dbeb4b30..c9352b42e 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -9,9 +9,11 @@ use Swagger\Context; use Swagger\Parser; -class ParserTest extends SwaggerTestCase { +class ParserTest extends SwaggerTestCase +{ - function testParseContents() { + public function testParseContents() + { $annotations = $this->parseComment('@SWG\Parameter(description="This is my parameter")'); $this->assertInternalType('array', $annotations); $parameter = $annotations[0]; @@ -19,13 +21,15 @@ function testParseContents() { $this->assertSame('This is my parameter', $parameter->description); } - function testWrongCommentType() { + public function testWrongCommentType() + { $parser = new Parser(); $this->assertSwaggerLogEntryStartsWith('Annotations are only parsed inside `/**` DocBlocks'); $parser->parseContents("parseFile(__DIR__ . '/Fixtures/ThirdPartyAnnotations.php'); @@ -38,15 +42,16 @@ function testThirdPartyAnnotations() { $this->assertCount(10, $swagger->_unmerged); } - function testIndentationCorrection() { + public function testIndentationCorrection() + { $parser = new Parser(); $annotations = $parser->parseFile(__DIR__ . '/Fixtures/routes.php'); $this->assertCount(2, $annotations); } - function testDeprecatedAnnotationWarning() { + public function testDeprecatedAnnotationWarning() + { $this->assertSwaggerLogEntryStartsWith('The annotation @SWG\\Resource() is deprecated.'); $annotations = $this->parseComment('@SWG\Resource()'); } - } diff --git a/tests/ProcessingTest.php b/tests/ProcessingTest.php index b7a9f8363..b2db7d1ef 100644 --- a/tests/ProcessingTest.php +++ b/tests/ProcessingTest.php @@ -9,9 +9,11 @@ use Swagger\Annotations\Swagger; use Swagger\Processing; -class ProcessingTest extends SwaggerTestCase { +class ProcessingTest extends SwaggerTestCase +{ - function testRegister() { + public function testRegister() + { $counter = 0; $swagger = $this->createSwaggerWithInfo(); Processing::process($swagger); @@ -26,5 +28,4 @@ function testRegister() { Processing::process($swagger); $this->assertSame(1, $counter); } - } diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index 205202a7d..955314074 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -6,13 +6,13 @@ namespace SwaggerTests; +class ResponseTest extends SwaggerTestCase +{ -class ResponseTest extends SwaggerTestCase { - - function testMisspelledDefault() { + public function testMisspelledDefault() + { $annotations = $this->parseComment('@SWG\Get(@SWG\Response(response="Default", description="description"))'); $this->assertSwaggerLogEntryStartsWith('Invalid value "Default" for @SWG\Response()->response, expecting "default" or a HTTP Status Code in '); $annotations[0]->validate(); } - -} \ No newline at end of file +} diff --git a/tests/SwaggerTestCase.php b/tests/SwaggerTestCase.php index 4906f6a82..9362d1c06 100644 --- a/tests/SwaggerTestCase.php +++ b/tests/SwaggerTestCase.php @@ -16,7 +16,8 @@ use Swagger\Logger; use Swagger\Parser; -class SwaggerTestCase extends PHPUnit_Framework_TestCase { +class SwaggerTestCase extends PHPUnit_Framework_TestCase +{ /** * @var array @@ -34,7 +35,8 @@ class SwaggerTestCase extends PHPUnit_Framework_TestCase { * @param Swagger $actualSwagger * @param string $message */ - public function assertSwaggerEqualsFile($expectedFile, $actualSwagger, $message = '') { + public function assertSwaggerEqualsFile($expectedFile, $actualSwagger, $message = '') + { $expected = json_decode(file_get_contents($expectedFile)); $error = json_last_error(); if ($error !== JSON_ERROR_NONE) { @@ -50,26 +52,30 @@ public function assertSwaggerEqualsFile($expectedFile, $actualSwagger, $message $this->assertEquals($expectedJson, $actualJson, $message); } - public function assertSwaggerLog($expectedEntry, $expectedType, $message = '') { + public function assertSwaggerLog($expectedEntry, $expectedType, $message = '') + { $this->expectedLogMessages[] = function ($actualEntry, $actualType) use ($expectedEntry, $expectedType, $message) { $this->assertSame($expectedEntry, $actualEntry, $message); $this->assertSame($expectedType, $actualType, $message); }; } - public function assertSwaggerLogType($expectedType, $message = '') { + public function assertSwaggerLogType($expectedType, $message = '') + { $this->expectedLogMessages[] = function ($entry, $actualType) use ($expectedType, $message) { $this->assertSame($expectedType, $actualType, $message); }; } - public function assertSwaggerLogEntry($expectedEntry, $message = '') { + public function assertSwaggerLogEntry($expectedEntry, $message = '') + { $this->expectedLogMessages[] = function ($actualEntry, $type) use ($expectedEntry, $message) { $this->assertSame($expectedEntry, $actualEntry, $message); }; } - public function assertSwaggerLogEntryStartsWith($entryPrefix, $message = '') { + public function assertSwaggerLogEntryStartsWith($entryPrefix, $message = '') + { $this->expectedLogMessages[] = function ($entry, $type) use ($entryPrefix, $message) { if ($entry instanceof Exception) { $entry = $entry->getMessage(); @@ -78,7 +84,8 @@ public function assertSwaggerLogEntryStartsWith($entryPrefix, $message = '') { }; } - protected function setUp() { + protected function setUp() + { $this->expectedLogMessages = []; $this->originalLogger = Logger::getInstance()->log; Logger::getInstance()->log = function ($entry, $type) { @@ -100,7 +107,8 @@ protected function setUp() { parent::setUp(); } - protected function tearDown() { + protected function tearDown() + { $this->assertCount(0, $this->expectedLogMessages, count($this->expectedLogMessages) . ' Swagger\Logger messages were not triggered'); Logger::getInstance()->log = $this->originalLogger; parent::tearDown(); @@ -111,7 +119,8 @@ protected function tearDown() { * @param string $comment Contents of a comment block * @return AbstractAnnotation[] */ - protected function parseComment($comment) { + protected function parseComment($comment) + { $parser = new Parser(); $context = Context::detect(1); $context->line -= 2; // correct generated lines: " new \Swagger\Annotations\Info([ 'title' => 'Swagger-PHP Test-API', @@ -141,7 +151,8 @@ protected function createSwaggerWithInfo() { * @param string $origin * @return stdClass The sorted object */ - protected function sorted(stdClass $object, $origin = 'unknown') { + protected function sorted(stdClass $object, $origin = 'unknown') + { static $sortMap = null; if ($sortMap === null) { $sortMap = [ @@ -196,5 +207,4 @@ protected function sorted(stdClass $object, $origin = 'unknown') { } return (object) $data; } - } diff --git a/tests/ValidateRelationsTest.php b/tests/ValidateRelationsTest.php index f7cd3fce0..da7e6db0a 100644 --- a/tests/ValidateRelationsTest.php +++ b/tests/ValidateRelationsTest.php @@ -9,14 +9,16 @@ /** * Test if the nesting/parent relations are coherent. */ -class ValidateRelationsTest extends SwaggerTestCase { +class ValidateRelationsTest extends SwaggerTestCase +{ /** * * @dataProvider getAnnotations * @param string $class */ - public function testParents($class) { + public function testParents($class) + { foreach ($class::$_parents as $parent) { $found = false; foreach (array_keys($parent::$_nested) as $nested) { @@ -36,7 +38,8 @@ public function testParents($class) { * @dataProvider getAnnotations * @param string $class */ - public function testNested($class) { + public function testNested($class) + { foreach (array_keys($class::$_nested) as $nested) { $found = false; foreach ($nested::$_parents as $parent) { @@ -55,7 +58,8 @@ public function testNested($class) { * dataProvider for testExample * @return array */ - public function getAnnotations() { + public function getAnnotations() + { $classes = []; $dir = new \DirectoryIterator(__DIR__ . '/../src/Annotations'); foreach ($dir as $entry) { @@ -68,5 +72,4 @@ public function getAnnotations() { } return $classes; } - } diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index 8f774ae97..000000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,3 +0,0 @@ -