From 40b25dcb402b1501272465df6a5b3e4d043c817d Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Mon, 13 Jan 2020 21:40:11 +0000 Subject: [PATCH] Apply fixes from StyleCI --- api/config/bundles.php | 30 ++--- api/src/Command/ApiHelmCommand.php | 6 +- api/src/Command/PubliccodeCommand.php | 8 +- api/src/Filter/LikeFilter.php | 16 +-- api/src/Filter/RegexpFilter.php | 16 +-- .../Repository/NLXRequestLogRepository.php | 9 +- .../Subscriber/FieldsAndExtendSubscriber.php | 38 +++--- api/src/Subscriber/NLXSubscriber.php | 4 +- api/src/Subscriber/ValidOnSubscriber.php | 2 +- api/src/Swagger/SwaggerDecorator.php | 120 +++++++++--------- 10 files changed, 124 insertions(+), 125 deletions(-) diff --git a/api/config/bundles.php b/api/config/bundles.php index 0b350522..4f75440e 100644 --- a/api/config/bundles.php +++ b/api/config/bundles.php @@ -1,20 +1,20 @@ ['all' => true], - Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true], - Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], - Symfony\Bundle\MercureBundle\MercureBundle::class => ['all' => true], - Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], - Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], - ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], - Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true], - Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], - Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], - Conduction\CommonGroundBundle\CommonGroundBundle::class => ['all' => true], - Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true], + Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], + Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true], + Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], + Symfony\Bundle\MercureBundle\MercureBundle::class => ['all' => true], + Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], + Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], + ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], + Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true], + Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], + Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], + Conduction\CommonGroundBundle\CommonGroundBundle::class => ['all' => true], + Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true], Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true], - Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['all' => true], - Tbbc\MoneyBundle\TbbcMoneyBundle::class => ['all' => true], - Knp\Bundle\MarkdownBundle\KnpMarkdownBundle::class => ['all' => true], + Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['all' => true], + Tbbc\MoneyBundle\TbbcMoneyBundle::class => ['all' => true], + Knp\Bundle\MarkdownBundle\KnpMarkdownBundle::class => ['all' => true], ]; diff --git a/api/src/Command/ApiHelmCommand.php b/api/src/Command/ApiHelmCommand.php index 0caa16f6..72c6793c 100644 --- a/api/src/Command/ApiHelmCommand.php +++ b/api/src/Command/ApiHelmCommand.php @@ -65,9 +65,9 @@ protected function execute(InputInterface $input, OutputInterface $output) } else { // outputs multiple lines to the console (adding "\n" at the end of each line) $output->writeln([ - 'Helm Chart Creator', - '============', - $chart, + 'Helm Chart Creator', + '============', + $chart, ]); } } diff --git a/api/src/Command/PubliccodeCommand.php b/api/src/Command/PubliccodeCommand.php index 75c24371..1ff5e1fe 100644 --- a/api/src/Command/PubliccodeCommand.php +++ b/api/src/Command/PubliccodeCommand.php @@ -57,14 +57,14 @@ protected function execute(InputInterface $input, OutputInterface $output) $publiccode = $this->twig->render('publiccode/publiccode.yaml.twig'); if (!empty($location = $input->getOption('location')) && \is_string($location)) { - file_put_contents($location.'/publiccode.yaml', $publiccode); + file_put_contents($location.'/publiccode.yaml', $publiccode); $io->success(sprintf('Data written to %s/publiccode.yaml (specification version %s).', $location, $version)); } else { // outputs multiple lines to the console (adding "\n" at the end of each line) $output->writeln([ - 'Publiccode Chart', - '============', - $chart, + 'Publiccode Chart', + '============', + $chart, ]); } } diff --git a/api/src/Filter/LikeFilter.php b/api/src/Filter/LikeFilter.php index 029c73e9..0bff7b42 100644 --- a/api/src/Filter/LikeFilter.php +++ b/api/src/Filter/LikeFilter.php @@ -36,14 +36,14 @@ public function getDescription(string $resourceClass): array $description = []; foreach ($this->properties as $property => $strategy) { $description["like_$property"] = [ - 'property' => $property, - 'type' => 'string', - 'required' => false, - 'swagger' => [ - 'description' => 'This filter narows your result using the * and _ wildcards, where * is assumed to be one or more characters and _ is assumed to be a single character', - 'name' => $property, - 'type' => 'string', - ], + 'property' => $property, + 'type' => 'string', + 'required' => false, + 'swagger' => [ + 'description' => 'This filter narows your result using the * and _ wildcards, where * is assumed to be one or more characters and _ is assumed to be a single character', + 'name' => $property, + 'type' => 'string', + ], ]; } diff --git a/api/src/Filter/RegexpFilter.php b/api/src/Filter/RegexpFilter.php index da1f747e..257b8f7b 100644 --- a/api/src/Filter/RegexpFilter.php +++ b/api/src/Filter/RegexpFilter.php @@ -36,14 +36,14 @@ public function getDescription(string $resourceClass): array $description = []; foreach ($this->properties as $property => $strategy) { $description["regexp_$property"] = [ - 'property' => $property, - 'type' => 'string', - 'required' => false, - 'swagger' => [ - 'description' => 'Filter for an exact match using a [Regular expression](https://en.wikipedia.org/wiki/Regular_expression).', - 'name' => $property, - 'type' => 'string', - ], + 'property' => $property, + 'type' => 'string', + 'required' => false, + 'swagger' => [ + 'description' => 'Filter for an exact match using a [Regular expression](https://en.wikipedia.org/wiki/Regular_expression).', + 'name' => $property, + 'type' => 'string', + ], ]; } diff --git a/api/src/Repository/NLXRequestLogRepository.php b/api/src/Repository/NLXRequestLogRepository.php index 69add53c..33986f87 100644 --- a/api/src/Repository/NLXRequestLogRepository.php +++ b/api/src/Repository/NLXRequestLogRepository.php @@ -6,7 +6,6 @@ use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Common\Persistence\ManagerRegistry; - /** * @method NLXRequestLog|null find($id, $lockMode = null, $lockVersion = null) * @method NLXRequestLog|null findOneBy(array $criteria, array $orderBy = null) @@ -15,10 +14,10 @@ */ class NLXRequestLogRepository extends ServiceEntityRepository { - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, ExampleEntity::class); - } + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, ExampleEntity::class); + } /** * @return NLXRequestLog[] Returns an array of NLXRequestLog objects diff --git a/api/src/Subscriber/FieldsAndExtendSubscriber.php b/api/src/Subscriber/FieldsAndExtendSubscriber.php index d50440c7..e4e45b7a 100644 --- a/api/src/Subscriber/FieldsAndExtendSubscriber.php +++ b/api/src/Subscriber/FieldsAndExtendSubscriber.php @@ -8,8 +8,8 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\PropertyAccess\PropertyAccess; +use Symfony\Component\Serializer\SerializerInterface; class FieldsAndExtendSubscriber implements EventSubscriberInterface { @@ -27,13 +27,13 @@ public function __construct(ParameterBagInterface $params, SerializerInterface $ public static function getSubscribedEvents() { return [ - KernelEvents::VIEW => ['FilterFields', EventPriorities::PRE_SERIALIZE], + KernelEvents::VIEW => ['FilterFields', EventPriorities::PRE_SERIALIZE], ]; } public function FilterFields(GetResponseForControllerResultEvent $event) { - /* @todo Contains a bug + /* @todo Contains a bug $result = $event->getControllerResult(); $fields = $event->getRequest()->query->get('fields'); $extends = $event->getRequest()->query->get('extend'); @@ -42,14 +42,14 @@ public function FilterFields(GetResponseForControllerResultEvent $event) $contentType= $event->getRequest()->headers->get('Accept'); } - + // Only do somthing if fields is query supplied if (!$fields && !$extends) { return $result; } - + // This needs to be bassed on the content-type - + // Lets set a return content type switch ($contentType) { case 'application/json': @@ -73,15 +73,15 @@ public function FilterFields(GetResponseForControllerResultEvent $event) if (!is_array($extends)) { $extends= explode(',', $extends); } - + // Its possible to nest fields for filterins foreach($fields as $key=>$value){ // Lets check if the fields contain one or more .'s if (strpos($value, '.') !== false) { - // This is where it gets complicated couse it could go on indevinitly + // This is where it gets complicated couse it could go on indevinitly } } - + // Overwrite maxdepth for extended properties // we always need to return an id and links (in order not to break stuff) @@ -95,18 +95,18 @@ public function FilterFields(GetResponseForControllerResultEvent $event) // now we need to overide the normal subscriber $json = $this->serializer->serialize( $result, - $renderType, - ['enable_max_depth' => true, + $renderType, + ['enable_max_depth' => true, 'attributes'=> $fields] ); - - + + $jsonArray = json_decode($json, true); - - + + // The we want to extend properties from the extend query foreach($extends as $extend){ - // @todo add security checks + // @todo add security checks // Get new object for the extend $extendObject = $this->propertyAccessor->getValue($result, $extend); // turn to json @@ -115,12 +115,12 @@ public function FilterFields(GetResponseForControllerResultEvent $event) $type, ['enable_max_depth' => true, 'attributes'=> $fields] - ); + ); // add to the array $jsonArray[$extend] = json_decode($extendjson, true); } - - + + $json = json_encode($jsonArray); $response = new Response( diff --git a/api/src/Subscriber/NLXSubscriber.php b/api/src/Subscriber/NLXSubscriber.php index 5411001e..09cd5e55 100644 --- a/api/src/Subscriber/NLXSubscriber.php +++ b/api/src/Subscriber/NLXSubscriber.php @@ -33,8 +33,8 @@ public function __construct(ParameterBagInterface $params, EntityManagerInterfac public static function getSubscribedEvents() { return [ - KernelEvents::VIEW => ['NLXLog', EventPriorities::PRE_VALIDATE], - KernelEvents::VIEW => ['NLXAudit', EventPriorities::PRE_SERIALIZE], + KernelEvents::VIEW => ['NLXLog', EventPriorities::PRE_VALIDATE], + KernelEvents::VIEW => ['NLXAudit', EventPriorities::PRE_SERIALIZE], ]; } diff --git a/api/src/Subscriber/ValidOnSubscriber.php b/api/src/Subscriber/ValidOnSubscriber.php index 4aac9f15..dd237ae9 100644 --- a/api/src/Subscriber/ValidOnSubscriber.php +++ b/api/src/Subscriber/ValidOnSubscriber.php @@ -29,7 +29,7 @@ public function __construct(ParameterBagInterface $params, EntityManagerInterfac public static function getSubscribedEvents() { return [ - KernelEvents::VIEW => ['validOn', EventPriorities::PRE_SERIALIZE], + KernelEvents::VIEW => ['validOn', EventPriorities::PRE_SERIALIZE], ]; } diff --git a/api/src/Swagger/SwaggerDecorator.php b/api/src/Swagger/SwaggerDecorator.php index b0610232..6d9b5de2 100644 --- a/api/src/Swagger/SwaggerDecorator.php +++ b/api/src/Swagger/SwaggerDecorator.php @@ -63,17 +63,17 @@ public function normalize($object, $format = null, array $context = []) // Lets add JWT-Oauth $docs['securityDefinitions']['JWT-Oauth'] = [ - 'type' => 'oauth2', - 'authorizationUrl'=> 'http://petstore.swagger.io/api/oauth/dialog', - 'flow' => 'implicit', - 'scopes' => [], //scopes will be filled later autmaticly + 'type' => 'oauth2', + 'authorizationUrl'=> 'http://petstore.swagger.io/api/oauth/dialog', + 'flow' => 'implicit', + 'scopes' => [], //scopes will be filled later autmaticly ]; $docs['securityDefinitions']['JWT-Token'] = [ - 'type' => 'apiKey', - 'in' => 'header', // can be "header", "query" or "cookie" - 'name' => 'Authorization', // name of the header, query parameter or cookie - 'scopes'=> [], //scopes will be filled later autmaticly + 'type' => 'apiKey', + 'in' => 'header', // can be "header", "query" or "cookie" + 'name' => 'Authorization', // name of the header, query parameter or cookie + 'scopes'=> [], //scopes will be filled later autmaticly ]; // Lets get al the entities known to doctrine @@ -114,8 +114,8 @@ public function normalize($object, $format = null, array $context = []) //$additionalEntityDocs = $this->getAdditionalEntityDocs($entity); $entityDocs = $this->getAdditionalEntityDocs($entity); // Only run if we have aditional docs - if(array_key_exists('properties',$entityDocs)){ - $additionalDocs = array_merge($additionalDocs, $entityDocs['properties']); + if (array_key_exists('properties', $entityDocs)) { + $additionalDocs = array_merge($additionalDocs, $entityDocs['properties']); } // Security @@ -196,16 +196,16 @@ public function normalize($object, $format = null, array $context = []) // NLX loging headers $call['parameters'][] = [ - 'name' => 'Authorization', - 'description' => 'The JWT of the entity performing the request', - 'in' => 'header', + 'name' => 'Authorization', + 'description' => 'The JWT of the entity performing the request', + 'in' => 'header', ]; // NLX loging headers $call['parameters'][] = [ - 'name' => 'API-Version', - 'description' => 'The version of the API conform [Landelijke API-strategie.](https://geonovum.github.io/KP-APIs/#versioning)', - 'example' => '1.0.1', - 'in' => 'header', + 'name' => 'API-Version', + 'description' => 'The version of the API conform [Landelijke API-strategie.](https://geonovum.github.io/KP-APIs/#versioning)', + 'example' => '1.0.1', + 'in' => 'header', ]; /* // NLX loging headers @@ -223,33 +223,33 @@ public function normalize($object, $format = null, array $context = []) */ // NLX loging headers $call['parameters'][] = [ - 'name' => 'X-NLX-Logrecord-ID', - 'description' => 'A globally unique id of the request, which makes a request traceable throughout the network.', - 'in' => 'header', + 'name' => 'X-NLX-Logrecord-ID', + 'description' => 'A globally unique id of the request, which makes a request traceable throughout the network.', + 'in' => 'header', ]; // NLX loging headers $call['parameters'][] = [ - 'name' => 'X-NLX-Request-Process-Id', - 'description' => 'A process id for purpose registration (doelbinding)', - 'in' => 'header', + 'name' => 'X-NLX-Request-Process-Id', + 'description' => 'A process id for purpose registration (doelbinding)', + 'in' => 'header', ]; // NLX loging headers $call['parameters'][] = [ - 'name' => 'X-NLX-Request-Data-Elements', - 'description' => 'A list of requested data elements', - 'in' => 'header', + 'name' => 'X-NLX-Request-Data-Elements', + 'description' => 'A list of requested data elements', + 'in' => 'header', ]; // NLX loging headers $call['parameters'][] = [ - 'name' => 'X-NLX-Request-Data-Subject', - 'description' => 'A key-value list of data subjects related to this request. e.g. `bsn=12345678, kenteken=ab-12-fg`', - 'in' => 'header', + 'name' => 'X-NLX-Request-Data-Subject', + 'description' => 'A key-value list of data subjects related to this request. e.g. `bsn=12345678, kenteken=ab-12-fg`', + 'in' => 'header', ]; // NLX loging headers $call['parameters'][] = [ - 'name' => 'X-NLX-Audit-Clarification', - 'description' => 'A clarification as to why a request has been made (doelbinding)', - 'in' => 'header', + 'name' => 'X-NLX-Audit-Clarification', + 'description' => 'A clarification as to why a request has been made (doelbinding)', + 'in' => 'header', ]; if ($method == 'get') { @@ -259,48 +259,48 @@ public function normalize($object, $format = null, array $context = []) // WEBSUB header $call['parameters'][] = [ - 'name' => 'Link', - 'description' => 'A [websub](https://www.w3.org/TR/websub/#discovery) header like ; rel="hub"', - 'in' => 'header', + 'name' => 'Link', + 'description' => 'A [websub](https://www.w3.org/TR/websub/#discovery) header like ; rel="hub"', + 'in' => 'header', ]; // Lets add the extend functionality $call['parameters'][] = [ - 'name' => 'extend[]', - 'required' => false, - 'description' => 'An array of nested objects to include in the return object', - 'in' => 'query', - 'schema' => ['type'=>'array'], + 'name' => 'extend[]', + 'required' => false, + 'description' => 'An array of nested objects to include in the return object', + 'in' => 'query', + 'schema' => ['type'=>'array'], ]; // Lets add the fields functionality $call['parameters'][] = [ - 'name' => 'fields[]', - 'required' => false, - 'description' => 'An array of fields to return in output, wil return all fields is not supplied', - 'in' => 'query', - 'schema' => ['type'=>'array'], + 'name' => 'fields[]', + 'required' => false, + 'description' => 'An array of fields to return in output, wil return all fields is not supplied', + 'in' => 'query', + 'schema' => ['type'=>'array'], ]; // Lets add some time travel $call['parameters'][] = [ - 'name' => 'validOn', - 'required' => false, - 'description' => 'Returns object as valid on a given date time', - 'schema' => ['type'=>'string', 'format' => 'date-time'], - 'in' => 'query', + 'name' => 'validOn', + 'required' => false, + 'description' => 'Returns object as valid on a given date time', + 'schema' => ['type'=>'string', 'format' => 'date-time'], + 'in' => 'query', ]; $call['parameters'][] = [ - 'name' => 'validFrom', - 'required' => false, - 'description' => 'Returns objects valid from a given date time', - 'schema' => ['type'=>'string', 'format' => 'date-time'], - 'in' => 'query', + 'name' => 'validFrom', + 'required' => false, + 'description' => 'Returns objects valid from a given date time', + 'schema' => ['type'=>'string', 'format' => 'date-time'], + 'in' => 'query', ]; $call['parameters'][] = [ - 'name' => 'validUntil', - 'required' => false, - 'description' => 'Returns objects valid until a given date time', - 'schema' => ['type'=>'string', 'format' => 'date-time'], - 'in' => 'query', + 'name' => 'validUntil', + 'required' => false, + 'description' => 'Returns objects valid until a given date time', + 'schema' => ['type'=>'string', 'format' => 'date-time'], + 'in' => 'query', ]; } }