diff --git a/og.module b/og.module index 8ce39c756..46ed6b65d 100755 --- a/og.module +++ b/og.module @@ -204,7 +204,7 @@ function og_entity_create_access(AccountInterface $account, array $context, $bun $required = FALSE; $field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($entity_type_id, $bundle); - foreach ($field_definitions as $field_name => $field_definition) { + foreach ($field_definitions as $field_definition) { /** @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */ if (!\Drupal::service('og.group_audience_helper')->isGroupAudienceField($field_definition)) { continue; @@ -359,7 +359,7 @@ function og_invalidate_group_content_cache_tags(EntityInterface $entity) { } } - foreach ($membership_manager->getGroups($entity) as $group_entity_type_id => $groups) { + foreach ($membership_manager->getGroups($entity) as $groups) { /** @var \Drupal\Core\Entity\ContentEntityInterface $group */ foreach ($groups as $group) { $tags = Cache::mergeTags($tags, $group->getCacheTagsToInvalidate()); diff --git a/phpcs-ruleset.xml.dist b/phpcs-ruleset.xml.dist index b7423d094..069d655b0 100644 --- a/phpcs-ruleset.xml.dist +++ b/phpcs-ruleset.xml.dist @@ -22,8 +22,6 @@ - - diff --git a/src/Cache/Context/OgRoleCacheContext.php b/src/Cache/Context/OgRoleCacheContext.php index 9a1372f14..b28ab35b9 100644 --- a/src/Cache/Context/OgRoleCacheContext.php +++ b/src/Cache/Context/OgRoleCacheContext.php @@ -121,9 +121,9 @@ public function getContext() { // Sort the memberships, so that the same key can be generated, even if // the memberships were defined in a different order. ksort($memberships); - foreach ($memberships as $entity_type_id => &$groups) { + foreach ($memberships as &$groups) { ksort($groups); - foreach ($groups as $group_id => &$role_names) { + foreach ($groups as &$role_names) { sort($role_names); } } diff --git a/src/ContextProvider/OgContext.php b/src/ContextProvider/OgContext.php index 9cd8fefed..6a492dcb2 100644 --- a/src/ContextProvider/OgContext.php +++ b/src/ContextProvider/OgContext.php @@ -126,7 +126,6 @@ protected function getOgContext() { */ protected function getBestCandidate() { $collection = new OgResolvedGroupCollection(); - $plugins = []; // Retrieve the list of group resolvers. These are stored in config, and are // ordered by priority. @@ -135,8 +134,6 @@ protected function getBestCandidate() { foreach ($group_resolvers as $plugin_id) { /** @var \Drupal\og\OgGroupResolverInterface $plugin */ if ($plugin = $this->pluginManager->createInstance($plugin_id)) { - $plugins[$plugin_id] = $plugin; - // Set the default vote weight according to the plugin's priority. $collection->setVoteWeight($priority); diff --git a/src/Event/DefaultRoleEvent.php b/src/Event/DefaultRoleEvent.php index 3e6679ce5..8ddd5e73e 100644 --- a/src/Event/DefaultRoleEvent.php +++ b/src/Event/DefaultRoleEvent.php @@ -73,7 +73,7 @@ public function setRole(OgRole $role) { * {@inheritdoc} */ public function setRoles(array $roles) { - foreach ($roles as $name => $properties) { + foreach ($roles as $properties) { $this->setRole($properties); } } diff --git a/src/GroupTypeManager.php b/src/GroupTypeManager.php index 40ed91939..332f5f0d7 100644 --- a/src/GroupTypeManager.php +++ b/src/GroupTypeManager.php @@ -200,7 +200,7 @@ public function getAllGroupBundles($entity_type = NULL) { */ public function getAllGroupContentBundleIds() { $bundles = []; - foreach ($this->getGroupRelationMap() as $group_entity_type_id => $group_bundle_ids) { + foreach ($this->getGroupRelationMap() as $group_bundle_ids) { foreach ($group_bundle_ids as $group_content_entity_type_ids) { foreach ($group_content_entity_type_ids as $group_content_entity_type_id => $group_content_bundle_ids) { $bundles[$group_content_entity_type_id] = array_merge(isset($bundles[$group_content_entity_type_id]) ? $bundles[$group_content_entity_type_id] : [], $group_content_bundle_ids); diff --git a/src/Og.php b/src/Og.php index 4232e9050..dd30d6aff 100644 --- a/src/Og.php +++ b/src/Og.php @@ -363,7 +363,9 @@ public static function invalidateCache() { protected static function getFieldBaseDefinition($plugin_id) { /** @var OgFieldsPluginManager $plugin_manager */ $plugin_manager = \Drupal::service('plugin.manager.og.fields'); - if (!$field_config = $plugin_manager->getDefinition($plugin_id)) { + + $field_config = $plugin_manager->getDefinition($plugin_id); + if (!$field_config) { throw new \Exception("The Organic Groups field with plugin ID $plugin_id is not a valid plugin."); } diff --git a/src/Plugin/EntityReferenceSelection/OgSelection.php b/src/Plugin/EntityReferenceSelection/OgSelection.php index 3b63fa4f1..131e53784 100644 --- a/src/Plugin/EntityReferenceSelection/OgSelection.php +++ b/src/Plugin/EntityReferenceSelection/OgSelection.php @@ -89,7 +89,7 @@ protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') $ids = []; if (!empty($this->getConfiguration()['field_mode']) && $this->getConfiguration()['field_mode'] === 'admin') { // Don't include the groups, the user doesn't have create permission. - foreach ($user_groups as $delta => $group) { + foreach ($user_groups as $group) { $ids[] = $group->id(); } diff --git a/tests/src/Kernel/Entity/GroupMembershipManagerTest.php b/tests/src/Kernel/Entity/GroupMembershipManagerTest.php index 14c1b76f2..42859160e 100644 --- a/tests/src/Kernel/Entity/GroupMembershipManagerTest.php +++ b/tests/src/Kernel/Entity/GroupMembershipManagerTest.php @@ -305,7 +305,7 @@ public function testGetGroups($group_type_id, $group_bundle, array $expected) { /** @var \Drupal\Core\Entity\EntityInterface $expected_group */ $expected_group = $this->groups[$expected_type][$expected_key]; /** @var \Drupal\Core\Entity\EntityInterface $group */ - foreach ($result[$expected_type] as $key => $group) { + foreach ($result[$expected_type] as $group) { if ($group->getEntityTypeId() === $expected_group->getEntityTypeId() && $group->id() === $expected_group->id()) { // The expected result was found. Continue the test. continue 2; diff --git a/tests/src/Unit/DefaultRoleEventTest.php b/tests/src/Unit/DefaultRoleEventTest.php index 6207c6070..52f881971 100644 --- a/tests/src/Unit/DefaultRoleEventTest.php +++ b/tests/src/Unit/DefaultRoleEventTest.php @@ -325,7 +325,7 @@ public function testAddInvalidRole(array $invalid_roles) { $this->expectOgRoleCreation($invalid_roles); try { - foreach ($invalid_roles as $name => $invalid_role) { + foreach ($invalid_roles as $invalid_role) { $this->defaultRoleEvent->addRole($invalid_role); } $this->fail('An invalid role cannot be added.'); @@ -368,8 +368,8 @@ public function testAddInvalidRoles(array $invalid_roles) { public function testSetInvalidRole(array $invalid_roles) { $this->expectOgRoleCreation($invalid_roles); - foreach ($invalid_roles as $name => $invalid_role) { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); + foreach ($invalid_roles as $invalid_role) { $this->defaultRoleEvent->setRole($invalid_role); } } diff --git a/tests/src/Unit/PermissionEventTest.php b/tests/src/Unit/PermissionEventTest.php index cc452ed9b..e7fe5f7ee 100644 --- a/tests/src/Unit/PermissionEventTest.php +++ b/tests/src/Unit/PermissionEventTest.php @@ -441,8 +441,11 @@ public function testOffsetSet(array $permissions, $entity_type_id, $bundle_id, a */ public function testOffsetSetInvalidPermission($key, $permission) { $this->expectException(\InvalidArgumentException::class); + + // phpcs:disable DrupalPractice.CodeAnalysis.VariableAnalysis.UnusedVariable $event = new PermissionEvent($this->randomMachineName(), $this->randomMachineName(), []); $event[$key] = $permission; + // phpcs:enable DrupalPractice.CodeAnalysis.VariableAnalysis.UnusedVariable } /**