diff --git a/og.module b/og.module index 099daa8c8..0367c1e2b 100755 --- a/og.module +++ b/og.module @@ -253,10 +253,10 @@ function og_entity_create_access(AccountInterface $account, array $context, $bun * * Add a read only property to group entities as a group flag. */ -function og_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) { +function og_entity_bundle_field_info(EntityTypeInterface $entity_type, string $bundle, array $base_field_definitions): array { if (!Og::isGroup($entity_type->id(), $bundle)) { // Not a group type. - return NULL; + return []; } $fields = []; diff --git a/src/Controller/OgAdminRoutesController.php b/src/Controller/OgAdminRoutesController.php index 41889fbc7..1357ff96d 100644 --- a/src/Controller/OgAdminRoutesController.php +++ b/src/Controller/OgAdminRoutesController.php @@ -23,14 +23,14 @@ class OgAdminRoutesController extends ControllerBase { * * @var \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher */ - protected $eventDispatcher; + protected ContainerAwareEventDispatcher $eventDispatcher; /** * The access manager service. * * @var \Drupal\Core\Access\AccessManagerInterface */ - protected $accessManager; + protected AccessManagerInterface $accessManager; /** * Constructs an OgAdminController object. @@ -64,7 +64,7 @@ public static function create(ContainerInterface $container) { * @return array * List of available admin routes for the current group. */ - public function overview(RouteMatchInterface $route_match) { + public function overview(RouteMatchInterface $route_match): array { $parameter_name = $route_match->getRouteObject()->getOption('_og_entity_type_id'); /** @var \Drupal\Core\Entity\EntityInterface $group */ diff --git a/src/GroupTypeManager.php b/src/GroupTypeManager.php index b74c3f849..4d2890be5 100644 --- a/src/GroupTypeManager.php +++ b/src/GroupTypeManager.php @@ -8,6 +8,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Routing\RouteBuilderInterface; use Drupal\og\Event\GroupCreationEvent; use Drupal\og\Event\GroupCreationEventInterface; @@ -42,35 +43,35 @@ class GroupTypeManager implements GroupTypeManagerInterface { * * @var \Drupal\Core\Config\ConfigFactoryInterface */ - protected $configFactory; + protected ConfigFactoryInterface $configFactory; /** * The service providing information about bundles. * * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface */ - protected $entityTypeBundleInfo; + protected EntityTypeBundleInfoInterface $entityTypeBundleInfo; /** * The event dispatcher. * * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */ - protected $eventDispatcher; + protected EventDispatcherInterface $eventDispatcher; /** * The cache backend. * * @var \Drupal\Core\Cache\CacheBackendInterface */ - protected $cache; + protected CacheBackendInterface $cache; /** * The OG permission manager. * * @var \Drupal\og\PermissionManagerInterface */ - protected $permissionManager; + protected PermissionManagerInterface $permissionManager; /** * A map of entity types and bundles. @@ -79,7 +80,7 @@ class GroupTypeManager implements GroupTypeManagerInterface { * * @var array */ - protected $groupMap; + protected array $groupMap; /** * A map of group and group content relations. @@ -103,42 +104,42 @@ class GroupTypeManager implements GroupTypeManagerInterface { * ] * @endcode */ - protected $groupRelationMap = []; + protected array $groupRelationMap = []; /** * The module handler. * * @var \Drupal\Core\Extension\ModuleHandlerInterface */ - protected $moduleHandler; + protected ModuleHandlerInterface $moduleHandler; /** * The OG role manager. * * @var \Drupal\og\OgRoleManagerInterface */ - protected $ogRoleManager; + protected OgRoleManagerInterface $ogRoleManager; /** * The route builder service. * * @var \Drupal\Core\Routing\RouteBuilderInterface */ - protected $routeBuilder; + protected RouteBuilderInterface $routeBuilder; /** * The OG group audience helper. * * @var \Drupal\og\OgGroupAudienceHelperInterface */ - protected $groupAudienceHelper; + protected OgGroupAudienceHelperInterface $groupAudienceHelper; /** * The Entity type manager service. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityTypeManager; + protected EntityTypeManagerInterface $entityTypeManager; /** * Constructs a GroupTypeManager object. @@ -177,7 +178,7 @@ public function __construct(ConfigFactoryInterface $config_factory, EntityTypeMa /** * {@inheritdoc} */ - public function isGroup($entity_type_id, $bundle) { + public function isGroup(string $entity_type_id, string $bundle): bool { $group_map = $this->getGroupMap(); return isset($group_map[$entity_type_id]) && in_array($bundle, $group_map[$entity_type_id]); } @@ -185,18 +186,19 @@ public function isGroup($entity_type_id, $bundle) { /** * {@inheritdoc} */ - public function isGroupContent($entity_type_id, $bundle) { + public function isGroupContent(string $entity_type_id, string $bundle): bool { // To avoid insanity, a group membership cannot be a group or group content. if ($entity_type_id === 'og_membership') { return FALSE; } + return $this->groupAudienceHelper->hasGroupAudienceField($entity_type_id, $bundle); } /** * {@inheritdoc} */ - public function getGroupBundleIdsByEntityType($entity_type_id) { + public function getGroupBundleIdsByEntityType(string $entity_type_id): array { $group_map = $this->getGroupMap(); return $group_map[$entity_type_id] ?? []; } @@ -204,7 +206,7 @@ public function getGroupBundleIdsByEntityType($entity_type_id) { /** * {@inheritdoc} */ - public function getAllGroupContentBundleIds() { + public function getAllGroupContentBundleIds(): array { $bundles = []; foreach ($this->getGroupRelationMap() as $group_bundle_ids) { foreach ($group_bundle_ids as $group_content_entity_type_ids) { @@ -219,7 +221,7 @@ public function getAllGroupContentBundleIds() { /** * {@inheritdoc} */ - public function getAllGroupContentBundlesByEntityType($entity_type_id) { + public function getAllGroupContentBundlesByEntityType(string $entity_type_id): array { $bundles = $this->getAllGroupContentBundleIds(); if (!isset($bundles[$entity_type_id])) { throw new \InvalidArgumentException("The '$entity_type_id' entity type has no group content bundles."); @@ -230,7 +232,7 @@ public function getAllGroupContentBundlesByEntityType($entity_type_id) { /** * {@inheritdoc} */ - public function getGroupBundleIdsByGroupContentBundle($group_content_entity_type_id, $group_content_bundle_id) { + public function getGroupBundleIdsByGroupContentBundle(string $group_content_entity_type_id, string $group_content_bundle_id): array { $bundles = []; foreach ($this->groupAudienceHelper->getAllGroupAudienceFields($group_content_entity_type_id, $group_content_bundle_id) as $field) { @@ -255,7 +257,7 @@ public function getGroupBundleIdsByGroupContentBundle($group_content_entity_type /** * {@inheritdoc} */ - public function getGroupContentBundleIdsByGroupBundle($group_entity_type_id, $group_bundle_id) { + public function getGroupContentBundleIdsByGroupBundle(string $group_entity_type_id, string $group_bundle_id): array { $group_relation_map = $this->getGroupRelationMap(); return $group_relation_map[$group_entity_type_id][$group_bundle_id] ?? []; } @@ -263,7 +265,7 @@ public function getGroupContentBundleIdsByGroupBundle($group_entity_type_id, $gr /** * {@inheritdoc} */ - public function addGroup($entity_type_id, $bundle_id) { + public function addGroup(string $entity_type_id, string $bundle_id): void { // To avoid insanity, a group membership cannot be a group or group content. if ($entity_type_id === 'og_membership') { throw new \InvalidArgumentException("The '$entity_type_id' type cannot be a group."); @@ -296,7 +298,7 @@ public function addGroup($entity_type_id, $bundle_id) { /** * {@inheritdoc} */ - public function removeGroup($entity_type_id, $bundle_id) { + public function removeGroup(string $entity_type_id, string $bundle_id): void { $editable = $this->configFactory->getEditable('og.settings'); $groups = $editable->get('groups'); @@ -324,7 +326,7 @@ public function removeGroup($entity_type_id, $bundle_id) { /** * {@inheritdoc} */ - public function reset() { + public function reset(): void { $this->resetGroupMap(); $this->resetGroupRelationMap(); } @@ -332,14 +334,14 @@ public function reset() { /** * {@inheritdoc} */ - public function resetGroupMap() { + public function resetGroupMap(): void { $this->groupMap = []; } /** * {@inheritdoc} */ - public function resetGroupRelationMap() { + public function resetGroupRelationMap(): void { $this->groupRelationMap = []; $this->cache->delete(self::GROUP_RELATION_MAP_CACHE_KEY); } @@ -347,7 +349,7 @@ public function resetGroupRelationMap() { /** * {@inheritdoc} */ - public function getGroupMap() { + public function getGroupMap(): array { if (empty($this->groupMap)) { $this->refreshGroupMap(); } @@ -360,7 +362,7 @@ public function getGroupMap() { * @return array * The group relation map. */ - protected function getGroupRelationMap() { + protected function getGroupRelationMap(): array { if (empty($this->groupRelationMap)) { $this->populateGroupRelationMap(); } diff --git a/src/GroupTypeManagerInterface.php b/src/GroupTypeManagerInterface.php index 74cdfb80f..7e21711a6 100644 --- a/src/GroupTypeManagerInterface.php +++ b/src/GroupTypeManagerInterface.php @@ -20,7 +20,7 @@ interface GroupTypeManagerInterface { * @return bool * TRUE if a bundle is a group. */ - public function isGroup($entity_type_id, $bundle); + public function isGroup(string $entity_type_id, string $bundle): bool; /** * Checks if the given entity bundle is group content. @@ -36,7 +36,7 @@ public function isGroup($entity_type_id, $bundle); * @return bool * TRUE if the entity bundle is group content. */ - public function isGroupContent($entity_type_id, $bundle); + public function isGroupContent(string $entity_type_id, string $bundle): bool; /** * Returns the group of an entity type. @@ -47,7 +47,7 @@ public function isGroupContent($entity_type_id, $bundle); * @return \Drupal\Core\Entity\EntityInterface[] * Array of groups, or an empty array if none found */ - public function getGroupBundleIdsByEntityType($entity_type_id); + public function getGroupBundleIdsByEntityType(string $entity_type_id): array; /** * Returns a list of all group content bundles IDs keyed by entity type. @@ -62,7 +62,7 @@ public function getGroupBundleIdsByEntityType($entity_type_id); * * @see \Drupal\og\GroupTypeManagerInterface::getGroupRelationMap() */ - public function getAllGroupContentBundleIds(); + public function getAllGroupContentBundleIds(): array; /** * Returns a list of all group content bundles filtered by entity type. @@ -83,7 +83,7 @@ public function getAllGroupContentBundleIds(); * * @see \Drupal\og\GroupTypeManagerInterface::getGroupRelationMap() */ - public function getAllGroupContentBundlesByEntityType($entity_type_id); + public function getAllGroupContentBundlesByEntityType(string $entity_type_id): array; /** * Returns all group bundles that are referenced by the given group content. @@ -98,7 +98,7 @@ public function getAllGroupContentBundlesByEntityType($entity_type_id); * @return string[][] * An array of group bundle IDs, keyed by group entity type ID. */ - public function getGroupBundleIdsByGroupContentBundle($group_content_entity_type_id, $group_content_bundle_id); + public function getGroupBundleIdsByGroupContentBundle(string $group_content_entity_type_id, string $group_content_bundle_id): array; /** * Returns group content bundles that are referencing the given group content. @@ -114,7 +114,7 @@ public function getGroupBundleIdsByGroupContentBundle($group_content_entity_type * An array of group content bundle IDs, keyed by group content entity type * ID. */ - public function getGroupContentBundleIdsByGroupBundle($group_entity_type_id, $group_bundle_id); + public function getGroupContentBundleIdsByGroupBundle(string $group_entity_type_id, string $group_bundle_id): array; /** * Declares a bundle of an entity type as being an OG group. @@ -127,24 +127,24 @@ public function getGroupContentBundleIdsByGroupBundle($group_entity_type_id, $gr * @throws \InvalidArgumentException * Thrown when the given bundle is already a group or is invalid. */ - public function addGroup($entity_type_id, $bundle_id); + public function addGroup(string $entity_type_id, string $bundle_id): void; /** * Removes an entity type instance as being an OG group. */ - public function removeGroup($entity_type_id, $bundle_id); + public function removeGroup(string $entity_type_id, string $bundle_id): void; /** * Resets all locally stored data. */ - public function reset(); + public function reset(): void; /** * Resets the cached group map. * * Call this after adding or removing a group type. */ - public function resetGroupMap(); + public function resetGroupMap(): void; /** * Resets the cached group relation map. @@ -152,7 +152,7 @@ public function resetGroupMap(); * Call this after making a change to the relationship between a group type * and a group content type. */ - public function resetGroupRelationMap(); + public function resetGroupRelationMap(): void; /** * Returns the group map. @@ -160,6 +160,6 @@ public function resetGroupRelationMap(); * @return string[][] * The group map. */ - public function getGroupMap(); + public function getGroupMap(): array; } diff --git a/src/Og.php b/src/Og.php index 6e43c0c6d..8e9855707 100644 --- a/src/Og.php +++ b/src/Og.php @@ -269,7 +269,7 @@ public static function isMemberBlocked(EntityInterface $group, AccountInterface * @return bool * True or false if the given entity is group. */ - public static function isGroup($entity_type_id, $bundle_id) { + public static function isGroup(string $entity_type_id, string $bundle_id): bool { return static::groupTypeManager()->isGroup($entity_type_id, $bundle_id); } @@ -284,8 +284,8 @@ public static function isGroup($entity_type_id, $bundle_id) { * @return bool * True or false if the given entity is group content. */ - public static function isGroupContent($entity_type_id, $bundle_id) { - return \Drupal::service('og.group_type_manager')->isGroupContent($entity_type_id, $bundle_id); + public static function isGroupContent(string $entity_type_id, string $bundle_id): bool { + return static::groupTypeManager()->isGroupContent($entity_type_id, $bundle_id); } /** @@ -296,7 +296,7 @@ public static function isGroupContent($entity_type_id, $bundle_id) { * @param string $bundle_id * The bundle name. */ - public static function addGroup($entity_type_id, $bundle_id) { + public static function addGroup(string $entity_type_id, string $bundle_id): void { static::groupTypeManager()->addGroup($entity_type_id, $bundle_id); } @@ -307,12 +307,9 @@ public static function addGroup($entity_type_id, $bundle_id) { * The entity type. * @param string $bundle_id * The bundle name. - * - * @return bool - * True or false if the action succeeded. */ - public static function removeGroup($entity_type_id, $bundle_id) { - return static::groupTypeManager()->removeGroup($entity_type_id, $bundle_id); + public static function removeGroup(string $entity_type_id, string $bundle_id): void { + static::groupTypeManager()->removeGroup($entity_type_id, $bundle_id); } /** @@ -321,7 +318,7 @@ public static function removeGroup($entity_type_id, $bundle_id) { * @return \Drupal\og\GroupTypeManagerInterface * Returns the group manager. */ - public static function groupTypeManager() { + public static function groupTypeManager(): GroupTypeManagerInterface { // @todo store static reference for this? return \Drupal::service('og.group_type_manager'); } diff --git a/src/OgAccess.php b/src/OgAccess.php index 5e0968189..ca22f2957 100644 --- a/src/OgAccess.php +++ b/src/OgAccess.php @@ -54,49 +54,49 @@ class OgAccess implements OgAccessInterface { * * @var \Drupal\Core\Config\ConfigFactoryInterface */ - protected $configFactory; + protected ConfigFactoryInterface $configFactory; /** * The service that contains the current active user. * * @var \Drupal\Core\Session\AccountProxyInterface */ - protected $accountProxy; + protected AccountProxyInterface $accountProxy; /** * The module handler. * * @var \Drupal\Core\Extension\ModuleHandlerInterface */ - protected $moduleHandler; + protected ModuleHandlerInterface $moduleHandler; /** * The group manager. * * @var \Drupal\og\GroupTypeManagerInterface */ - protected $groupTypeManager; + protected GroupTypeManagerInterface $groupTypeManager; /** * The OG permission manager. * * @var \Drupal\og\PermissionManagerInterface */ - protected $permissionManager; + protected PermissionManagerInterface $permissionManager; /** * The group membership manager. * * @var \Drupal\og\MembershipManagerInterface */ - protected $membershipManager; + protected MembershipManagerInterface $membershipManager; /** * The event dispatcher. * * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */ - protected $dispatcher; + protected EventDispatcherInterface $dispatcher; /** * Constructs the OgAccess service. diff --git a/src/OgRoleManager.php b/src/OgRoleManager.php index 979830b56..93dcfae9b 100644 --- a/src/OgRoleManager.php +++ b/src/OgRoleManager.php @@ -4,6 +4,7 @@ namespace Drupal\og; +use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\og\Event\DefaultRoleEvent; use Drupal\og\Event\DefaultRoleEventInterface; @@ -19,28 +20,28 @@ class OgRoleManager implements OgRoleManagerInterface { * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityTypeManager; + protected EntityTypeManagerInterface $entityTypeManager; /** * The entity storage for OgRole entities. * * @var \Drupal\Core\Entity\EntityStorageInterface */ - protected $ogRoleStorage; + protected EntityStorageInterface $ogRoleStorage; /** * The event dispatcher. * * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */ - protected $eventDispatcher; + protected EventDispatcherInterface $eventDispatcher; /** * The OG permission manager. * * @var \Drupal\og\PermissionManagerInterface */ - protected $permissionManager; + protected PermissionManagerInterface $permissionManager; /** * Constructs an OgRoleManager object. @@ -61,7 +62,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Eve /** * {@inheritdoc} */ - public function createPerBundleRoles($entity_type_id, $bundle_id) { + public function createPerBundleRoles(string $entity_type_id, string $bundle_id): array { $roles = []; foreach ($this->getDefaultRoles() as $role) { $role->setGroupType($entity_type_id); @@ -83,7 +84,7 @@ public function createPerBundleRoles($entity_type_id, $bundle_id) { /** * {@inheritdoc} */ - public function getDefaultRoles() { + public function getDefaultRoles(): array { // Provide the required default roles: 'member' and 'non-member'. $roles = $this->getRequiredDefaultRoles(); @@ -100,7 +101,7 @@ public function getDefaultRoles() { /** * {@inheritdoc} */ - public function getRequiredDefaultRoles() { + public function getRequiredDefaultRoles(): array { $roles = []; $role_properties = [ @@ -126,7 +127,7 @@ public function getRequiredDefaultRoles() { /** * {@inheritdoc} */ - public function getRolesByBundle($entity_type_id, $bundle) { + public function getRolesByBundle(string $entity_type_id, string $bundle): array { $properties = [ 'group_type' => $entity_type_id, 'group_bundle' => $bundle, @@ -137,7 +138,7 @@ public function getRolesByBundle($entity_type_id, $bundle) { /** * {@inheritdoc} */ - public function getRolesByPermissions(array $permissions, $entity_type_id = NULL, $bundle = NULL, $require_all = TRUE): array { + public function getRolesByPermissions(array $permissions, ?string $entity_type_id = NULL, ?string $bundle = NULL, bool $require_all = TRUE): array { $role_storage = $this->ogRoleStorage(); $query = $role_storage->getQuery(); if ($require_all) { @@ -166,7 +167,7 @@ public function getRolesByPermissions(array $permissions, $entity_type_id = NULL /** * {@inheritdoc} */ - public function removeRoles($entity_type_id, $bundle_id) { + public function removeRoles(string $entity_type_id, string $bundle_id): void { $properties = [ 'group_type' => $entity_type_id, 'group_bundle' => $bundle_id, @@ -182,8 +183,8 @@ public function removeRoles($entity_type_id, $bundle_id) { * @return \Drupal\Core\Entity\EntityStorageInterface * The OG Role storage */ - protected function ogRoleStorage() { - if (!$this->ogRoleStorage) { + protected function ogRoleStorage(): EntityStorageInterface { + if (!isset($this->ogRoleStorage)) { $this->ogRoleStorage = $this->entityTypeManager->getStorage('og_role'); } diff --git a/src/OgRoleManagerInterface.php b/src/OgRoleManagerInterface.php index b7871fa0c..5630276f4 100644 --- a/src/OgRoleManagerInterface.php +++ b/src/OgRoleManagerInterface.php @@ -22,7 +22,7 @@ interface OgRoleManagerInterface { * @return \Drupal\og\Entity\OgRole[] * Array with the saved OG roles that were created */ - public function createPerBundleRoles($entity_type_id, $bundle_id); + public function createPerBundleRoles(string $entity_type_id, string $bundle_id): array; /** * Returns the default roles. @@ -32,7 +32,7 @@ public function createPerBundleRoles($entity_type_id, $bundle_id); * These are populated with the basic properties: name, label, role_type and * is_admin. */ - public function getDefaultRoles(); + public function getDefaultRoles(): array; /** * Returns the roles which every group type requires. @@ -45,7 +45,7 @@ public function getDefaultRoles(); * name. These are populated with the basic properties: name, label and * role_type. */ - public function getRequiredDefaultRoles(); + public function getRequiredDefaultRoles(): array; /** * Returns all the roles of a provided group. @@ -58,7 +58,7 @@ public function getRequiredDefaultRoles(); * @return \Drupal\og\OgRoleInterface[] * An array of roles indexed by their IDs. */ - public function getRolesByBundle($entity_type_id, $bundle); + public function getRolesByBundle(string $entity_type_id, string $bundle): array; /** * Returns all the roles that have a specific permission. @@ -67,9 +67,9 @@ public function getRolesByBundle($entity_type_id, $bundle); * * @param array $permissions * An array of permissions that the roles must have. - * @param string $entity_type_id + * @param string|null $entity_type_id * (optional) The entity type ID of the group. - * @param string $bundle + * @param string|null $bundle * (optional) The bundle of the group. * @param bool $require_all * (optional) Whether all given permissions are required. When set to FALSE @@ -79,7 +79,7 @@ public function getRolesByBundle($entity_type_id, $bundle); * @return \Drupal\og\OgRoleInterface[] * An array of roles indexed by their IDs. */ - public function getRolesByPermissions(array $permissions, $entity_type_id = NULL, $bundle = NULL, $require_all = TRUE): array; + public function getRolesByPermissions(array $permissions, ?string $entity_type_id = NULL, ?string $bundle = NULL, bool $require_all = TRUE): array; /** * Deletes the roles associated with a group type. @@ -89,6 +89,6 @@ public function getRolesByPermissions(array $permissions, $entity_type_id = NULL * @param string $bundle_id * The bundle ID of the group for which to delete the roles. */ - public function removeRoles($entity_type_id, $bundle_id); + public function removeRoles(string $entity_type_id, string $bundle_id): void; } diff --git a/src/PermissionManager.php b/src/PermissionManager.php index bb91cae4b..24545d051 100644 --- a/src/PermissionManager.php +++ b/src/PermissionManager.php @@ -18,7 +18,7 @@ class PermissionManager implements PermissionManagerInterface { * * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */ - protected $eventDispatcher; + protected EventDispatcherInterface $eventDispatcher; /** * Constructs a PermissionManager object. @@ -33,7 +33,7 @@ public function __construct(EventDispatcherInterface $event_dispatcher) { /** * {@inheritdoc} */ - public function getDefaultPermissions($group_entity_type_id, $group_bundle_id, array $group_content_bundle_ids, $role_name = NULL) { + public function getDefaultPermissions(string $group_entity_type_id, string $group_bundle_id, array $group_content_bundle_ids, ?string $role_name = NULL): array { $event = new PermissionEvent($group_entity_type_id, $group_bundle_id, $group_content_bundle_ids); $this->eventDispatcher->dispatch($event, PermissionEventInterface::EVENT_NAME); return $event->getPermissions(); @@ -42,7 +42,7 @@ public function getDefaultPermissions($group_entity_type_id, $group_bundle_id, a /** * {@inheritdoc} */ - public function getDefaultGroupPermissions($group_entity_type_id, $group_bundle_id, $role_name = NULL) { + public function getDefaultGroupPermissions(string $group_entity_type_id, string $group_bundle_id, ?string $role_name = NULL): array { $permissions = $this->getDefaultPermissions($group_entity_type_id, $group_bundle_id, [], $role_name); $permissions = array_filter($permissions, function (PermissionInterface $permission) use ($role_name) { @@ -62,7 +62,7 @@ public function getDefaultGroupPermissions($group_entity_type_id, $group_bundle_ /** * {@inheritdoc} */ - public function getDefaultEntityOperationPermissions($group_entity_type_id, $group_bundle_id, array $group_content_bundle_ids, $role_name = NULL) { + public function getDefaultEntityOperationPermissions(string $group_entity_type_id, string $group_bundle_id, array $group_content_bundle_ids, ?string $role_name = NULL): array { $permissions = $this->getDefaultPermissions($group_entity_type_id, $group_bundle_id, $group_content_bundle_ids, $role_name); $permissions = array_filter($permissions, function (PermissionInterface $permission) use ($role_name) { diff --git a/src/PermissionManagerInterface.php b/src/PermissionManagerInterface.php index 1a9f38dd7..37de2dc31 100644 --- a/src/PermissionManagerInterface.php +++ b/src/PermissionManagerInterface.php @@ -30,7 +30,7 @@ interface PermissionManagerInterface { * @return \Drupal\og\PermissionInterface[] * The array of permissions. */ - public function getDefaultPermissions($group_entity_type_id, $group_bundle_id, array $group_content_bundle_ids, $role_name = NULL); + public function getDefaultPermissions(string $group_entity_type_id, string $group_bundle_id, array $group_content_bundle_ids, ?string $role_name = NULL): array; /** * Returns permissions that are enabled by default for the given role. @@ -58,7 +58,7 @@ public function getDefaultPermissions($group_entity_type_id, $group_bundle_id, a * @see \Drupal\og\Event\PermissionEventInterface * @see \Drupal\og\EventSubscriber\OgEventSubscriber::provideDefaultOgPermissions() */ - public function getDefaultGroupPermissions($group_entity_type_id, $group_bundle_id, $role_name = NULL); + public function getDefaultGroupPermissions(string $group_entity_type_id, string $group_bundle_id, ?string $role_name = NULL): array; /** * Returns the list of entity operation permissions for a given group content. @@ -89,6 +89,6 @@ public function getDefaultGroupPermissions($group_entity_type_id, $group_bundle_ * @see \Drupal\og\EventSubscriber\OgEventSubscriber::provideDefaultNodePermissions() * @see \Drupal\og\EventSubscriber\OgEventSubscriber::getDefaultEntityOperationPermissions() */ - public function getDefaultEntityOperationPermissions($group_entity_type_id, $group_bundle_id, array $group_content_bundle_ids, $role_name = NULL); + public function getDefaultEntityOperationPermissions(string $group_entity_type_id, string $group_bundle_id, array $group_content_bundle_ids, ?string $role_name = NULL): array; } diff --git a/src/Routing/RouteSubscriber.php b/src/Routing/RouteSubscriber.php index 6b7959deb..b16bd1cca 100644 --- a/src/Routing/RouteSubscriber.php +++ b/src/Routing/RouteSubscriber.php @@ -28,21 +28,21 @@ class RouteSubscriber extends RouteSubscriberBase { * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityTypeManager; + protected EntityTypeManagerInterface $entityTypeManager; /** * The route provider service. * - * @var \Drupal\Core\Routing\RouteProvider + * @var \Drupal\Core\Routing\RouteProviderInterface */ - protected $routeProvider; + protected RouteProviderInterface $routeProvider; /** * The event dispatcher service. * - * @var \Symfony\Component\EventDispatcher\EventDispatcher + * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */ - protected $eventDispatcher; + protected EventDispatcherInterface $eventDispatcher; /** * Constructs a new RouteSubscriber object. @@ -63,7 +63,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Rou /** * {@inheritdoc} */ - protected function alterRoutes(RouteCollection $collection) { + protected function alterRoutes(RouteCollection $collection): void { foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { if (!$entity_type->hasLinkTemplate('canonical')) { @@ -103,9 +103,7 @@ protected function alterRoutes(RouteCollection $collection) { // Add the routes defined in the event subscribers. $this->createRoutesFromEventSubscribers($og_admin_path, $entity_type_id, $collection); - } - } /** @@ -118,7 +116,7 @@ protected function alterRoutes(RouteCollection $collection) { * @param \Symfony\Component\Routing\RouteCollection $collection * The route collection object. */ - protected function createRoutesFromEventSubscribers($og_admin_path, $entity_type_id, RouteCollection $collection) { + protected function createRoutesFromEventSubscribers(string $og_admin_path, string $entity_type_id, RouteCollection $collection): void { $event = new OgAdminRoutesEvent(); $this->eventDispatcher->dispatch($event, OgAdminRoutesEventInterface::EVENT_NAME); @@ -144,7 +142,7 @@ protected function createRoutesFromEventSubscribers($og_admin_path, $entity_type * Array with the router definitions. Required keys are "defaults", * "options", and "requirements". */ - protected function addRoute(RouteCollection $collection, $route_name, $path, array $route_info) { + protected function addRoute(RouteCollection $collection, string $route_name, string $path, array $route_info): void { $route = new Route($path); $route ->addDefaults($route_info['defaults']) diff --git a/tests/src/Kernel/DefaultRoleEventIntegrationTest.php b/tests/src/Kernel/DefaultRoleEventIntegrationTest.php index c1d0b0530..5e0d14f7e 100644 --- a/tests/src/Kernel/DefaultRoleEventIntegrationTest.php +++ b/tests/src/Kernel/DefaultRoleEventIntegrationTest.php @@ -4,11 +4,13 @@ namespace Drupal\Tests\og\Kernel; +use Drupal\Core\Entity\EntityStorageInterface; use Drupal\KernelTests\KernelTestBase; use Drupal\og\Event\DefaultRoleEvent; use Drupal\og\Event\DefaultRoleEventInterface; use Drupal\og\Og; use Drupal\og\OgRoleInterface; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Tests the implementation of the DefaultRoleEvent in the 'og' module. @@ -25,23 +27,23 @@ class DefaultRoleEventIntegrationTest extends KernelTestBase { /** * The Symfony event dispatcher. * - * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface + * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface|null */ - protected $eventDispatcher; + protected ?EventDispatcherInterface $eventDispatcher; /** * The group bundle ID of the test group. * - * @var string + * @var string|null */ - protected $groupBundleId; + protected ?string $groupBundleId; /** * The OG role storage handler. * - * @var \Drupal\Core\Entity\EntityStorageInterface + * @var \Drupal\Core\Entity\EntityStorageInterface|null */ - protected $ogRoleStorage; + protected ?EntityStorageInterface $ogRoleStorage; /** * {@inheritdoc} @@ -62,8 +64,7 @@ protected function setUp(): void { /** * Tests that OG correctly provides the group administrator default role. */ - public function testPermissionEventIntegration() { - /** @var \Drupal\og\Event\DefaultRoleEvent $event */ + public function testPermissionEventIntegration(): void { $event = new DefaultRoleEvent(); // Query the event listener directly to see if the administrator role is diff --git a/tests/src/Kernel/PermissionEventTest.php b/tests/src/Kernel/PermissionEventTest.php index 98e164158..8c90ba912 100644 --- a/tests/src/Kernel/PermissionEventTest.php +++ b/tests/src/Kernel/PermissionEventTest.php @@ -14,6 +14,7 @@ use Drupal\og\OgAccess; use Drupal\og\OgRoleInterface; use Drupal\og\PermissionInterface; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Tests the implementations of the PermissionEvent in 'og' and 'og_ui'. @@ -37,16 +38,16 @@ class PermissionEventTest extends KernelTestBase { /** * The Symfony event dispatcher. * - * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface + * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface|null */ - protected $eventDispatcher; + protected ?EventDispatcherInterface $eventDispatcher; /** * The bundle ID used for the test group. * - * @var string + * @var string|null */ - protected $groupBundleId; + protected ?string $groupBundleId; /** * {@inheritdoc} @@ -94,7 +95,7 @@ protected function setUp(): void { * * @dataProvider permissionEventDataProvider */ - public function testPermissionEventIntegration(array $group_content_bundle_ids, array $expected_permissions, array $expected_full_permissions) { + public function testPermissionEventIntegration(array $group_content_bundle_ids, array $expected_permissions, array $expected_full_permissions): void { // Retrieve the permissions from the listeners. /** @var \Drupal\og\Event\PermissionEvent $permission_event */ $event = new PermissionEvent($this->randomMachineName(), $this->randomMachineName(), $group_content_bundle_ids); @@ -131,7 +132,7 @@ public function testPermissionEventIntegration(array $group_content_bundle_ids, * permission data for each entry, testing the data for only 1 or 2 * permissions is sufficient. */ - public function permissionEventDataProvider() { + public function permissionEventDataProvider(): array { // Test permissions that should be available for both test groups. $default_permissions = [ 'add user', @@ -246,7 +247,7 @@ public function permissionEventDataProvider() { * * @see t() */ - public function t($string, array $args = [], array $options = []) { + protected function t($string, array $args = [], array $options = []): FormattableMarkup { return new FormattableMarkup($string, $args); } @@ -258,7 +259,7 @@ public function t($string, array $args = [], array $options = []) { * @param \Drupal\og\PermissionInterface $actual * The actual permission. */ - protected function assertPermission(PermissionInterface $expected, PermissionInterface $actual) { + protected function assertPermission(PermissionInterface $expected, PermissionInterface $actual): void { foreach ($this->getPermissionProperties($expected) as $property) { $this->assertEquals($expected->get($property), $actual->get($property), "The $property property is equal."); } @@ -270,10 +271,10 @@ protected function assertPermission(PermissionInterface $expected, PermissionInt * @param \Drupal\og\PermissionInterface $permission * The Permission object for which to return the properties. * - * @return array + * @return string[] * An array of property names. */ - protected function getPermissionProperties(PermissionInterface $permission) { + protected function getPermissionProperties(PermissionInterface $permission): array { $shared_permissions = [ 'default roles', 'description', diff --git a/tests/src/Unit/GroupTypeManagerTest.php b/tests/src/Unit/GroupTypeManagerTest.php index 41a1d0b98..b954624f2 100644 --- a/tests/src/Unit/GroupTypeManagerTest.php +++ b/tests/src/Unit/GroupTypeManagerTest.php @@ -164,7 +164,7 @@ public function testInstance() { * * @dataProvider providerTestIsGroup */ - public function testIsGroup($entity_type_id, $bundle_id, $expected_result) { + public function testIsGroup($entity_type_id, $bundle_id, $expected_result): void { // It is expected that the group map will be retrieved from config. $groups = ['test_entity' => ['a', 'b']]; $this->expectGroupMapRetrieval($groups); @@ -181,7 +181,7 @@ public function testIsGroup($entity_type_id, $bundle_id, $expected_result) { * array with the entity type ID, bundle ID and boolean indicating the * expected result. */ - public function providerTestIsGroup() { + public function providerTestIsGroup(): array { return [ ['test_entity', 'a', TRUE], ['test_entity', 'b', TRUE], @@ -196,7 +196,7 @@ public function providerTestIsGroup() { * * @covers ::getGroupBundleIdsByEntityType */ - public function testGetGroupBundleIdsByEntityType() { + public function testGetGroupBundleIdsByEntityType(): void { // It is expected that the group map will be retrieved from config. $groups = ['test_entity' => ['a', 'b']]; $this->expectGroupMapRetrieval($groups); @@ -212,7 +212,7 @@ public function testGetGroupBundleIdsByEntityType() { * * @covers ::addGroup */ - public function testAddGroupExisting() { + public function testAddGroupExisting(): void { // It is expected that the group map will be retrieved from config. $groups_before = ['test_entity' => ['a', 'b']]; $this->expectGroupMapRetrieval($groups_before); @@ -241,7 +241,7 @@ public function testAddGroupExisting() { * * @covers ::addGroup */ - public function testAddGroupNew() { + public function testAddGroupNew(): void { $this->configFactory->getEditable('og.settings') ->willReturn($this->config->reveal()) ->shouldBeCalled(); @@ -282,7 +282,7 @@ public function testAddGroupNew() { * * @covers ::addGroup */ - public function testRemoveGroup() { + public function testRemoveGroup(): void { $this->configFactory->getEditable('og.settings') ->willReturn($this->config->reveal()) ->shouldBeCalled(); @@ -318,7 +318,7 @@ public function testRemoveGroup() { * @return \Drupal\og\GroupTypeManagerInterface * Returns the group manager. */ - protected function createGroupManager() { + protected function createGroupManager(): GroupTypeManagerInterface { return new GroupTypeManager( $this->configFactory->reveal(), $this->entityTypeManager->reveal(), @@ -338,7 +338,7 @@ protected function createGroupManager() { * @param array $groups * The expected group map that will be returned by the mocked config. */ - protected function expectGroupMapRetrieval(array $groups = []) { + protected function expectGroupMapRetrieval(array $groups = []): void { $this->configFactory->get('og.settings') ->willReturn($this->config->reveal()) ->shouldBeCalled(); diff --git a/tests/src/Unit/OgAdminRoutesControllerTest.php b/tests/src/Unit/OgAdminRoutesControllerTest.php index 396f07b40..af30eeeb5 100644 --- a/tests/src/Unit/OgAdminRoutesControllerTest.php +++ b/tests/src/Unit/OgAdminRoutesControllerTest.php @@ -185,7 +185,7 @@ protected function setUp(): void { * * @covers ::overview */ - public function testRoutesWithNoAccess() { + public function testRoutesWithNoAccess(): void { $result = $this->getRenderElementResult(FALSE); $this->assertEquals('You do not have any administrative items.', $result['#markup']); } @@ -195,14 +195,13 @@ public function testRoutesWithNoAccess() { * * @covers ::overview */ - public function testRoutesWithAccess() { + public function testRoutesWithAccess(): void { $result = $this->getRenderElementResult(TRUE); foreach ($result['og_admin_routes']['#content'] as $key => $value) { $this->assertEquals($this->routesInfo[$key]['title'], $value['title']); $this->assertEquals($this->routesInfo[$key]['description'], $value['description']); } - } /** @@ -214,7 +213,7 @@ public function testRoutesWithAccess() { * @return array * The render array. */ - protected function getRenderElementResult($allow_access) { + protected function getRenderElementResult($allow_access): array { $parameters = [$this->entityTypeId => $this->entityId]; foreach (array_keys($this->routesInfo) as $name) { $route_name = "entity.{$this->entityTypeId}.og_admin_routes.$name";