瀏覽代碼

Merge pull request #3952 from sonata-project/3.x-dev-kit

DevKit updates for 3.x branch
Sonata CI 9 年之前
父節點
當前提交
c5d657c08e

+ 30 - 10
.github/ISSUE_TEMPLATE.md

@@ -8,20 +8,40 @@
     Otherwise remove it.
 -->
 
-| Question       | Answer
-|----------------|-------------------------------
-| Bundle version | composer show sonata-project/*
-| Symfony version| composer show symfony/*
-| php version    | php --version
+### Environment
 
-# Error message
+#### Sonata packages
 
+```bash
+$ composer show sonata-project/*
+# Put the result here.
 ```
-Error message goes here
+
+#### Symfony packages
+
+```bash
+$ composer show symfony/*
+# Put the result here.
+```
+
+#### PHP version
+
+```bash
+$ php -v
+# Put the result here.
 ```
 
-# Steps to reproduce
+## Subject
+
+<!--
+    Give here as many details as possible.
+    Next sections are for ERRORS only.
+-->
+
+## Steps to reproduce
+
+## Expected results
 
-# Expected results
+## Actual results
 
-# Actual results
+<!-- If it's an error message or piece of code, use code block tags. -->

+ 19 - 10
.github/PULL_REQUEST_TEMPLATE.md

@@ -1,20 +1,30 @@
 <!-- THE PR TEMPLATE IS NOT AN OPTION. DO NOT DELETE IT! -->
 
+<!--
+    Show us you choose the right branch.
+    Different branches are used for different things :
+    - 3.x is for everything backwards compatible, like patches, features and deprecation notices
+    - master is for deprecation removals and other changes that cannot be done without a BC-break
+    More details here: https://github.com/sonata-project/SonataAdminBundle/blob/3.x/CONTRIBUTING.md#the-base-branch
+-->
+I am targetting this branch, because…
+
 <!--
     Specify which issues will be fixed/closed.
     Remove it if this is not related.
 -->
 
 Closes #
+Fixes #
 
-### Changelog
+## Changelog
 
 <!-- MANDATORY
     Fill the changelog part inside the code block.
-    Remove unneeded sections.
     Follow this schema: http://keepachangelog.com/
 -->
 
+<!-- REMOVE EMPTY SECTIONS -->
 ```markdown
 ### Added
 - Added some `Class::newMethod` to do great stuff
@@ -30,19 +40,18 @@ Closes #
 ### Security
 ```
 
-### Subject
-
-<!-- Describe your Pull Request content here -->
-
-### To do
+## To do
 
 <!--
-    Complete the tasks.
+    If this is a work in progress, COMPLETE and ADD needed tasks.
     You can add as many tasks as you want.
-    If some are not relevant, just remove them.
+    If some are not relevant, just REMOVE them.
 -->
 
-- [ ] My PR stuff
 - [ ] Update the tests
 - [ ] Update the documentation
 - [ ] Add an upgrade note
+
+## Subject
+
+<!-- Describe your Pull Request content here -->

+ 4 - 1
.styleci.yml

@@ -7,10 +7,13 @@
 preset: symfony
 
 enabled:
+  - combine_consecutive_unsets
+  - long_array_syntax
   - newline_after_open_tag
+  - no_php4_constructor
+  - no_useless_else
   - ordered_class_elements
   - ordered_use
-  - long_array_syntax
 # Comment strict rules for the moment. Should be uncomment later to see StyleCI PR results
 #  - strict
 #  - strict_param

+ 2 - 2
Admin/AdminHelper.php

@@ -293,9 +293,9 @@ class AdminHelper
         $associationAdmin = $admin->getFormFieldDescription($element)->getAssociationAdmin();
         if (count($elements) == 0) {
             return $associationAdmin->getClass();
-        } else {
-            return $this->getEntityClassName($associationAdmin, $elements);
         }
+
+        return $this->getEntityClassName($associationAdmin, $elements);
     }
 
     /**

+ 2 - 2
Controller/CRUDController.php

@@ -1019,9 +1019,9 @@ class CRUDController extends Controller
     {
         if ($this->container->has('logger')) {
             return $this->container->get('logger');
-        } else {
-            return new NullLogger();
         }
+
+        return new NullLogger();
     }
 
     /**

+ 1 - 2
Controller/HelperController.php

@@ -213,9 +213,8 @@ class HelperController
                 'object' => $object,
                 'link_parameters' => $linkParameters,
             )));
-        } else {
-            throw new \RuntimeException('Invalid format');
         }
+        throw new \RuntimeException('Invalid format');
     }
 
     /**

+ 11 - 12
Datagrid/Pager.php

@@ -227,9 +227,9 @@ abstract class Pager implements \Iterator, \Countable, \Serializable, PagerInter
     {
         if ($this->cursor + 1 > $this->nbResults) {
             return;
-        } else {
-            return $this->retrieveObject($this->cursor + 1);
         }
+
+        return $this->retrieveObject($this->cursor + 1);
     }
 
     /**
@@ -241,9 +241,9 @@ abstract class Pager implements \Iterator, \Countable, \Serializable, PagerInter
     {
         if ($this->cursor - 1 < 1) {
             return;
-        } else {
-            return $this->retrieveObject($this->cursor - 1);
         }
+
+        return $this->retrieveObject($this->cursor - 1);
     }
 
     /**
@@ -255,9 +255,9 @@ abstract class Pager implements \Iterator, \Countable, \Serializable, PagerInter
     {
         if ($this->page == 0) {
             return 1;
-        } else {
-            return ($this->page - 1) * $this->maxPerPage + 1;
         }
+
+        return ($this->page - 1) * $this->maxPerPage + 1;
     }
 
     /**
@@ -269,13 +269,12 @@ abstract class Pager implements \Iterator, \Countable, \Serializable, PagerInter
     {
         if ($this->page == 0) {
             return $this->nbResults;
-        } else {
-            if ($this->page * $this->maxPerPage >= $this->nbResults) {
-                return $this->nbResults;
-            } else {
-                return $this->page * $this->maxPerPage;
-            }
         }
+        if ($this->page * $this->maxPerPage >= $this->nbResults) {
+            return $this->nbResults;
+        }
+
+        return $this->page * $this->maxPerPage;
     }
 
     /**

+ 4 - 6
DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php

@@ -105,9 +105,8 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
                 if (isset($groupDefaults[$resolvedGroupName]['on_top']) && $groupDefaults[$resolvedGroupName]['on_top']
                     || $onTop && (count($groupDefaults[$resolvedGroupName]['items']) > 1)) {
                     throw new \RuntimeException('You can\'t use "on_top" option with multiple same name groups.');
-                } else {
-                    $groupDefaults[$resolvedGroupName]['on_top'] = $onTop;
                 }
+                $groupDefaults[$resolvedGroupName]['on_top'] = $onTop;
             }
         }
 
@@ -153,10 +152,9 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
                 if (isset($groups[$resolvedGroupName]['on_top']) && !empty($group['on_top']) && $group['on_top']
                     && (count($groups[$resolvedGroupName]['items']) > 1)) {
                     throw new \RuntimeException('You can\'t use "on_top" option with multiple same name groups.');
-                } else {
-                    if (empty($group['on_top'])) {
-                        $groups[$resolvedGroupName]['on_top'] = $groupDefaults[$resolvedGroupName]['on_top'];
-                    }
+                }
+                if (empty($group['on_top'])) {
+                    $groups[$resolvedGroupName]['on_top'] = $groupDefaults[$resolvedGroupName]['on_top'];
                 }
             }
         } elseif ($container->getParameter('sonata.admin.configuration.sort_admins')) {

+ 1 - 2
Mapper/BaseGroupedMapper.php

@@ -84,9 +84,8 @@ abstract class BaseGroupedMapper extends BaseMapper
             if ($this->currentTab) {
                 if (isset($tabs[$this->currentTab]['auto_created']) && true === $tabs[$this->currentTab]['auto_created']) {
                     throw new \RuntimeException('New tab was added automatically when you have added field or group. You should close current tab before adding new one OR add tabs before adding groups and fields.');
-                } else {
-                    throw new \RuntimeException(sprintf('You should close previous tab "%s" with end() before adding new tab "%s".', $this->currentTab, $name));
                 }
+                throw new \RuntimeException(sprintf('You should close previous tab "%s" with end() before adding new tab "%s".', $this->currentTab, $name));
             } elseif ($this->currentGroup) {
                 throw new \RuntimeException(sprintf('You should open tab before adding new group "%s".', $name));
             }

+ 3 - 3
Tests/Form/Widget/FilterChoiceWidgetTest.php

@@ -94,10 +94,10 @@ class FilterChoiceWidgetTest extends BaseWidgetTest
             return array(
                 'placeholder' => 'Choose an option',
             );
-        } else {
-            return array(
+        }
+
+        return array(
                 'empty_value' => 'Choose an option',
             );
-        }
     }
 }

+ 3 - 3
Tests/Form/Widget/FormChoiceWidgetTest.php

@@ -118,10 +118,10 @@ class FormChoiceWidgetTest extends BaseWidgetTest
             return array(
                 'placeholder' => 'Choose an option',
             );
-        } else {
-            return array(
+        }
+
+        return array(
                 'empty_value' => 'Choose an option',
             );
-        }
     }
 }

+ 4 - 4
Tests/Form/Widget/FormSonataFilterChoiceWidgetTest.php

@@ -65,18 +65,18 @@ class FormSonataFilterChoiceWidgetTest extends BaseWidgetTest
     {
         if (class_exists('Symfony\Component\Form\Extension\Core\Type\RangeType')) {
             return 'Sonata\AdminBundle\Form\Type\Filter\ChoiceType';
-        } else {
-            return 'sonata_type_filter_choice';
         }
+
+        return 'sonata_type_filter_choice';
     }
 
     protected function getChoiceClass()
     {
         if (class_exists('Symfony\Component\Form\Extension\Core\Type\RangeType')) {
             return 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
-        } else {
-            return 'choice';
         }
+
+        return 'choice';
     }
 
     protected function getExtensions()

+ 3 - 4
Tests/Show/ShowMapperTest.php

@@ -125,11 +125,10 @@ class ShowMapperTest extends \PHPUnit_Framework_TestCase
             ->will($this->returnCallback(function ($name) use (&$listShowFields) {
                 if (isset($listShowFields[$name])) {
                     return true;
-                } else {
-                    $listShowFields[$name] = true;
-
-                    return false;
                 }
+                $listShowFields[$name] = true;
+
+                return false;
             }));
 
         $this->showBuilder->expects($this->any())

+ 2 - 2
Util/AdminAclManipulator.php

@@ -113,8 +113,8 @@ class AdminAclManipulator implements AdminAclManipulatorInterface
             }
 
             return true;
-        } else {
-            return false;
         }
+
+        return false;
     }
 }