From 5650e4b85dd799100956823ee886b5f6b4a62dc0 Mon Sep 17 00:00:00 2001 From: JMSBot Date: Mon, 1 Oct 2012 15:01:48 +0200 Subject: [PATCH] changes from automatic review --- Controller/ResourceController.php | 3 ++ Model/Representation/Entity.php | 8 ++++++ Normalizer/FormNormalizer.php | 16 +++++++---- REST/AbstractDoctrineResource.php | 3 +- REST/AbstractResource.php | 28 +++++++++++++++++++ REST/AtomLinkFactory.php | 11 ++++++++ REST/Description/FormDescription.php | 6 ++++ Routing/RouteNameProvider.php | 16 +++++++++++ Routing/RouteNameProviderInterface.php | 18 ++++++++++++ Routing/UrlGenerator.php | 9 ++++++ Routing/UrlGeneratorInterface.php | 18 ++++++++++++ Tests/Functional/AppKernel.php | 1 - .../Normalizer/FormNormalizerTest.php | 1 - Tests/Functional/SerializationTestCase.php | 8 ++++++ .../Serializer/FormNormalizerTest.php | 1 - Tests/Functional/TestCase.php | 3 ++ 16 files changed, 140 insertions(+), 10 deletions(-) diff --git a/Controller/ResourceController.php b/Controller/ResourceController.php index c76ba37..3d435e3 100644 --- a/Controller/ResourceController.php +++ b/Controller/ResourceController.php @@ -103,6 +103,9 @@ protected function getRelFromCollectionFormRoute(Request $request) return $matches[1]; } + /** + * @return \FSC\RestBundle\REST\Description\FormDescription|\Pagerfanta\Pagerfanta|integer|string|null|Request + */ protected function getRelFromEntityCollectionRoute(Request $request) { $route = $request->attributes->get('_route'); diff --git a/Model/Representation/Entity.php b/Model/Representation/Entity.php index 1d7eaf0..83c72ba 100644 --- a/Model/Representation/Entity.php +++ b/Model/Representation/Entity.php @@ -51,11 +51,19 @@ public function addRelation(Entity $entity) $this->relations[$entity->rel] = $entity; } + /** + * @param string $key + * @param string $value + */ public function setElement($key, $value) { $this->elements[$key] = $value; } + /** + * @param string $key + * @param string $value + */ public function setAttribute($key, $value) { $this->attributes[$key] = $value; diff --git a/Normalizer/FormNormalizer.php b/Normalizer/FormNormalizer.php index 922551a..4b76931 100644 --- a/Normalizer/FormNormalizer.php +++ b/Normalizer/FormNormalizer.php @@ -30,6 +30,7 @@ public function __construct(AtomLinkFactory $atomLinkFactory = null) /** * {@inheritdoc} + * @param \Symfony\Component\Form\FormInterface $object */ public function normalize($object, $format = null) { @@ -102,6 +103,9 @@ protected function mergeFormElementsArrays($formElements) return $this->mergeFormElementsArrays($formElements); } + /** + * @param string|null $blockName + */ protected function renderBlock(FormView $view, $blockName = null, array $variables = array()) { $variables = $view->getVars(); @@ -148,8 +152,7 @@ protected function renderBlock(FormView $view, $blockName = null, array $variabl /* {% if compound %} {{ block('form_widget_compound') }} - {% else %} - {{ block('form_widget_simple') }} + {% else { %}{ block('form_widget_simple') }} {% endif %} */ protected function renderFormWidget(FormView $view, $blockName, array $variables = array()) @@ -358,8 +361,7 @@ protected function renderCollectionWidget(FormView $view, $blockName, array $var /* {% if expanded %} {{ block('choice_widget_expanded') }} - {% else %} - {{ block('choice_widget_collapsed') }} + {% else { %}{ block('choice_widget_collapsed') }} {% endif %} */ protected function renderChoiceWidget(FormView $view, $blockName, array $variables = array()) @@ -507,11 +509,13 @@ protected function renderFormRows(FormView $view, $blockName, array $variables = {% for attrname, attrvalue in attr %} {% if attrname in ['placeholder', 'title'] %} {{ attrname }}="{{ attrvalue|trans({}, translation_domain) }}" - {% else %} - {{ attrname }}="{{ attrvalue }}" + {% else { %}{ attrname }}="{{ attrvalue }}" {% endif %} {% endfor %} */ + /** + * @param FormRepresentations\Input|FormRepresentations\Textarea|FormRepresentations\Select $widget + */ protected function addWidgetAttributes($widget, FormView $view, $blockName, array $variables = array()) { $widget->attributes['name'] = $variables['full_name']; diff --git a/REST/AbstractDoctrineResource.php b/REST/AbstractDoctrineResource.php index a0bb282..d4e0e84 100644 --- a/REST/AbstractDoctrineResource.php +++ b/REST/AbstractDoctrineResource.php @@ -75,7 +75,8 @@ protected function getRepository() /** * @param QueryBuilder|Query $query - * @param Collection $collection + * @param null|Collection $collection + * @param boolean $fetchJoinCollection * * @return Pagerfanta */ diff --git a/REST/AbstractResource.php b/REST/AbstractResource.php index 44c5645..77dfea9 100644 --- a/REST/AbstractResource.php +++ b/REST/AbstractResource.php @@ -305,6 +305,9 @@ public function guessRouteNamePrefix() return sprintf('%s_rest_%s', $routeName, $this->guessResourceName()); } + /** + * @param boolean $doNotExpandRelationsAndCollections + */ public function normalizeEntity($entity, $doNotExpandRelationsAndCollections = false) { // Make sure that the used is authorized to see this resource @@ -410,6 +413,9 @@ public function normalizeCollection(Pagerfanta $pager, FormDescription $formDesc return $collectionRepresentation; } + /** + * @param integer|string $rel + */ public function normalizeEntityCollection($entity, $rel, Pagerfanta $pager, FormDescription $formDescription) { $configurationEntityCollection = $this->getConfigurationEntityCollections()[$rel]; @@ -503,6 +509,9 @@ public function createCollectionSearchFormDescription(Request $request = null) return new FormDescription($rel, $method, $actionUrl, $form, $formData, $selfUrl); } + /** + * @return FormDescription + */ public function createEntityCollectionFormDescription($rel, $entity, $collectionRel, Request $request = null) { if ('search' == $rel) { @@ -512,6 +521,9 @@ public function createEntityCollectionFormDescription($rel, $entity, $collection throw new \Exception('Not implemented, sorry!'); } + /** + * @param integer|string $collectionRel + */ public function createEntityCollectionSearchFormDescription($entity, $collectionRel, Request $request = null) { $createForm = $this->getConfigurationCollectionSearch()['create_form']; @@ -542,10 +554,26 @@ public function getEntityCollectionRelFromRouteRel($routeRel) } } + /** + * @return FormDescription|Pagerfanta|integer|string|null|Request + */ abstract public function getEntity(Request $request); + /** + * @return FormDescription|Pagerfanta + */ abstract public function getCollectionPager(Collection $search); + /** + * @param integer|string $rel + * + * @return FormDescription|Pagerfanta|integer|string + */ abstract public function getEntityCollectionPager($entity, Collection $search, $rel); + /** + * @param integer|string $entityRelationRel + * + * @return object|null + */ public function getEntityRelation($entity, $entityRelationRel) { $getRelation = $this->getConfigurationEntityRelations()[$entityRelationRel]['get_relation']; diff --git a/REST/AtomLinkFactory.php b/REST/AtomLinkFactory.php index d86be7f..dfb0f66 100644 --- a/REST/AtomLinkFactory.php +++ b/REST/AtomLinkFactory.php @@ -31,6 +31,12 @@ public function __construct($relPrefix = '') $this->relPrefix = $relPrefix; } + /** + * @param string|integer $rel + * @param string $href + * + * @return AtomLink + */ public function create($rel, $href, $type = null) { return AtomLink::create($this->getRel($rel), $href, $type); @@ -41,6 +47,11 @@ public static function getIanaRelations() return static::$ianaRelations; } + /** + * @param integer|string $rel + * + * @return string + */ public function getRel($rel) { if (!in_array($rel, static::$ianaRelations)) { diff --git a/REST/Description/FormDescription.php b/REST/Description/FormDescription.php index 463ffda..751e55e 100644 --- a/REST/Description/FormDescription.php +++ b/REST/Description/FormDescription.php @@ -43,11 +43,17 @@ public function getForm() return $this->form; } + /** + * @return \FSC\RestBundle\Form\Model\Collection + */ public function getData() { return $this->data; } + /** + * @return string + */ public function getSelfUrl() { return $this->selfUrl; diff --git a/Routing/RouteNameProvider.php b/Routing/RouteNameProvider.php index 9d97820..5f2193f 100644 --- a/Routing/RouteNameProvider.php +++ b/Routing/RouteNameProvider.php @@ -16,6 +16,9 @@ public function getCollectionRouteName() return $this->resourceBaseRoute.'_collection'; } + /** + * @param string $formRel + */ public function getCollectionFormRouteName($formRel) { return $this->resourceBaseRoute.'_collection_form_'.$this->normalizeRel($formRel); @@ -26,21 +29,34 @@ public function getEntityRouteName() return $this->resourceBaseRoute.'_entity'; } + /** + * @param string $formRel + */ public function getEntityFormRouteName($formRel) { return $this->resourceBaseRoute.'_entity_form_'.$this->normalizeRel($formRel); } + /** + * @param string $collectionRel + */ public function getEntityCollectionRouteName($collectionRel) { return $this->resourceBaseRoute.'_entity_collection_'.$this->normalizeRel($collectionRel); } + /** + * @param string $collectionRel + * @param string $formRel + */ public function getEntityCollectionFormRouteName($collectionRel, $formRel) { return $this->resourceBaseRoute.'_entity_collection_'.$this->normalizeRel($collectionRel).'_form_'.$this->normalizeRel($formRel); } + /** + * @param integer|string $rel + */ public static function normalizeRel($rel) { return preg_replace('/[^0-9a-zA-Z_.]+/', '', $rel); diff --git a/Routing/RouteNameProviderInterface.php b/Routing/RouteNameProviderInterface.php index 5d51e8a..babcd5d 100644 --- a/Routing/RouteNameProviderInterface.php +++ b/Routing/RouteNameProviderInterface.php @@ -4,10 +4,28 @@ interface RouteNameProviderInterface { + /** + * @return string + */ public function getCollectionRouteName(); + /** + * @return string + */ public function getCollectionFormRouteName($formRel); + /** + * @return string + */ public function getEntityRouteName(); + /** + * @return string + */ public function getEntityFormRouteName($formRel); + /** + * @return string + */ public function getEntityCollectionRouteName($collectionRel); + /** + * @return string + */ public function getEntityCollectionFormRouteName($collectionRel, $formRel); } diff --git a/Routing/UrlGenerator.php b/Routing/UrlGenerator.php index aa9f271..4ef9fe6 100644 --- a/Routing/UrlGenerator.php +++ b/Routing/UrlGenerator.php @@ -22,6 +22,7 @@ public function __construct(SFUrlGeneratorInterface $urlGenerator, RouteNameProv /** * {@inheritdoc} + * @param array $parameters */ public function generateCollectionUrl($parameters = array()) { @@ -32,6 +33,8 @@ public function generateCollectionUrl($parameters = array()) /** * {@inheritdoc} + * @param string $formRel + * @param array $parameters */ public function generateCollectionFormUrl($formRel, $parameters = array()) { @@ -42,6 +45,7 @@ public function generateCollectionFormUrl($formRel, $parameters = array()) /** * {@inheritdoc} + * @param array $parameters */ public function generateEntityUrl($entity, $parameters = array()) { @@ -53,6 +57,7 @@ public function generateEntityUrl($entity, $parameters = array()) /** * {@inheritdoc} + * @param array $parameters */ public function generateEntityFormUrl($entity, $formRel, $parameters = array()) { @@ -64,6 +69,8 @@ public function generateEntityFormUrl($entity, $formRel, $parameters = array()) /** * {@inheritdoc} + * @param integer|string $collectionRel + * @param array $parameters */ public function generateEntityCollectionUrl($entity, $collectionRel, $parameters = array()) { @@ -75,6 +82,8 @@ public function generateEntityCollectionUrl($entity, $collectionRel, $parameters /** * {@inheritdoc} + * @param string $formRel + * @param array $parameters */ public function generateEntityCollectionFormUrl($entity, $collectionRel, $formRel, $parameters = array()) { diff --git a/Routing/UrlGeneratorInterface.php b/Routing/UrlGeneratorInterface.php index 3a3ff1f..e40a369 100644 --- a/Routing/UrlGeneratorInterface.php +++ b/Routing/UrlGeneratorInterface.php @@ -4,10 +4,28 @@ interface UrlGeneratorInterface { + /** + * @return string + */ public function generateCollectionUrl($parameters = array()); + /** + * @return string + */ public function generateCollectionFormUrl($formRel, $parameters = array()); + /** + * @return string + */ public function generateEntityUrl($entity, $parameters = array()); + /** + * @return string + */ public function generateEntityFormUrl($entity, $formRel, $parameters = array()); + /** + * @return string + */ public function generateEntityCollectionUrl($entity, $collectionRel, $parameters = array()); + /** + * @return string + */ public function generateEntityCollectionFormUrl($entity, $collectionRel, $formRel, $parameters = array()); } diff --git a/Tests/Functional/AppKernel.php b/Tests/Functional/AppKernel.php index a6125ff..7d6f61c 100644 --- a/Tests/Functional/AppKernel.php +++ b/Tests/Functional/AppKernel.php @@ -2,7 +2,6 @@ namespace FSC\RestBundle\Tests\Functional; -use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\HttpKernel\Kernel; diff --git a/Tests/Functional/Normalizer/FormNormalizerTest.php b/Tests/Functional/Normalizer/FormNormalizerTest.php index b8b3996..83199eb 100644 --- a/Tests/Functional/Normalizer/FormNormalizerTest.php +++ b/Tests/Functional/Normalizer/FormNormalizerTest.php @@ -3,7 +3,6 @@ namespace FSC\RestBundle\Tests\Functional\Normalizer; use FSC\RestBundle\Tests\Functional\TestCase; -use FSC\RestBundle\Form\RestRendererEngine; class FormNormalizerTest extends TestCase { diff --git a/Tests/Functional/SerializationTestCase.php b/Tests/Functional/SerializationTestCase.php index c5ba91a..9813fac 100644 --- a/Tests/Functional/SerializationTestCase.php +++ b/Tests/Functional/SerializationTestCase.php @@ -4,6 +4,10 @@ abstract class SerializationTestCase extends TestCase { + /** + * @param string $expectedXml + * @param \FSC\RestBundle\Model\Representation\Form\Form|\FSC\RestBundle\Model\Representation\AtomLink|\FSC\RestBundle\Model\Representation\Common\Measure|\FSC\RestBundle\Model\Representation\Resource $value + */ protected function assertSerializedXmlEquals($expectedXml, $value) { $serializedValue = $this->get('serializer')->serialize($value, 'xml'); @@ -11,6 +15,10 @@ protected function assertSerializedXmlEquals($expectedXml, $value) $this->assertEquals(sprintf('%s%s%s', "\n", $expectedXml, "\n"), $serializedValue); } + /** + * @param string $expectedSerializedValue + * @param \FSC\RestBundle\Model\Representation\Resource $value + */ protected function assertSerializedJsonEquals($expectedSerializedValue, $value) { $serializedValue = $this->get('serializer')->serialize($value, 'json'); diff --git a/Tests/Functional/Serializer/FormNormalizerTest.php b/Tests/Functional/Serializer/FormNormalizerTest.php index 90ff745..999bd51 100644 --- a/Tests/Functional/Serializer/FormNormalizerTest.php +++ b/Tests/Functional/Serializer/FormNormalizerTest.php @@ -3,7 +3,6 @@ namespace FSC\RestBundle\Tests\Functional\Serializer; use FSC\RestBundle\Tests\Functional\SerializationTestCase; -use Symfony\Component\Serializer\Serializer as SymfonySerializer; use FSC\RestBundle\Normalizer\FormNormalizer; diff --git a/Tests/Functional/TestCase.php b/Tests/Functional/TestCase.php index 2cc567d..8b01bd5 100644 --- a/Tests/Functional/TestCase.php +++ b/Tests/Functional/TestCase.php @@ -17,6 +17,9 @@ public function setUp() static::$kernel->boot(); } + /** + * @param string $name + */ public function get($name) { return static::$kernel->getContainer()->get($name);