From a1ab9d50c758d6b7858980d056c8bde63413ed51 Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sun, 6 Dec 2015 02:39:07 +0200 Subject: [PATCH 01/12] clear code --- .../EntityBundle/Provider/AbstractChainProvider.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Oro/Bundle/EntityBundle/Provider/AbstractChainProvider.php b/src/Oro/Bundle/EntityBundle/Provider/AbstractChainProvider.php index 49b7de6d41a..bc2589cd307 100644 --- a/src/Oro/Bundle/EntityBundle/Provider/AbstractChainProvider.php +++ b/src/Oro/Bundle/EntityBundle/Provider/AbstractChainProvider.php @@ -36,11 +36,9 @@ protected function getProviders() if (null === $this->sorted) { ksort($this->providers); - if (empty($this->providers)) { - $this->sorted = []; - } else { - $this->sorted = call_user_func_array('array_merge', $this->providers); - } + $this->sorted = $this->providers + ? call_user_func_array('array_merge', $this->providers) + : []; } return $this->sorted; From 9974fe910b27db05ae6dce742683c15c80519da8 Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sun, 6 Dec 2015 02:48:37 +0200 Subject: [PATCH 02/12] clear code --- src/Oro/Bundle/UserBundle/Entity/AbstractRole.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Oro/Bundle/UserBundle/Entity/AbstractRole.php b/src/Oro/Bundle/UserBundle/Entity/AbstractRole.php index 6a75577e5d3..516de5d658d 100644 --- a/src/Oro/Bundle/UserBundle/Entity/AbstractRole.php +++ b/src/Oro/Bundle/UserBundle/Entity/AbstractRole.php @@ -25,11 +25,9 @@ abstract public function getPrefix(); */ public function setRole($role, $generateUnique = true) { - if ($generateUnique) { - $this->role = $this->generateUniqueRole($role); - } else { - $this->role = $this->addPrefix($this->normalize($role)); - } + $this->role = $generateUnique + ? $this->generateUniqueRole($role) + : $this->addPrefix($this->normalize($role)); return $this; } From 9ef3ff7ae0ab1170838acea0b4fe2848f6d0cf84 Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sun, 6 Dec 2015 02:55:00 +0200 Subject: [PATCH 03/12] clear code --- src/Oro/Bundle/UserBundle/Entity/Group.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Oro/Bundle/UserBundle/Entity/Group.php b/src/Oro/Bundle/UserBundle/Entity/Group.php index d49d067a01c..23b10c7343c 100644 --- a/src/Oro/Bundle/UserBundle/Entity/Group.php +++ b/src/Oro/Bundle/UserBundle/Entity/Group.php @@ -243,11 +243,7 @@ public function removeRole($role) public function setRoles($roles) { if ($roles instanceof Collection) { - $this->roles->clear(); - - foreach ($roles as $role) { - $this->addRole($role); - } + $this->roles = new ArrayCollection($roles->toArray()); } elseif (is_array($roles)) { $this->roles = new ArrayCollection($roles); } else { From 87880164600bbee65af841755356fb6a2ebc04f8 Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sun, 6 Dec 2015 03:01:53 +0200 Subject: [PATCH 04/12] clear code --- .../Api/Rest/CalendarConnectionController.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Oro/Bundle/CalendarBundle/Controller/Api/Rest/CalendarConnectionController.php b/src/Oro/Bundle/CalendarBundle/Controller/Api/Rest/CalendarConnectionController.php index 65c5b9c383b..1b251e4d4ec 100644 --- a/src/Oro/Bundle/CalendarBundle/Controller/Api/Rest/CalendarConnectionController.php +++ b/src/Oro/Bundle/CalendarBundle/Controller/Api/Rest/CalendarConnectionController.php @@ -138,11 +138,13 @@ protected function fixFormData(array &$data, $entity) { parent::fixFormData($data, $entity); - unset($data['calendarName']); - unset($data['removable']); - unset($data['canAddEvent']); - unset($data['canEditEvent']); - unset($data['canDeleteEvent']); + unset( + $data['calendarName'], + $data['removable'], + $data['canAddEvent'], + $data['canEditEvent'], + $data['canDeleteEvent'] + ); return true; } From 9e07b7e54f7d36869d55e7765eb8448d71154b8c Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sun, 6 Dec 2015 03:11:46 +0200 Subject: [PATCH 05/12] clear code --- .../Bundle/CalendarBundle/Provider/CalendarPropertyProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Oro/Bundle/CalendarBundle/Provider/CalendarPropertyProvider.php b/src/Oro/Bundle/CalendarBundle/Provider/CalendarPropertyProvider.php index 7c17251ec04..6dd8ae65240 100644 --- a/src/Oro/Bundle/CalendarBundle/Provider/CalendarPropertyProvider.php +++ b/src/Oro/Bundle/CalendarBundle/Provider/CalendarPropertyProvider.php @@ -91,7 +91,7 @@ public function getItems($calendarId) $result = $qb->getQuery()->getArrayResult(); // normalize integer foreign keys due Doctrine IDENTITY function always returns a string - if (!empty($intCasts)) { + if ($intCasts) { foreach ($result as &$item) { foreach ($intCasts as $fieldName) { if (isset($item[$fieldName]) && is_string($item[$fieldName])) { From 2ad636d15925a8ee65ccbae4bb2214a3cfa7711e Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sun, 6 Dec 2015 03:13:51 +0200 Subject: [PATCH 06/12] clear code --- .../CalendarBundle/Provider/PublicCalendarProvider.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Oro/Bundle/CalendarBundle/Provider/PublicCalendarProvider.php b/src/Oro/Bundle/CalendarBundle/Provider/PublicCalendarProvider.php index d87d043afa2..ac39b9f876c 100644 --- a/src/Oro/Bundle/CalendarBundle/Provider/PublicCalendarProvider.php +++ b/src/Oro/Bundle/CalendarBundle/Provider/PublicCalendarProvider.php @@ -48,16 +48,11 @@ public function __construct( */ public function getCalendarDefaultValues($organizationId, $userId, $calendarId, array $calendarIds) { - $result = []; - if (!$this->calendarConfig->isPublicCalendarEnabled()) { - foreach ($calendarIds as $id) { - $result[$id] = null; - } - - return $result; + return array_fill_keys($calendarIds, null); } + $result = []; /** @var SystemCalendarRepository $repo */ $repo = $this->doctrineHelper->getEntityRepository('OroCalendarBundle:SystemCalendar'); $qb = $repo->getPublicCalendarsQueryBuilder(); From 56af71049485d2aa9346b5e214727a1320908572 Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sun, 6 Dec 2015 03:17:08 +0200 Subject: [PATCH 07/12] clear code --- .../Provider/SystemCalendarProvider.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Oro/Bundle/CalendarBundle/Provider/SystemCalendarProvider.php b/src/Oro/Bundle/CalendarBundle/Provider/SystemCalendarProvider.php index cd903d52194..6d617db77fa 100644 --- a/src/Oro/Bundle/CalendarBundle/Provider/SystemCalendarProvider.php +++ b/src/Oro/Bundle/CalendarBundle/Provider/SystemCalendarProvider.php @@ -48,18 +48,13 @@ public function __construct( */ public function getCalendarDefaultValues($organizationId, $userId, $calendarId, array $calendarIds) { - $result = []; - if (!$this->calendarConfig->isSystemCalendarEnabled() || !$this->securityFacade->isGranted('oro_system_calendar_view') ) { - foreach ($calendarIds as $id) { - $result[$id] = null; - } - - return $result; + return array_fill_keys($calendarIds, null); } + $result = []; /** @var SystemCalendarRepository $repo */ $repo = $this->doctrineHelper->getEntityRepository('OroCalendarBundle:SystemCalendar'); @@ -133,7 +128,7 @@ public function getCalendarEvents( $invisibleIds[] = $id; } } - if (!empty($invisibleIds)) { + if ($invisibleIds) { $qb ->andWhere('c.id NOT IN (:invisibleIds)') ->setParameter('invisibleIds', $invisibleIds); From e755bd6df1d81aea3b49fc963b11583994ab1768 Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sun, 6 Dec 2015 03:19:28 +0200 Subject: [PATCH 08/12] clear code --- .../CalendarBundle/Provider/UserCalendarEventNormalizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Oro/Bundle/CalendarBundle/Provider/UserCalendarEventNormalizer.php b/src/Oro/Bundle/CalendarBundle/Provider/UserCalendarEventNormalizer.php index 7d1b819164b..7cb882c1170 100644 --- a/src/Oro/Bundle/CalendarBundle/Provider/UserCalendarEventNormalizer.php +++ b/src/Oro/Bundle/CalendarBundle/Provider/UserCalendarEventNormalizer.php @@ -83,7 +83,7 @@ protected function serializeCalendarEvent(CalendarEvent $event) protected function applyAdditionalData(&$items, $calendarId) { $parentEventIds = $this->getParentEventIds($items); - if (!empty($parentEventIds)) { + if ($parentEventIds) { /** @var CalendarEventRepository $repo */ $repo = $this->doctrineHelper->getEntityRepository('OroCalendarBundle:CalendarEvent'); $invitees = $repo->getInvitedUsersByParentsQueryBuilder($parentEventIds) From 816f59f3bd79bb047979e5b5f0aacbc146a38dd8 Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sun, 6 Dec 2015 03:26:24 +0200 Subject: [PATCH 09/12] clear code --- src/Oro/Bundle/CalendarBundle/Provider/UserCalendarProvider.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Oro/Bundle/CalendarBundle/Provider/UserCalendarProvider.php b/src/Oro/Bundle/CalendarBundle/Provider/UserCalendarProvider.php index 829e410dd1e..55c333fadf4 100644 --- a/src/Oro/Bundle/CalendarBundle/Provider/UserCalendarProvider.php +++ b/src/Oro/Bundle/CalendarBundle/Provider/UserCalendarProvider.php @@ -60,8 +60,6 @@ public function getCalendarDefaultValues($organizationId, $userId, $calendarId, // prohibit to remove the current calendar from the list of connected calendars if ($calendar->getId() === $calendarId) { $resultItem['removable'] = false; - } - if ($calendarId === $calendar->getId()) { $resultItem['canAddEvent'] = true; $resultItem['canEditEvent'] = true; $resultItem['canDeleteEvent'] = true; From d3e62ee18270a02ba84c3bb902a6911ba26cdb60 Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sun, 6 Dec 2015 03:29:24 +0200 Subject: [PATCH 10/12] clear code --- .../CalendarBundle/Provider/UserCalendarProvider.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Oro/Bundle/CalendarBundle/Provider/UserCalendarProvider.php b/src/Oro/Bundle/CalendarBundle/Provider/UserCalendarProvider.php index 55c333fadf4..cd410b89b2c 100644 --- a/src/Oro/Bundle/CalendarBundle/Provider/UserCalendarProvider.php +++ b/src/Oro/Bundle/CalendarBundle/Provider/UserCalendarProvider.php @@ -92,7 +92,7 @@ public function getCalendarEvents( $visibleIds[] = $id; } } - if (!empty($visibleIds)) { + if ($visibleIds) { $qb ->andWhere('c.id IN (:visibleIds)') ->setParameter('visibleIds', $visibleIds); @@ -111,11 +111,6 @@ public function getCalendarEvents( */ protected function buildCalendarName(Calendar $calendar) { - $name = $calendar->getName(); - if (!$name) { - $name = $this->entityNameResolver->getName($calendar->getOwner()); - } - - return $name; + return $calendar->getName() ?: $this->entityNameResolver->getName($calendar->getOwner()); } } From 3574990d63a9cf1a0e3f4bdce384982546eb81ed Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sun, 6 Dec 2015 03:32:40 +0200 Subject: [PATCH 11/12] clear code --- .../Datagrid/EntityPaginationExtension.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Oro/Bundle/EntityPaginationBundle/Datagrid/EntityPaginationExtension.php b/src/Oro/Bundle/EntityPaginationBundle/Datagrid/EntityPaginationExtension.php index 075a86b3371..54619668131 100644 --- a/src/Oro/Bundle/EntityPaginationBundle/Datagrid/EntityPaginationExtension.php +++ b/src/Oro/Bundle/EntityPaginationBundle/Datagrid/EntityPaginationExtension.php @@ -36,7 +36,6 @@ public function processConfigs(DatagridConfiguration $config) throw new \LogicException('Entity pagination is not boolean'); } - $pagination = $pagination ? true : false; - $config->offsetSetByPath(self::ENTITY_PAGINATION_PATH, $pagination); + $config->offsetSetByPath(self::ENTITY_PAGINATION_PATH, (bool)$pagination); } } From 0cd65546cba0004db82553c1efcd5827c2bafbdb Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sun, 6 Dec 2015 04:02:50 +0200 Subject: [PATCH 12/12] clear code --- .../Manager/EntityPaginationManager.php | 10 +++------- .../EntityPaginationBundle/Manager/MessageManager.php | 10 +++------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Oro/Bundle/EntityPaginationBundle/Manager/EntityPaginationManager.php b/src/Oro/Bundle/EntityPaginationBundle/Manager/EntityPaginationManager.php index 12050a065cb..4b1fcee5575 100644 --- a/src/Oro/Bundle/EntityPaginationBundle/Manager/EntityPaginationManager.php +++ b/src/Oro/Bundle/EntityPaginationBundle/Manager/EntityPaginationManager.php @@ -58,15 +58,11 @@ public static function getPermission($scope) { switch ($scope) { case self::VIEW_SCOPE: - $permission = 'VIEW'; - break; + return 'VIEW'; case self::EDIT_SCOPE: - $permission = 'EDIT'; - break; - default: - throw new \LogicException(sprintf('Scope "%s" is not available.', $scope)); + return 'EDIT'; } - return $permission; + throw new \LogicException(sprintf('Scope "%s" is not available.', $scope)); } } diff --git a/src/Oro/Bundle/EntityPaginationBundle/Manager/MessageManager.php b/src/Oro/Bundle/EntityPaginationBundle/Manager/MessageManager.php index 67c1ec9e014..5e5ec38d5a7 100644 --- a/src/Oro/Bundle/EntityPaginationBundle/Manager/MessageManager.php +++ b/src/Oro/Bundle/EntityPaginationBundle/Manager/MessageManager.php @@ -150,19 +150,15 @@ protected function getStatsMessage($scope) { switch ($scope) { case EntityPaginationManager::VIEW_SCOPE: - $message = + return 'oro.entity_pagination.message.' . 'stats_number_view_%count%_record|stats_number_view_%count%_records'; - break; case EntityPaginationManager::EDIT_SCOPE: - $message = + return 'oro.entity_pagination.message.' . 'stats_number_edit_%count%_record|stats_number_edit_%count%_records'; - break; - default: - throw new \LogicException(sprintf('Scope "%s" is not available.', $scope)); } - return $message; + throw new \LogicException(sprintf('Scope "%s" is not available.', $scope)); } }