Skip to content

Commit

Permalink
Replace get_class with instanceof and remove @var annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyVlcek authored and Milan Felix Šulc committed Sep 2, 2019
1 parent ed47bc7 commit 1d31ac2
Showing 1 changed file with 17 additions and 33 deletions.
50 changes: 17 additions & 33 deletions src/DI/Loader/DoctrineAnnotationLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,33 +129,29 @@ protected function parseControllerClassAnnotations(Controller $controller, Class
// Iterate over all class annotations in controller
foreach ($annotations as $annotation) {
// Parse @Path =======================
if (get_class($annotation) === Path::class) {
/** @var Path $annotation */
if ($annotation instanceof Path) {
$controller->setPath($annotation->getPath());
continue;
}

// Parse @ControllerId =========================
if (get_class($annotation) === ControllerId::class) {
/** @var ControllerId $annotation */
if ($annotation instanceof ControllerId) {
$controller->setId($annotation->getName());
}

// Parse @Tag ==================================
if (get_class($annotation) === Tag::class) {
/** @var Tag $annotation */
if ($annotation instanceof Tag) {
$controller->addTag($annotation->getName(), $annotation->getValue());
}

// Parse @OpenApi ============================
if (get_class($annotation) === OpenApi::class) {
/** @var OpenApi $annotation */
if ($annotation instanceof OpenApi) {
$controller->setOpenApi(Neon::decode($annotation->getData()) ?? []);
continue;
}

// Parse @GroupId ==============================
if (get_class($annotation) === GroupId::class) {
if ($annotation instanceof GroupId) {
throw new InvalidStateException(sprintf('Annotation @GroupId cannot be on non-abstract "%s"', $class->getName()));
}
}
Expand All @@ -171,20 +167,17 @@ protected function parseControllerClassAnnotations(Controller $controller, Class
// Iterate over all parent class annotations
foreach ($parentAnnotations as $annotation) {
// Parse @GroupId ==========================
if (get_class($annotation) === GroupId::class) {
/** @var GroupId $annotation */
if ($annotation instanceof GroupId) {
$controller->addGroupId($annotation->getName());
}

// Parse @Path ========================
if (get_class($annotation) === Path::class) {
/** @var Path $annotation */
if ($annotation instanceof Path) {
$controller->addGroupPath($annotation->getPath());
}

// Parse @Tag ==============================
if (get_class($annotation) === Tag::class) {
/** @var Tag $annotation */
if ($annotation instanceof Tag) {
$controller->addTag($annotation->getName(), $annotation->getValue());
}
}
Expand All @@ -211,36 +204,31 @@ protected function parseControllerMethodsAnnotations(Controller $controller, Cla
// Iterate over all method annotations
foreach ($annotations as $annotation) {
// Parse @Path =============================
if (get_class($annotation) === Path::class) {
/** @var Path $annotation */
if ($annotation instanceof Path) {
$schemaMethod->setPath($annotation->getPath());
continue;
}

// Parse @Method ===========================
if (get_class($annotation) === Method::class) {
/** @var Method $annotation */
if ($annotation instanceof Method) {
$schemaMethod->addHttpMethods($annotation->getMethods());
continue;
}

// Parse @Tag ==============================
if (get_class($annotation) === Tag::class) {
/** @var Tag $annotation */
if ($annotation instanceof Tag) {
$schemaMethod->addTag($annotation->getName(), $annotation->getValue());
continue;
}

// Parse @Id ===============================
if (get_class($annotation) === Id::class) {
/** @var Id $annotation */
if ($annotation instanceof Id) {
$schemaMethod->setId($annotation->getName());
continue;
}

// Parse @RequestParameters ================
if (get_class($annotation) === RequestParameters::class) {
/** @var RequestParameters $annotation */
if ($annotation instanceof RequestParameters) {
foreach ($annotation->getParameters() as $p) {
$parameter = $schemaMethod->addParameter($p->getName(), $p->getType());
$parameter->setDescription($p->getDescription());
Expand All @@ -253,8 +241,7 @@ protected function parseControllerMethodsAnnotations(Controller $controller, Cla
}

// Parse @Response ================
if (get_class($annotation) === Responses::class) {
/** @var Responses $annotation */
if ($annotation instanceof Responses) {
foreach ($annotation->getResponses() as $r) {
$response = $schemaMethod->addResponse($r->getCode(), $r->getDescription());
$response->setEntity($r->getEntity());
Expand All @@ -263,8 +250,7 @@ protected function parseControllerMethodsAnnotations(Controller $controller, Cla
}

// Parse @Request ================
if (get_class($annotation) === RequestBody::class) {
/** @var RequestBody $annotation */
if ($annotation instanceof RequestBody) {
$requestBody = new MethodRequestBody();
$requestBody->setDescription($annotation->getDescription());
$requestBody->setEntity($annotation->getEntity());
Expand All @@ -275,15 +261,13 @@ protected function parseControllerMethodsAnnotations(Controller $controller, Cla
}

// Parse @OpenApi ================
if (get_class($annotation) === OpenApi::class) {
/** @var OpenApi $annotation */
if ($annotation instanceof OpenApi) {
$schemaMethod->setOpenApi(Neon::decode($annotation->getData()) ?? []);
continue;
}

// Parse @Negotiations =====================
if (get_class($annotation) === Negotiations::class) {
/** @var Negotiations $annotation */
if ($annotation instanceof Negotiations) {
foreach ($annotation->getNegotiations() as $n) {
$negotiation = $schemaMethod->addNegotiation($n->getSuffix());
$negotiation->setDefault($n->isDefault());
Expand Down

0 comments on commit 1d31ac2

Please sign in to comment.