Skip to content

Commit

Permalink
Update phpstan.neon
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-getopensocial committed Dec 17, 2024
1 parent 4fa7116 commit 3932726
Show file tree
Hide file tree
Showing 185 changed files with 468 additions and 510 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function getRecipientOrganizerFromEntity(array $related_entity, array $da
&& $original_related_object['target_type'] === 'event_enrollment'
&& $related_entity !== NULL) {
$storage = $this->entityTypeManager->getStorage($related_entity['target_type']);
/** @var EventEnrollmentInterface|NULL $event */
/** @var \Drupal\social_event\EventEnrollmentInterface|NULL $event */
$event = $storage->load($related_entity['target_id']);

if ($event === NULL) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Drupal\activity_creator\ActivityFactory;
use Drupal\activity_creator\Plugin\ActivityContextBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Query\Sql\QueryFactory;
use Drupal\group\Entity\GroupInterface;
Expand Down Expand Up @@ -120,7 +119,7 @@ public function getRecipientOwnerFromEntity(array $related_entity, array $data):
$recipients = [];

$entity_storage = $this->entityTypeManager->getStorage($related_entity['target_type']);
/** @var EntityOwnerInterface|NULL $entity */
/** @var \Drupal\user\EntityOwnerInterface|NULL $entity */
$entity = $entity_storage->load($related_entity['target_id']);

// It could happen that a notification has been queued but the content
Expand All @@ -134,7 +133,7 @@ public function getRecipientOwnerFromEntity(array $related_entity, array $data):
$original_related_object = $data['related_object'][0];
if (isset($original_related_object['target_type']) && $original_related_object['target_type'] === 'comment') {
$storage = $this->entityTypeManager->getStorage($original_related_object['target_type']);
/** @var EntityOwnerInterface $original_related_entity */
/** @var \Drupal\user\EntityOwnerInterface $original_related_entity */
$original_related_entity = $storage->load($original_related_object['target_id']);

if ($original_related_entity !== NULL && $original_related_entity->getOwnerId() === $entity->getOwnerId()) {
Expand All @@ -144,7 +143,7 @@ public function getRecipientOwnerFromEntity(array $related_entity, array $data):

if ($entity instanceof EntityOwnerInterface) {
$account = $entity->getOwner();
/** @var EntityInterface $entity */
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$group = $this->groupMuteNotify->getGroupByContent($entity);
// Check if we have $group set which means that this content was
// posted in a group.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Drupal\activity_basics\Plugin\ActivityContext;

use Drupal\activity_creator\Plugin\ActivityContextBase;
use Drupal\user\EntityOwnerInterface;

/**
* Provides a 'OwnerActivityContext' activity context.
Expand Down Expand Up @@ -37,7 +36,7 @@ public function getRecipients(array $data, int $last_id, int $limit): array {

// Add the owner of the related entity as a recipient.
// No owner found set user 1.
/** @var EntityOwnerInterface $entity*/
/** @var \Drupal\user\EntityOwnerInterface $entity*/
$recipients[] = [
'target_type' => 'user',
'target_id' => $entity->getOwnerId() ?? 1,
Expand Down
2 changes: 1 addition & 1 deletion modules/custom/activity_creator/activity_creator.module
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function activity_creator_activity_insert(ActivityInterface $activity): void {
// notifications.
if (in_array('notifications', $activity->getDestinations(), TRUE)) {
// Get recipients.
/** @var Activity $activity */
/** @var \Drupal\activity_creator\Entity\Activity $activity */
$recipients = $activity->getRecipient();

if (is_array($recipients)) {
Expand Down
3 changes: 2 additions & 1 deletion modules/custom/activity_creator/src/ActivityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\activity_creator;

use Drupal\Core\Url;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\user\EntityOwnerInterface;
Expand Down Expand Up @@ -59,7 +60,7 @@ public function setPublished(bool $published): ActivityInterface;
* @return \Drupal\Core\Url|string
* Empty string if entity canonical url could not be found.
*/
public function getRelatedEntityUrl(): string|\Drupal\Core\Url;
public function getRelatedEntityUrl(): string|Url;

/**
* Get destinations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function getNotificationListCallback(): AjaxResponse {
? '0'
: (string) count($this->activities->getNotifications($this->currentUser()));

// $notification_count = $this->activities->markAllNotificationsAsSeen($this->currentUser()) ? 0 : count($this->activities->getNotifications($this->currentUser()));
$response->addCommand(new HtmlCommand('.notification-bell .badge', $notification_count));

return $response;
Expand Down
19 changes: 9 additions & 10 deletions modules/custom/activity_creator/src/Entity/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Drupal\activity_creator\Entity;

use Drupal\Core\Entity\EntityInterface;
use Drupal\user\EntityOwnerInterface;
use Drupal\Core\Config\Entity\ConfigEntityStorage;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
Expand All @@ -11,11 +13,8 @@
use Drupal\activity_creator\ActivityInterface;
use Drupal\Core\Url;
use Drupal\flag\Entity\Flagging;
use Drupal\group\Entity\Storage\GroupRelationshipStorage;
use Drupal\user\UserInterface;
use Drupal\node\NodeInterface;
use Drupal\votingapi\Entity\Vote;
use Drupal\votingapi\VoteStorage;

/**
* Defines the Activity entity.
Expand Down Expand Up @@ -94,7 +93,7 @@ public function setCreatedTime(int $timestamp): ActivityInterface|static {
* {@inheritdoc}
*/
public function getOwner(): UserInterface {
/** @var UserInterface $user */
/** @var \Drupal\user\UserInterface $user */
$user = $this->get('user_id')->entity;
return $user;
}
Expand All @@ -109,15 +108,15 @@ public function getOwnerId(): ?int {
/**
* {@inheritdoc}
*/
public function setOwnerId($uid): \Drupal\user\EntityOwnerInterface|Activity|static {
public function setOwnerId($uid): EntityOwnerInterface|Activity|static {
$this->set('user_id', $uid);
return $this;
}

/**
* {@inheritdoc}
*/
public function setOwner(UserInterface $account): \Drupal\user\EntityOwnerInterface|Activity|static {
public function setOwner(UserInterface $account): EntityOwnerInterface|Activity|static {
$this->set('user_id', $account->id());
return $this;
}
Expand Down Expand Up @@ -207,7 +206,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
* @return \Drupal\Core\Entity\EntityInterface|null
* Returns NULL or Entity object.
*/
public function getRelatedEntity(): ?\Drupal\Core\Entity\EntityInterface {
public function getRelatedEntity(): ?EntityInterface {
$related_object = $this->get('field_activity_entity')->getValue();
if (!empty($related_object)) {
$target_type = $related_object['0']['target_type'];
Expand Down Expand Up @@ -249,16 +248,16 @@ public function getRelatedEntityUrl(): string|Url {

// Make an exception for Votes.
if ($target_type === 'vote') {
/** @var VoteStorage $vote_storage */
/** @var \Drupal\votingapi\VoteStorage $vote_storage */
$vote_storage = \Drupal::entityTypeManager()->getStorage($target_type);
if ($vote = $vote_storage->load($target_id)) {
/** @var Vote $vote */
/** @var \Drupal\votingapi\Entity\Vote $vote */
$target_type = $vote->getVotedEntityType();
$target_id = $vote->getVotedEntityId();
}
}
elseif ($target_type === 'group_content') {
/** @var GroupRelationshipStorage $group_content_storage */
/** @var \Drupal\group\Entity\Storage\GroupRelationshipStorage $group_content_storage */
$group_content_storage = \Drupal::service('entity_type.manager')->getStorage($target_type);
if ($group_content = $group_content_storage->load($target_id)) {
/** @var \Drupal\group\Entity\GroupRelationship $group_content */
Expand Down
7 changes: 0 additions & 7 deletions modules/custom/activity_creator/src/Form/ActivityForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
*/
class ActivityForm extends ContentEntityForm {

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state): array {
return parent::buildForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Drupal\activity_logger\Entity\NotificationConfigEntityInterface;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityBase;
use Drupal\Core\Entity\EntityInterface;

/**
Expand All @@ -29,7 +28,7 @@ public function createMessage(EntityInterface $entity): void {
// Use the queue logger.
$activity_logger_factory = \Drupal::service('activity_logger.activity_factory');
// Create messages for all other types of content.
/** @var EntityBase $entity */
/** @var \Drupal\Core\Entity\EntityBase $entity */
$activity_logger_factory->createMessages($entity, $this->pluginId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\system\Entity\Action;

/**
* Defines an interface for Activity action plugins.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Component\Utility\Html;
use Drupal\activity_creator\Annotation\ActivityEntityCondition;

/**
* Provides the Activity entity condition plugin manager.
Expand All @@ -24,7 +25,7 @@ class ActivityEntityConditionManager extends DefaultPluginManager {
* The module handler to invoke the alter hook with.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/ActivityEntityCondition', $namespaces, $module_handler, 'Drupal\activity_creator\Plugin\ActivityEntityConditionInterface', 'Drupal\activity_creator\Annotation\ActivityEntityCondition');
parent::__construct('Plugin/ActivityEntityCondition', $namespaces, $module_handler, ActivityEntityConditionInterface::class, ActivityEntityCondition::class);

$this->alterInfo('activity_creator_activity_entity_condition_info');
$this->setCacheBackend($cache_backend, 'activity_creator_activity_entity_condition_plugins');
Expand All @@ -40,7 +41,7 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
* An associative array mapping the IDs of all available tracker plugins to
* their labels.
*/
public function getOptionsList(array $entities = []) {
public function getOptionsList(array $entities = []): array {
$options = [];

foreach ($entities as $entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Drupal\activity_creator\Plugin\QueueWorker;

use Drupal\Core\State\StateInterface;

/**
* A report worker.
*
Expand All @@ -22,7 +24,7 @@ class ActivityWorkerLogger extends ActivityWorkerBase {
*
* @var \Drupal\Core\State\StateInterface
*/
protected \Drupal\Core\State\StateInterface $state;
protected StateInterface $state;

/**
* {@inheritdoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Drupal\activity_logger\Plugin\QueueWorker;

use Drupal\activity_creator\Plugin\ActivityActionInterface;
use Drupal\activity_creator\Plugin\ActivityActionManager;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueFactory;
Expand Down Expand Up @@ -84,7 +83,7 @@ public function processItem($data): void {
else {
// Trigger the creation action for entities.
if ($this->actionManager->hasDefinition('create_entitiy_action')) {
/** @var ActivityActionInterface $create_action */
/** @var \Drupal\activity_creator\Plugin\ActivityActionInterface $create_action */
$create_action = $this->actionManager->createInstance('create_entitiy_action');
$create_action->createMessage($entity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

namespace Drupal\activity_logger\Service;

use Drupal\activity_creator\Plugin\ActivityContextInterface;
use Drupal\activity_creator\Plugin\ActivityContextManager;
use Drupal\activity_creator\Plugin\ActivityEntityConditionInterface;
use Drupal\activity_creator\Plugin\ActivityEntityConditionManager;
use Drupal\activity_logger\Entity\NotificationConfigEntityInterface;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\field\FieldConfigInterface;
Expand Down Expand Up @@ -120,7 +115,7 @@ public function createMessages(EntityBase $entity, string $action): void {
$new_message['field_message_destination'] = $destinations;

if ($entity instanceof NotificationConfigEntityInterface) {
/** @var EntityBase $entity_base */
/** @var \Drupal\Core\Entity\EntityBase $entity_base */
$entity_base = $entity;
$new_message['field_message_related_object'] = [
'target_type' => $entity_base->getEntityTypeId(),
Expand All @@ -129,18 +124,18 @@ public function createMessages(EntityBase $entity, string $action): void {
$new_message['created'] = $entity->getCreatedTime();
}
else {
/** @var EntityInterface $entity */
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$new_message['field_message_related_object'] = [
'target_type' => $entity->getEntityTypeId(),
'target_id' => $entity->id(),
];
// The flagging entity does not implement getCreatedTime().
if ($entity->getEntityTypeId() === 'flagging') {
/** @var ContentEntityInterface $entity */
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$new_message['created'] = $entity->get('created')->value;
}
else {
/** @var NotificationConfigEntityInterface $entity */
/** @var \Drupal\activity_logger\Entity\NotificationConfigEntityInterface $entity */
$new_message['created'] = $entity->getCreatedTime();
}
}
Expand Down Expand Up @@ -178,12 +173,12 @@ public function getMessageTypes(string $action, EntityBase $entity): array {

// Check all enabled messages.
foreach ($message_storage->loadByProperties(['status' => '1']) as $key => $message_type) {
/** @var ConfigEntityBase $message_type */
/** @var \Drupal\Core\Config\Entity\ConfigEntityBase $message_type */
$mt_entity_bundles = $message_type->getThirdPartySetting('activity_logger', 'activity_bundle_entities', []);
$mt_action = $message_type->getThirdPartySetting('activity_logger', 'activity_action', NULL);
$mt_context = $message_type->getThirdPartySetting('activity_logger', 'activity_context', NULL);
$mt_destinations = $message_type->getThirdPartySetting('activity_logger', 'activity_destinations', NULL);
$mt_entity_condition = $message_type->getThirdPartySetting('activity_logger', 'activity_entity_condition', NULL);
$mt_entity_condition = (string) $message_type->getThirdPartySetting('activity_logger', 'activity_entity_condition', NULL);

if ($mt_action !== $action) {
continue;
Expand All @@ -198,19 +193,22 @@ public function getMessageTypes(string $action, EntityBase $entity): array {
continue;
}

/** @var ActivityEntityConditionInterface $entity_condition */
/** @var ContentEntityInterface $entity */
$entity_condition = $this->activityEntityConditionManager->createInstance($mt_entity_condition);
if (
!empty($mt_entity_condition)
&& $this->activityEntityConditionManager->hasDefinition($mt_entity_condition)
&& !$entity_condition->isValidEntityCondition($entity)
) {
if (!empty($mt_entity_condition)) {
continue;
}

/** @var ActivityContextInterface $context_plugin */
if ($this->activityEntityConditionManager->hasDefinition($mt_entity_condition)) {
continue;
}

/** @var \Drupal\activity_creator\Plugin\ActivityEntityConditionInterface $context_plugin */
$context_plugin = $this->activityContextManager->createInstance($mt_context);
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
if (!$context_plugin->isValidEntityCondition($entity)) {
continue;
}

/** @var \Drupal\activity_creator\Plugin\ActivityContextInterface $context_plugin */
if ($context_plugin->isValidEntity($entity)) {
$message_types[$key] = [
'messagetype' => $message_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ function activity_send_email_form_user_form_alter(array &$form, FormStateInterfa

$user_email_settings = EmailActivityDestination::getSendEmailUserSettings($account);


foreach ($items as $item_id => $item) {
// Don't render the fieldset when there are no templates.
if (empty($item['templates'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public function getInterval(): int;
* @param string|null $body_text
* The output text of message.
*/
public function processItem(Activity $activity, Message $message, User $target, ?string$body_text = NULL): void ;
public function processItem(Activity $activity, Message $message, User $target, ?string $body_text = NULL): void;

}
Loading

0 comments on commit 3932726

Please sign in to comment.