Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #604 from kbrodej/hotfix/remove-unused-variables-#545
Browse files Browse the repository at this point in the history
Removed unused variables
  • Loading branch information
pfrenssen authored Jan 29, 2020
2 parents 488b701 + eaf0088 commit 76b0b6c
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions og.module
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 0 additions & 2 deletions phpcs-ruleset.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
<rule ref="./vendor/drupal/coder/coder_sniffer/DrupalPractice">
<!-- https://github.com/Gizra/og/issues/549 -->
<exclude name="DrupalPractice.CodeAnalysis.VariableAnalysis.UndefinedVariable" />
<!-- https://github.com/Gizra/og/issues/545 -->
<exclude name="DrupalPractice.CodeAnalysis.VariableAnalysis.UnusedVariable" />
<!-- https://github.com/Gizra/og/issues/550 -->
<exclude name="DrupalPractice.Constants.GlobalDefine.GlobalConstant" />
<!-- https://github.com/Gizra/og/issues/544 -->
Expand Down
4 changes: 2 additions & 2 deletions src/Cache/Context/OgRoleCacheContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/ContextProvider/OgContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/Event/DefaultRoleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/GroupTypeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/Og.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}

Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/EntityReferenceSelection/OgSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/Entity/GroupMembershipManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions tests/src/Unit/DefaultRoleEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down Expand Up @@ -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);
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/src/Unit/PermissionEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down

0 comments on commit 76b0b6c

Please sign in to comment.