From 3954cacc408e10f748a8451bdd706fb44f17bcef Mon Sep 17 00:00:00 2001 From: benatespina Date: Mon, 12 Oct 2015 16:58:46 +0200 Subject: [PATCH] Updated project structure and CS --- .coveralls.yml | 12 --- .editorconfig | 19 +++-- .formatter.yml | 23 ++++++ .gitignore | 24 ++---- .php_cs | 37 +++++++++ .phpspec_cs | 35 +++++++++ .travis.yml | 18 ++--- LICENSE | 4 +- README.md | 76 ++++++++++--------- Resources/config/routing.yml | 11 --- composer.json | 26 ++----- phpmd.xml | 41 ---------- phpspec.yml | 17 ----- ruleset.xml | 67 ---------------- spec/Annotation/ApiDocSpec.php | 38 ++++++++++ spec/Controller/ApiDocControllerSpec.php | 55 ++++++++++++++ .../ExtractorHandlerCompilerPassSpec.php | 64 ++++++++++++++++ .../DependencyInjection/ConfigurationSpec.php | 39 ++++++++++ .../KretaSimpleApiDocExtensionSpec.php | 39 ++++++++++ spec/KretaSimpleApiDocBundleSpec.php | 44 +++++++++++ {Annotation => src/Annotation}/ApiDoc.php | 35 +++++---- .../Controller}/ApiDocController.php | 18 +++-- .../Compiler/ExtractorHandlerCompilerPass.php | 19 ++--- .../DependencyInjection}/Configuration.php | 15 ++-- .../KretaSimpleApiDocExtension.php | 17 +++-- .../Extractor}/ApiDocExtractor.php | 65 ++++++++-------- .../KretaSimpleApiDocBundle.php | 15 ++-- {Parser => src/Parser}/ValidationParser.php | 42 +++++++--- src/Resources/config/routing.yml | 12 +++ .../Resources}/config/services.yml | 11 +-- 30 files changed, 600 insertions(+), 338 deletions(-) delete mode 100644 .coveralls.yml create mode 100644 .formatter.yml create mode 100644 .php_cs create mode 100644 .phpspec_cs delete mode 100644 Resources/config/routing.yml delete mode 100644 phpmd.xml delete mode 100644 phpspec.yml delete mode 100644 ruleset.xml create mode 100644 spec/Annotation/ApiDocSpec.php create mode 100644 spec/Controller/ApiDocControllerSpec.php create mode 100644 spec/DependencyInjection/Compiler/ExtractorHandlerCompilerPassSpec.php create mode 100644 spec/DependencyInjection/ConfigurationSpec.php create mode 100644 spec/DependencyInjection/KretaSimpleApiDocExtensionSpec.php create mode 100644 spec/KretaSimpleApiDocBundleSpec.php rename {Annotation => src/Annotation}/ApiDoc.php (77%) rename {Controller => src/Controller}/ApiDocController.php (58%) rename {DependencyInjection => src/DependencyInjection}/Compiler/ExtractorHandlerCompilerPass.php (78%) rename {DependencyInjection => src/DependencyInjection}/Configuration.php (58%) rename {DependencyInjection => src/DependencyInjection}/KretaSimpleApiDocExtension.php (63%) rename {Extractor => src/Extractor}/ApiDocExtractor.php (72%) rename KretaSimpleApiDocBundle.php => src/KretaSimpleApiDocBundle.php (59%) rename {Parser => src/Parser}/ValidationParser.php (80%) create mode 100644 src/Resources/config/routing.yml rename {Resources => src/Resources}/config/services.yml (77%) diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index 293c9e3..0000000 --- a/.coveralls.yml +++ /dev/null @@ -1,12 +0,0 @@ -# This file belongs to Kreta. -# The source code of application includes a LICENSE file -# with all information about license. -# -# @author benatespina -# @author gorkalaucirica - -service_name: travis-ci - -src_dir: . -coverage_clover: coverage.xml -json_path: coveralls-upload.json diff --git a/.editorconfig b/.editorconfig index cc4357b..6d99447 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,17 +1,20 @@ -; This file belongs to Kreta. -; The source code of application includes a LICENSE file -; with all information about license. +; This file is part of the Kreta package. ; -; @author benatespina -; @author gorkalaucirica +; (c) Beñat Espiña +; (c) Gorka Laucirica +; +; For the full copyright and license information, please view the LICENSE +; file that was distributed with this source code. -; top-most EditorConfig file root = true -; Unix-style newlines [*] end_of_line = LF -[*.php] +[{*.php, *.yml}] +indent_style = space +indent_size = 4 + +[composer.json] indent_style = space indent_size = 4 diff --git a/.formatter.yml b/.formatter.yml new file mode 100644 index 0000000..f33f788 --- /dev/null +++ b/.formatter.yml @@ -0,0 +1,23 @@ +# This file is part of the Kreta package. +# +# (c) Beñat Espiña +# (c) Gorka Laucirica +# +# For the full copyright and license information, please view the LICENSE +# file that was distributed with this source code. + +use-sort: + group-type: each + sort-type: alph + sort-direction: asc + +header: | + /* + * This file is part of the Kreta package. + * + * (c) Beñat Espiña + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ diff --git a/.gitignore b/.gitignore index adc99c7..27344f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,19 +1,11 @@ -# This file belongs to Kreta. -# The source code of application includes a LICENSE file -# with all information about license. +# This file is part of the Kreta package. # -# @author benatespina -# @author gorkalaucirica - -#### Generic #### -src/ -vendor/ -bin/ +# (c) Beñat Espiña +# (c) Gorka Laucirica +# +# For the full copyright and license information, please view the LICENSE +# file that was distributed with this source code. -#### Composer #### -/composer.phar composer.lock - -#### PHPSpec #### -/coverage -coverage.xml +composer.phar +vendor diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..00bea4c --- /dev/null +++ b/.php_cs @@ -0,0 +1,37 @@ + + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + + +$finder = Symfony\CS\Finder\DefaultFinder::create() + ->in(__DIR__ . '/src') + ->notName('*.yml') + ->notName('*.xml') + ->notName('*Spec.php'); + +return Symfony\CS\Config\Config::create() + ->finder($finder) + ->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL) + ->fixers([ + '-unalign_double_arrow', + '-concat_without_spaces', + 'align_double_arrow', + 'concat_with_spaces', + 'multiline_spaces_before_semicolon', + 'newline_after_open_tag', + 'ordered_use', + 'php4_constructor', + 'phpdoc_order', + 'short_array_syntax', + 'short_echo_tag', + 'strict', + 'strict_param' + ]); diff --git a/.phpspec_cs b/.phpspec_cs new file mode 100644 index 0000000..5e03ccc --- /dev/null +++ b/.phpspec_cs @@ -0,0 +1,35 @@ + + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +$finder = Symfony\Component\Finder\Finder::create() + ->in(__DIR__ . '/spec') + ->name('*Spec.php'); + +return Symfony\CS\Config\Config::create() + ->finder($finder) + ->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL) + ->fixers([ + '-visibility', + '-unalign_double_arrow', + '-concat_without_spaces', + 'align_double_arrow', + 'concat_with_spaces', + 'multiline_spaces_before_semicolon', + 'newline_after_open_tag', + 'ordered_use', + 'php4_constructor', + 'phpdoc_order', + 'short_array_syntax', + 'short_echo_tag', + 'strict', + 'strict_param' + ]); diff --git a/.travis.yml b/.travis.yml index 96164a7..c42c071 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,12 @@ -# This file belongs to Kreta. -# The source code of application includes a LICENSE file -# with all information about license. +# This file is part of the Kreta package. # -# @author benatespina -# @author gorkalaucirica +# (c) Beñat Espiña +# (c) Gorka Laucirica +# +# For the full copyright and license information, please view the LICENSE +# file that was distributed with this source code. + +sudo: false language: php @@ -21,10 +24,7 @@ install: - composer update --no-interaction ${COMPOSER_OPTIONS} script: - - bin/phpspec run -fpretty - -after_script: - - bin/coveralls -v + - vendor/bin/phpspec run -fpretty cache: directories: diff --git a/LICENSE b/LICENSE index e80a0ac..12d472e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,8 +1,6 @@ -License - The MIT License (MIT) -Copyright (c) 2015 Kreta Simple ApiDoc Bundle - by gorkalaucirica and benatespina +Copyright (c) 2014, 2015 Kreta - by gorkalaucirica and benatespina Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index 3e5fe36..5cbad29 100644 --- a/README.md +++ b/README.md @@ -1,57 +1,65 @@ -# Kreta Simple Api Doc Bundle -> Bundle that generates Api documentation on top of **[NelmioApiDocBundle][0]**. +#Kreta Simple Api Doc Bundle +>Bundle that generates Api documentation on top of **[NelmioApiDocBundle][0]**. +[![SensioLabsInsight](https://insight.sensiolabs.com/projects/87e637fa-3e4e-47d1-8b27-fd5fe65e8def/mini.png)](https://insight.sensiolabs.com/projects/87e637fa-3e4e-47d1-8b27-fd5fe65e8def) [![Build Status](https://travis-ci.org/kreta/SimpleApiDocBundle.svg?branch=master)](https://travis-ci.org/kreta/SimpleApiDocBundle) -[![Coverage Status](https://img.shields.io/coveralls/kreta/SimpleApiDocBundle.svg)](https://coveralls.io/r/kreta/SimpleApiDocBundle) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/kreta/SimpleApiDocBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/kreta/SimpleApiDocBundle/?branch=master) -[![HHVM Status](http://hhvm.h4cc.de/badge/kreta/simple-api-doc-bundle.svg)](http://hhvm.h4cc.de/package/kreta/simple-api-doc-bundle) [![Total Downloads](https://poser.pugx.org/kreta/simple-api-doc-bundle/downloads)](https://packagist.org/packages/kreta/simple-api-doc-bundle) - [![Latest Stable Version](https://poser.pugx.org/kreta/simple-api-doc-bundle/v/stable.svg)](https://packagist.org/packages/kreta/simple-api-doc-bundle) [![Latest Unstable Version](https://poser.pugx.org/kreta/simple-api-doc-bundle/v/unstable.svg)](https://packagist.org/packages/kreta/simple-api-doc-bundle) -Tests ------ - +##Tests This bundle is completely tested by **[PHPSpec][1], SpecBDD framework for PHP**. Because you want to contribute or simply because you want to throw the tests, you have to type the following command in your terminal. +``` +$ vendor/bin/phpspec run -fpretty +``` +##Contributing +This bundle follows PHP coding standards, so pull requests need to execute the Fabien Potencier's [PHP-CS-Fixer][5] +and Marc Morera's [PHP-Formatter][6]. Furthermore, if the PR creates some not-PHP file remember that you have to put +the license header manually. +``` +$ vendor/bin/php-cs-fixer fix +$ vendor/bin/php-cs-fixer fix --config-file .phpspec_cs - $ bin/phpspec run -fpretty +$ vendor/bin/php-formatter formatter:use:sort src/ +$ vendor/bin/php-formatter formatter:use:sort spec/ +$ vendor/bin/php-formatter formatter:header:fix src/ +$ vendor/bin/php-formatter formatter:header:fix spec/ +``` ->*Depends the location of the `bin` directory (sometimes in the root dir; sometimes in the `/vendor` dir) the way that -works every time is to use the absolute path of the binary `vendor/phpspec/phpspec/bin/phpspec`* +There is also a policy for contributing to this project. Pull requests must be explained step by step to make the +review process easy in order to accept and merge them. New methods or code improvements must come paired with +[PHPSpec][1] tests. -Contributing ------------- +If you would like to contribute it is a good point to follow Symfony contribution standards, so please read the +[Contributing Code][2] in the project documentation. If you are submitting a pull request, please follow the guidelines +in the [Submitting a Patch][3] section and use the [Pull Request Template][4]. -This bundle follows PHP coding standards, so pull requests must pass PHP Code Sniffer and PHP Mess Detector -checks. In the root directory of this project you have the **custom rulesets** ([ruleset.xml]() for PHPCS and -[phpmd.xml]() for PHPMD). +If you have any doubt or maybe you want to share some opinion, you can use our **Gitter chat**. +[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/kreta/kreta?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -There is also a policy for contributing to this project. Pull requests must -be explained step by step to make the review process easy in order to -accept and merge them. New methods or code improvements must come paired with [PHPSpec][1] tests. +##To do +[]: Unit tests of [ValidationParser][7] class. +[]: Unit tests of [ApiDocExtractor][8] class. -If you would like to contribute it is a good point to follow Symfony contribution standards, -so please read the [Contributing Code][2] in the project -documentation. If you are submitting a pull request, please follow the guidelines -in the [Submitting a Patch][3] section and use the [Pull Request Template][4]. +##Credits +Kreta is created by: +> +**@benatespina** - [benatespina@gmail.com](mailto:benatespina@gmail.com)
+**@gorkalaucirica** - [gorka.lauzirika@gmail.com](mailto:gorka.lauzirika@gmail.com) + +##Licensing Options +[![License](https://poser.pugx.org/kreta/simple-api-doc-bundle/license.svg)](https://github.com/kreta/SimpleApiDocBundle/blob/master/LICENSE) -[0]: https://github.com/nelmio/NelmioApiDocBundle [1]: http://www.phpspec.net/ [2]: http://symfony.com/doc/current/contributing/code/index.html [3]: http://symfony.com/doc/current/contributing/code/patches.html#check-list [4]: http://symfony.com/doc/current/contributing/code/patches.html#make-a-pull-request +[5]: http://cs.sensiolabs.org/ +[6]: https://github.com/mmoreram/php-formatter -Credits -------- -Kreta Simple Api Doc Bundle is created by: -> -**@benatespina** - [benatespina@gmail.com](mailto:benatespina@gmail.com)
-**@gorkalaucirica** - [gorka.lauzirika@gmail.com](mailto:gorka.lauzirika@gmail.com) - -Licensing Options ------------------ -[![License](https://poser.pugx.org/kreta/simple-api-doc-bundle/license.svg)](https://github.com/kreta/SimpleApiDocBundle/blob/master/LICENSE) +[7]: https://github.com/kreta/SimpleApiDocBundle/blob/master/src/Parser/ValidationParser.php +[8]: https://github.com/kreta/SimpleApiDocBundle/blob/master/src/Extractor/ApiDocExtractor.php diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml deleted file mode 100644 index c63f828..0000000 --- a/Resources/config/routing.yml +++ /dev/null @@ -1,11 +0,0 @@ -# This file belongs to Kreta. -# The source code of application includes a LICENSE file -# with all information about license. -# -# @author benatespina -# @author gorkalaucirica - -nelmio_api_doc_index: - pattern: / - defaults: { _controller: KretaSimpleApiDocBundle:ApiDoc:index } - methods: [GET] diff --git a/composer.json b/composer.json index 7cb98a3..7347ad1 100644 --- a/composer.json +++ b/composer.json @@ -18,29 +18,19 @@ } ], "require": { - "php": ">=5.4", - "nelmio/api-doc-bundle": "~2.8" + "php": ">=5.4", + + "nelmio/api-doc-bundle": "^2.8" }, "require-dev": { - "phpspec/phpspec": "~2.2", - "henrikbjorn/phpspec-code-coverage": "~1.0", - "satooshi/php-coveralls": "~0.6,>=0.6.2", - "squizlabs/php_codesniffer": "~1.0", - "phpmd/phpmd": "~2.1" + "fabpot/php-cs-fixer": "^1.10", + "mmoreram/php-formatter": "^1.0", + "phpspec/phpspec": "^2.3" }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/kreta/php-coveralls" - } - ], "autoload": { - "psr-4": { "Kreta\\SimpleApiDocBundle\\": "" } + "psr-4": { "Kreta\\SimpleApiDocBundle\\": "src/" } }, "autoload-dev": { - "psr-4": { "Kreta\\SimpleApiDocBundle\\spec\\": "spec/" } - }, - "config": { - "bin-dir": "bin" + "psr-4": { "spec\\Kreta\\SimpleApiDocBundle\\": "spec/" } } } diff --git a/phpmd.xml b/phpmd.xml deleted file mode 100644 index fdf5142..0000000 --- a/phpmd.xml +++ /dev/null @@ -1,41 +0,0 @@ - - -Kreta PHP Mess Detector ruleset - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/phpspec.yml b/phpspec.yml deleted file mode 100644 index 95db60a..0000000 --- a/phpspec.yml +++ /dev/null @@ -1,17 +0,0 @@ -# This file belongs to Kreta. -# The source code of application includes a LICENSE file -# with all information about license. -# -# @author benatespina -# @author gorkalaucirica - -extensions: - - PhpSpec\Extension\CodeCoverageExtension - -code_coverage: - format: - - html - - clover - output: - html: coverage - clover: coverage.xml diff --git a/ruleset.xml b/ruleset.xml deleted file mode 100644 index 4352fde..0000000 --- a/ruleset.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - Kreta PHP Code Sniffer ruleset - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spec/Annotation/ApiDocSpec.php b/spec/Annotation/ApiDocSpec.php new file mode 100644 index 0000000..5ea758a --- /dev/null +++ b/spec/Annotation/ApiDocSpec.php @@ -0,0 +1,38 @@ + + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace spec\Kreta\SimpleApiDocBundle\Annotation; + +use PhpSpec\ObjectBehavior; + +/** + * Spec of Api Doc class. + * + * @author Beñat Espiña + */ +class ApiDocSpec extends ObjectBehavior +{ + function let() + { + $this->beConstructedWith(['statusCodes' => ['401' => 'Bad authorized']]); + } + + function it_is_initializable() + { + $this->shouldHaveType('Kreta\SimpleApiDocBundle\Annotation\ApiDoc'); + } + + function it_extends_nelmio_api_doc() + { + $this->shouldHaveType('Nelmio\ApiDocBundle\Annotation\ApiDoc'); + } +} diff --git a/spec/Controller/ApiDocControllerSpec.php b/spec/Controller/ApiDocControllerSpec.php new file mode 100644 index 0000000..828d593 --- /dev/null +++ b/spec/Controller/ApiDocControllerSpec.php @@ -0,0 +1,55 @@ + + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace spec\Kreta\SimpleApiDocBundle\Controller; + +use Kreta\SimpleApiDocBundle\Extractor\ApiDocExtractor; +use Nelmio\ApiDocBundle\Formatter\HtmlFormatter; +use PhpSpec\ObjectBehavior; +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** + * Spec of Api Doc controller class. + * + * @author Beñat Espiña + */ +class ApiDocControllerSpec extends ObjectBehavior +{ + function let(ContainerInterface $container) + { + $this->setContainer($container); + } + + function it_is_initializable() + { + $this->shouldHaveType('Kreta\SimpleApiDocBundle\Controller\ApiDocController'); + } + + function it_extends_controller() + { + $this->shouldHaveType('Symfony\Bundle\FrameworkBundle\Controller\Controller'); + } + + function it_index_action( + ContainerInterface $container, + ApiDocExtractor $apiDocExtractor, + HtmlFormatter $htmlFormatter + ) { + $container->get('kreta_simple_api_doc.extractor.api_doc_extractor') + ->shouldBeCalled()->willReturn($apiDocExtractor); + $apiDocExtractor->all()->shouldBeCalled()->willReturn([]); + $container->get('nelmio_api_doc.formatter.html_formatter')->shouldBeCalled()->willReturn($htmlFormatter); + $htmlFormatter->format([])->shouldBeCalled()->willReturn('formatted result'); + + $this->indexAction()->shouldReturnAnInstanceOf('Symfony\Component\HttpFoundation\Response'); + } +} diff --git a/spec/DependencyInjection/Compiler/ExtractorHandlerCompilerPassSpec.php b/spec/DependencyInjection/Compiler/ExtractorHandlerCompilerPassSpec.php new file mode 100644 index 0000000..14a90cf --- /dev/null +++ b/spec/DependencyInjection/Compiler/ExtractorHandlerCompilerPassSpec.php @@ -0,0 +1,64 @@ + + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace spec\Kreta\SimpleApiDocBundle\DependencyInjection\Compiler; + +use PhpSpec\ObjectBehavior; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Reference; + +/** + * Spec of Extractor Handler Compiler Pass class. + * + * @author Beñat Espiña + */ +class ExtractorHandlerCompilerPassSpec extends ObjectBehavior +{ + function it_is_initializable() + { + $this->shouldHaveType('Kreta\SimpleApiDocBundle\DependencyInjection\Compiler\ExtractorHandlerCompilerPass'); + } + + function it_extends_nelmio_extractor_handler_compiler_pass() + { + $this->shouldHaveType('Nelmio\ApiDocBundle\DependencyInjection\ExtractorHandlerCompilerPass'); + } + + function it_implements_compiler_pass_interface() + { + $this->shouldImplement('Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface'); + } + + function it_builds(ContainerBuilder $container, Definition $definition) + { + $container->findTaggedServiceIds('nelmio_api_doc.extractor.handler') + ->shouldBeCalled()->willReturn(['id' => ['attr1', 'attr2']]); + + $container->findTaggedServiceIds('nelmio_api_doc.extractor.annotations_provider') + ->shouldBeCalled()->willReturn(['id' => ['attr1', 'attr2']]); + + $container->getDefinition('kreta_simple_api_doc.extractor.api_doc_extractor') + ->shouldBeCalled()->willReturn($definition); + $definition->replaceArgument( + 5, [new Reference('id')] + )->shouldBeCalled()->willReturn($definition); + + $container->getDefinition('kreta_simple_api_doc.extractor.api_doc_extractor') + ->shouldBeCalled()->willReturn($definition); + $definition->replaceArgument( + 6, [new Reference('id')] + )->shouldBeCalled()->willReturn($definition); + + $this->process($container); + } +} diff --git a/spec/DependencyInjection/ConfigurationSpec.php b/spec/DependencyInjection/ConfigurationSpec.php new file mode 100644 index 0000000..497d674 --- /dev/null +++ b/spec/DependencyInjection/ConfigurationSpec.php @@ -0,0 +1,39 @@ + + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace spec\Kreta\SimpleApiDocBundle\DependencyInjection; + +use PhpSpec\ObjectBehavior; + +/** + * Spec of Configuration class. + * + * @author Beñat Espiña + */ +class ConfigurationSpec extends ObjectBehavior +{ + function it_is_initializable() + { + $this->shouldHaveType('Kreta\SimpleApiDocBundle\DependencyInjection\Configuration'); + } + + function it_implements_configuration_interface() + { + $this->shouldImplement('Symfony\Component\Config\Definition\ConfigurationInterface'); + } + + function it_builds() + { + $this->getConfigTreeBuilder() + ->shouldReturnAnInstanceOf('Symfony\Component\Config\Definition\Builder\TreeBuilder'); + } +} diff --git a/spec/DependencyInjection/KretaSimpleApiDocExtensionSpec.php b/spec/DependencyInjection/KretaSimpleApiDocExtensionSpec.php new file mode 100644 index 0000000..d6d8a76 --- /dev/null +++ b/spec/DependencyInjection/KretaSimpleApiDocExtensionSpec.php @@ -0,0 +1,39 @@ + + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace spec\Kreta\SimpleApiDocBundle\DependencyInjection; + +use PhpSpec\ObjectBehavior; +use Symfony\Component\DependencyInjection\ContainerBuilder; + +/** + * Spec of Kreta Simple Api Doc Extension class. + * + * @author Beñat Espiña + */ +class KretaSimpleApiDocExtensionSpec extends ObjectBehavior +{ + function it_is_initializable() + { + $this->shouldHaveType('Kreta\SimpleApiDocBundle\DependencyInjection\KretaSimpleApiDocExtension'); + } + + function it_extends_extension() + { + $this->shouldHaveType('Symfony\Component\DependencyInjection\Extension\Extension'); + } + + function it_builds(ContainerBuilder $container) + { + $this->load([], $container); + } +} diff --git a/spec/KretaSimpleApiDocBundleSpec.php b/spec/KretaSimpleApiDocBundleSpec.php new file mode 100644 index 0000000..ce79f25 --- /dev/null +++ b/spec/KretaSimpleApiDocBundleSpec.php @@ -0,0 +1,44 @@ + + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace spec\Kreta\SimpleApiDocBundle; + +use PhpSpec\ObjectBehavior; +use Prophecy\Argument; +use Symfony\Component\DependencyInjection\ContainerBuilder; + +/** + * Spec of Kreta Simple Api Doc kernel class. + * + * @author Beñat Espiña + */ +class KretaSimpleApiDocBundleSpec extends ObjectBehavior +{ + function it_is_initializable() + { + $this->shouldHaveType('Kreta\SimpleApiDocBundle\KretaSimpleApiDocBundle'); + } + + function it_extends_bundle() + { + $this->shouldHaveType('Symfony\Component\HttpKernel\Bundle\Bundle'); + } + + function it_builds(ContainerBuilder $container) + { + $container->addCompilerPass( + Argument::type('Kreta\SimpleApiDocBundle\DependencyInjection\Compiler\ExtractorHandlerCompilerPass') + )->shouldBeCalled()->willReturn($container); + + $this->build($container); + } +} diff --git a/Annotation/ApiDoc.php b/src/Annotation/ApiDoc.php similarity index 77% rename from Annotation/ApiDoc.php rename to src/Annotation/ApiDoc.php index 64c82e1..f337df3 100644 --- a/Annotation/ApiDoc.php +++ b/src/Annotation/ApiDoc.php @@ -1,12 +1,13 @@ - * @author gorkalaucirica + * (c) Beñat Espiña + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Kreta\SimpleApiDocBundle\Annotation; @@ -14,9 +15,9 @@ use Nelmio\ApiDocBundle\Annotation\ApiDoc as BaseApiDoc; /** - * Class ApiDoc. + * Api doc class. * - * @package Kreta\SimpleApiDocBundle\Annotation + * @author Beñat Espiña * * @Annotation() */ @@ -33,7 +34,7 @@ class ApiDoc extends BaseApiDoc 204 => '', 403 => 'Not allowed to access this resource', 404 => 'Does not exist any object with id passed', - 409 => 'The resource is currently in use' + 409 => 'The resource is currently in use', ]; /** @@ -43,7 +44,7 @@ class ApiDoc extends BaseApiDoc */ protected $format = [ 'requirement' => 'json|jsonp', - 'description' => 'Supported formats, by default json' + 'description' => 'Supported formats, by default json', ]; /** @@ -63,14 +64,14 @@ public function __construct(array $data) * * @param array $data Array that contains all the data * - * @return $this self Object + * @return self */ protected function buildStatusCodes(array $data) { if (isset($data['statusCodes'])) { $this->initializeStatusCodes(); foreach ($data['statusCodes'] as $key => $element) { - if ((int)$key < 200) { + if ((int) $key < 200) { $this->statusCodes($element); } else { $this->statusCodes($key, $element); @@ -82,12 +83,13 @@ protected function buildStatusCodes(array $data) } /** - * Method that allows to choose between status code passing the code and optional description. + * Method that allows to choose between status + * code passing the code and optional description. * * @param int $statusCode The status code * @param string|null $customDescription The description * - * @return $this self Object + * @return self */ protected function statusCodes($statusCode, $customDescription = null) { @@ -107,10 +109,11 @@ protected function statusCodes($statusCode, $customDescription = null) /** * Purges the statusCodes array to populate with the new way. + * + * This method is required because the $statusCodes + * is a private field, and the reflection is necessary. * - * This method is required because the $statusCodes is a private field, and the reflection is necessary. - * - * @return $this self Object + * @return self */ protected function initializeStatusCodes() { diff --git a/Controller/ApiDocController.php b/src/Controller/ApiDocController.php similarity index 58% rename from Controller/ApiDocController.php rename to src/Controller/ApiDocController.php index d18f2af..94744a5 100644 --- a/Controller/ApiDocController.php +++ b/src/Controller/ApiDocController.php @@ -1,12 +1,13 @@ - * @author gorkalaucirica + * (c) Beñat Espiña + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Kreta\SimpleApiDocBundle\Controller; @@ -15,16 +16,17 @@ use Symfony\Component\HttpFoundation\Response; /** - * Class ApiDocController. + * Api doc controller class. * - * @package Kreta\SimpleApiDocBundle\Controller + * @author Beñat Espiña + * @author Gorka Laucirica */ class ApiDocController extends Controller { /** * The index action. * - * @return \Symfony\Component\HttpFoundation\Response + * @return Response */ public function indexAction() { diff --git a/DependencyInjection/Compiler/ExtractorHandlerCompilerPass.php b/src/DependencyInjection/Compiler/ExtractorHandlerCompilerPass.php similarity index 78% rename from DependencyInjection/Compiler/ExtractorHandlerCompilerPass.php rename to src/DependencyInjection/Compiler/ExtractorHandlerCompilerPass.php index bbec106..ddabb7f 100644 --- a/DependencyInjection/Compiler/ExtractorHandlerCompilerPass.php +++ b/src/DependencyInjection/Compiler/ExtractorHandlerCompilerPass.php @@ -1,25 +1,26 @@ - * @author gorkalaucirica + * (c) Beñat Espiña + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Kreta\SimpleApiDocBundle\DependencyInjection\Compiler; -use Symfony\Component\DependencyInjection\ContainerBuilder; +use Nelmio\ApiDocBundle\DependencyInjection\ExtractorHandlerCompilerPass as BaseExtractorHandlerCompilerPass; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; -use Nelmio\ApiDocBundle\DependencyInjection\ExtractorHandlerCompilerPass as BaseExtractorHandlerCompilerPass; /** - * Class ExtractorHandlerCompilerPass. + * Extractor Handler Compiler Pass. * - * @package Kreta\SimpleApiDocBundle\DependencyInjection\Compiler + * @author Beñat Espiña */ class ExtractorHandlerCompilerPass extends BaseExtractorHandlerCompilerPass implements CompilerPassInterface { diff --git a/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php similarity index 58% rename from DependencyInjection/Configuration.php rename to src/DependencyInjection/Configuration.php index cf12dd6..0fc9eed 100644 --- a/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -1,12 +1,13 @@ - * @author gorkalaucirica + * (c) Beñat Espiña + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Kreta\SimpleApiDocBundle\DependencyInjection; @@ -15,9 +16,9 @@ use Symfony\Component\Config\Definition\ConfigurationInterface; /** - * Class Configuration. + * Configuration class. * - * @package Kreta\SimpleApiDocBundle\DependencyInjection + * @author Beñat Espiña */ class Configuration implements ConfigurationInterface { diff --git a/DependencyInjection/KretaSimpleApiDocExtension.php b/src/DependencyInjection/KretaSimpleApiDocExtension.php similarity index 63% rename from DependencyInjection/KretaSimpleApiDocExtension.php rename to src/DependencyInjection/KretaSimpleApiDocExtension.php index 19bbf0b..95ed527 100644 --- a/DependencyInjection/KretaSimpleApiDocExtension.php +++ b/src/DependencyInjection/KretaSimpleApiDocExtension.php @@ -1,12 +1,13 @@ - * @author gorkalaucirica + * (c) Beñat Espiña + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Kreta\SimpleApiDocBundle\DependencyInjection; @@ -17,9 +18,9 @@ use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; /** - * Class KretaSimpleApiDocExtension. + * Kreta Simple Api Doc Extension class. * - * @package Kreta\SimpleApiDocBundle\DependencyInjection + * @author Beñat Espiña */ class KretaSimpleApiDocExtension extends Extension { @@ -30,7 +31,7 @@ public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $this->processConfiguration($configuration, $configs); - $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yml'); } } diff --git a/Extractor/ApiDocExtractor.php b/src/Extractor/ApiDocExtractor.php similarity index 72% rename from Extractor/ApiDocExtractor.php rename to src/Extractor/ApiDocExtractor.php index b7fad07..f0f85b8 100644 --- a/Extractor/ApiDocExtractor.php +++ b/src/Extractor/ApiDocExtractor.php @@ -1,34 +1,36 @@ - * @author gorkalaucirica + * (c) Beñat Espiña + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Kreta\SimpleApiDocBundle\Extractor; use Doctrine\Common\Annotations\Reader; use Kreta\SimpleApiDocBundle\Parser\ValidationParser; -use ReflectionMethod; +use Nelmio\ApiDocBundle\Annotation\ApiDoc; +use Nelmio\ApiDocBundle\Extractor\ApiDocExtractor as BaseApiDocExtractor; +use Nelmio\ApiDocBundle\Util\DocCommentExtractor; use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Routing\Route; -use Nelmio\ApiDocBundle\Extractor\ApiDocExtractor as BaseApiDocExtractor; -use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Component\Routing\RouterInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Nelmio\ApiDocBundle\Util\DocCommentExtractor; /** - * Class ApiDocExtractor. + * Api Doc Extractor class. * - * @package Kreta\SimpleApiDocBundle\Extractor + * @author Beñat Espiña */ class ApiDocExtractor extends BaseApiDocExtractor { + const ANNOTATION_CLASS = 'Kreta\\SimpleApiDocBundle\\Annotation'; + /** * The validation parser. * @@ -36,19 +38,17 @@ class ApiDocExtractor extends BaseApiDocExtractor */ private $validationParser; - const ANNOTATION_CLASS = 'Kreta\\SimpleApiDocBundle\\Annotation'; - /** * Constructor. * - * @param \Symfony\Component\DependencyInjection\ContainerInterface $container The container - * @param \Symfony\Component\Routing\RouterInterface $router The router - * @param \Doctrine\Common\Annotations\Reader $reader The reader - * @param \Nelmio\ApiDocBundle\Util\DocCommentExtractor $commentExtractor The comment extractor - * @param \Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser $controllerNameParser Controller name parser - * @param array $handlers Array that contains handlers - * @param array $annotationsProviders Annotation providers - * @param \Kreta\SimpleApiDocBundle\Parser\ValidationParser $validationParser The validation parser + * @param ContainerInterface $container The container + * @param RouterInterface $router The router + * @param Reader $reader The reader + * @param DocCommentExtractor $commentExtractor The comment extractor + * @param ControllerNameParser $controllerNameParser Controller name parser + * @param array $handlers Array that contains handlers + * @param array $annotationsProviders Annotation providers + * @param ValidationParser $validationParser The validation parser */ public function __construct( ContainerInterface $container, @@ -59,8 +59,7 @@ public function __construct( array $handlers, array $annotationsProviders, ValidationParser $validationParser - ) - { + ) { parent::__construct( $container, $router, @@ -96,12 +95,13 @@ protected function extractData(ApiDoc $annotation, Route $route, \ReflectionMeth } /** - * Method that adds the input property of ApiDoc getting the form type's fully qualified name. + * Method that adds the input property of ApiDoc + * getting the form type's fully qualified name. * - * @param \Nelmio\ApiDocBundle\Annotation\ApiDoc $annotation The annotation - * @param array|null $data The data given + * @param ApiDoc $annotation The annotation + * @param array|null $data The data given * - * @return \Nelmio\ApiDocBundle\Annotation\ApiDoc + * @return ApiDoc */ public function buildInput(ApiDoc $annotation, $data = null) { @@ -128,12 +128,13 @@ public function buildInput(ApiDoc $annotation, $data = null) } /** - * Method that adds the output property of ApiDoc getting the model's fully qualified name. + * Method that adds the output property of ApiDoc + * getting the model's fully qualified name. * - * @param \Nelmio\ApiDocBundle\Annotation\ApiDoc $annotation The annotation - * @param array|null $data The data given + * @param ApiDoc $annotation The annotation + * @param array|null $data The data given * - * @return \Nelmio\ApiDocBundle\Annotation\ApiDoc + * @return ApiDoc */ public function buildOutput(ApiDoc $annotation, $data = null) { diff --git a/KretaSimpleApiDocBundle.php b/src/KretaSimpleApiDocBundle.php similarity index 59% rename from KretaSimpleApiDocBundle.php rename to src/KretaSimpleApiDocBundle.php index e6f4db2..d0d76fc 100644 --- a/KretaSimpleApiDocBundle.php +++ b/src/KretaSimpleApiDocBundle.php @@ -1,12 +1,13 @@ - * @author gorkalaucirica + * (c) Beñat Espiña + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Kreta\SimpleApiDocBundle; @@ -16,9 +17,9 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; /** - * Class KretaSimpleApiDocBundle. + * Simple ApiDoc Bundle kernel class. * - * @package Kreta\SimpleApiDocBundle + * @author Beñat Espiña */ class KretaSimpleApiDocBundle extends Bundle { diff --git a/Parser/ValidationParser.php b/src/Parser/ValidationParser.php similarity index 80% rename from Parser/ValidationParser.php rename to src/Parser/ValidationParser.php index 4d60316..d540810 100644 --- a/Parser/ValidationParser.php +++ b/src/Parser/ValidationParser.php @@ -1,12 +1,13 @@ - * @author gorkalaucirica + * (c) Beñat Espiña + * (c) Gorka Laucirica + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. */ namespace Kreta\SimpleApiDocBundle\Parser; @@ -19,9 +20,9 @@ use Symfony\Component\Validator\ValidatorInterface; /** - * Class ValidationParser. + * Validation parser class. * - * @package Kreta\SimpleApiDocBundle\Parser + * @author Beñat Espiña */ class ValidationParser extends BaseValidationParser { @@ -35,8 +36,8 @@ class ValidationParser extends BaseValidationParser /** * Constructor. * - * @param MetadataFactoryInterface $factory The metadata factory - * @param \Symfony\Component\Validator\ValidatorInterface $validator The Symfony validator component + * @param MetadataFactoryInterface $factory The metadata factory + * @param ValidatorInterface $validator The Symfony validator component */ public function __construct(MetadataFactoryInterface $factory, ValidatorInterface $validator) { @@ -44,6 +45,13 @@ public function __construct(MetadataFactoryInterface $factory, ValidatorInterfac $this->validator = $validator; } + /** + * Gets the validations. + * + * @param string|null $class The class namespace + * + * @return array + */ public function getValidations($class = null) { $reflectionClass = $class ? new \ReflectionClass($class) : false; @@ -71,6 +79,13 @@ public function getValidations($class = null) return $validations; } + /** + * Parses and builds the validation. + * + * @param string|null $class The class namespace + * + * @return array + */ protected function buildValidation($class = null) { $validations = []; @@ -79,7 +94,7 @@ protected function buildValidation($class = null) foreach ($metadata->getConstraints() as $constraint) { $class = new \ReflectionClass($constraint); $fields = $constraint->fields; - $entityConstraint = [implode(', ', (array)$fields) => $constraint->message]; + $entityConstraint = [implode(', ', (array) $fields) => $constraint->message]; $entityConstraints = array_merge($entityConstraints, $entityConstraint); $validations[$class->getShortName()] = $entityConstraint; } @@ -113,6 +128,13 @@ protected function buildValidation($class = null) return $validations; } + /** + * Parses the constraint message. + * + * @param \Symfony\Component\Validator\Constraint $constraint The constraint + * + * @return array + */ protected function constraintMessages(Constraint $constraint) { $result = []; diff --git a/src/Resources/config/routing.yml b/src/Resources/config/routing.yml new file mode 100644 index 0000000..72a60ec --- /dev/null +++ b/src/Resources/config/routing.yml @@ -0,0 +1,12 @@ +# This file is part of the Kreta package. +# +# (c) Beñat Espiña +# (c) Gorka Laucirica +# +# For the full copyright and license information, please view the LICENSE +# file that was distributed with this source code. + +nelmio_api_doc_index: + pattern: / + defaults: { _controller: KretaSimpleApiDocBundle:ApiDoc:index } + methods: [GET] diff --git a/Resources/config/services.yml b/src/Resources/config/services.yml similarity index 77% rename from Resources/config/services.yml rename to src/Resources/config/services.yml index bc1726f..e0395bf 100644 --- a/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -1,9 +1,10 @@ -# This file belongs to Kreta. -# The source code of application includes a LICENSE file -# with all information about license. +# This file is part of the Kreta package. # -# @author benatespina -# @author gorkalaucirica +# (c) Beñat Espiña +# (c) Gorka Laucirica +# +# For the full copyright and license information, please view the LICENSE +# file that was distributed with this source code. parameters: kreta_simple_api_doc.extractor.api_doc_extractor.class: Kreta\SimpleApiDocBundle\Extractor\ApiDocExtractor