浏览代码

Applied fixes from StyleCI (#3953)

Sonata CI 9 年之前
父节点
当前提交
ab06bf85c4

+ 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;
     }
 }