Skip to content

Commit

Permalink
Remove old phpstan-warnings and add some validation to fix others php…
Browse files Browse the repository at this point in the history
…stan-warnings
  • Loading branch information
vcsvinicius committed Nov 7, 2024
1 parent 53e9aa7 commit 82ec521
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public function __construct(EntityReferenceInterface $parent) {
* {@inheritdoc}
*/
public function configureField(BaseFieldDefinition $entity_reference): void {
if (!isset($this->parent)) {
throw new \LogicException('Using EntityReferenceTrait without assigning a parent or overwriting the methods.');
}
$this->parent->configureField($entity_reference);

$handler_settings = $entity_reference->getSetting('handler_settings');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public function __construct(
* {@inheritdoc}
*/
public function getGroupOperations(GroupInterface $group) {
if (!isset($this->parent)) {
throw new \LogicException('Using OperationProviderTrait without assigning a parent or overwriting the methods.');
}
$operations = $this->parent->getGroupOperations($group);

if (!$group->getMember($this->currentUser) && $group->hasPermission('request group membership', $this->currentUser)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public function __construct(PermissionProviderInterface $parent) {
* {@inheritdoc}
*/
public function getPermission($operation, $target, $scope = 'any') {
if (!isset($this->parent)) {
throw new \LogicException('Using PermissionProviderTrait without assigning a parent or overwriting the methods.');
}

// The following permissions are handled by the admin permission or have a
// different permission name.
if ($target === 'relationship') {
Expand All @@ -44,6 +48,9 @@ public function getPermission($operation, $target, $scope = 'any') {
* {@inheritdoc}
*/
public function buildPermissions() {
if (!isset($this->parent)) {
throw new \LogicException('Using PermissionProviderTrait without assigning a parent or overwriting the methods.');
}
$permissions = $this->parent->buildPermissions();

// Update the title to make user friendly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ public function __construct(PostInstallInterface $parent, EntityTypeManagerInter
* {@inheritdoc}
*/
public function getInstallTasks() {
if (!isset($this->parent)) {
throw new \LogicException('Using PostInstallTrait without assigning a parent or overwriting the methods.');
}

$tasks = $this->parent->getInstallTasks();
$tasks['install-group-membership-request-fields'] = [$this, 'installGroupMembershipRequestFields'];

return $tasks;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public function __construct(AccessControlInterface $parent) {
* {@inheritdoc}
*/
public function entityAccess(EntityInterface $entity, $operation, AccountInterface $account, $return_as_object = FALSE) {
if (!isset($this->parent)) {
throw new \LogicException('Using AccessControlTrait without assigning a parent or overwriting the methods.');
}

// We only care about Update (/edit) of the Event content.
if ($operation !== 'update') {
return $this->parent->entityAccess($entity, $operation, $account, $return_as_object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public function __construct(AccessControlInterface $parent) {
* {@inheritdoc}
*/
public function relationshipAccess(GroupRelationshipInterface $group_relationship, $operation, AccountInterface $account, $return_as_object = FALSE): bool|AccessResultInterface {
if (!isset($this->parent)) {
throw new \LogicException('Using AccessControlTrait without assigning a parent or overwriting the methods.');
}

// User who receives the invite should be able to view it.
if ($group_relationship->getEntityId() === $account->id()) {
return AccessResult::allowed();
Expand Down
35 changes: 0 additions & 35 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1572,31 +1572,6 @@ parameters:
count: 1
path: modules/custom/grequest/src/Form/GroupRequestMembershipRejectForm.php

-
message: "#^Cannot call method configureField\\(\\) on Drupal\\\\group\\\\Plugin\\\\Group\\\\RelationHandler\\\\RelationHandlerInterface\\|null\\.$#"
count: 1
path: modules/custom/grequest/src/Plugin/Group/RelationHandler/GroupMembershipRequestEntityReference.php

-
message: "#^Cannot call method getGroupOperations\\(\\) on Drupal\\\\group\\\\Plugin\\\\Group\\\\RelationHandler\\\\RelationHandlerInterface\\|null\\.$#"
count: 1
path: modules/custom/grequest/src/Plugin/Group/RelationHandler/GroupMembershipRequestOperationProvider.php

-
message: "#^Cannot call method buildPermissions\\(\\) on Drupal\\\\group\\\\Plugin\\\\Group\\\\RelationHandler\\\\RelationHandlerInterface\\|null\\.$#"
count: 1
path: modules/custom/grequest/src/Plugin/Group/RelationHandler/GroupMembershipRequestPermissionProvider.php

-
message: "#^Cannot call method getPermission\\(\\) on Drupal\\\\group\\\\Plugin\\\\Group\\\\RelationHandler\\\\RelationHandlerInterface\\|null\\.$#"
count: 1
path: modules/custom/grequest/src/Plugin/Group/RelationHandler/GroupMembershipRequestPermissionProvider.php

-
message: "#^Cannot call method getInstallTasks\\(\\) on Drupal\\\\group\\\\Plugin\\\\Group\\\\RelationHandler\\\\RelationHandlerInterface\\|null\\.$#"
count: 1
path: modules/custom/grequest/src/Plugin/Group/RelationHandler/GroupMembershipRequestPostInstall.php

-
message: "#^Function group_core_comments_install\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -5753,11 +5728,6 @@ parameters:
count: 1
path: modules/social_features/social_event/modules/social_event_managers/src/Plugin/Action/SocialEventManagersSendEmail.php

-
message: "#^Cannot call method entityAccess\\(\\) on Drupal\\\\group\\\\Plugin\\\\Group\\\\RelationHandler\\\\RelationHandlerInterface\\|null\\.$#"
count: 3
path: modules/social_features/social_event/modules/social_event_managers/src/Plugin/Group/RelationHandler/EventsGroupContentAccessControl.php

-
message: "#^Method Drupal\\\\social_event_managers\\\\Plugin\\\\views\\\\access\\\\ManageByOrganizersOnlyAccess\\:\\:alterRouteDefinition\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -7787,11 +7757,6 @@ parameters:
count: 2
path: modules/social_features/social_group/modules/social_group_invite/src/Plugin/Block/SocialInviteLocalActionsBlock.php

-
message: "#^Cannot call method relationshipAccess\\(\\) on Drupal\\\\group\\\\Plugin\\\\Group\\\\RelationHandler\\\\RelationHandlerInterface\\|null\\.$#"
count: 1
path: modules/social_features/social_group/modules/social_group_invite/src/Plugin/Group/RelationHandler/SocialGroupInviteAccessControl.php

-
message: "#^Method Drupal\\\\social_group_invite\\\\Plugin\\\\Join\\\\SocialGroupInviteJoin\\:\\:create\\(\\) should return static\\(Drupal\\\\social_group_invite\\\\Plugin\\\\Join\\\\SocialGroupInviteJoin\\) but returns Drupal\\\\social_group_invite\\\\Plugin\\\\Join\\\\SocialGroupInviteJoin\\.$#"
count: 1
Expand Down

0 comments on commit 82ec521

Please sign in to comment.