/**
  * @param StaticSegment $staticSegment
  * @param string $segmentStateFilter
  * @param string $method
  * @param string $itemState
  * @param bool $deleteMember
  * @return array
  */
 public function handleMembersUpdate(StaticSegment $staticSegment, $segmentStateFilter, $method, $itemState, $deleteMember = false)
 {
     $itemsToWrite = [];
     $items = $staticSegment->getSegmentMembers()->filter(function (StaticSegmentMember $segmentMember) use($segmentStateFilter) {
         return $segmentMember->getState() === $segmentStateFilter;
     })->toArray();
     if (empty($items)) {
         return [];
     }
     $emails = array_map(function (StaticSegmentMember $segmentMember) {
         return $segmentMember->getMember()->getEmail();
     }, $items);
     $response = $this->transport->{$method}(['id' => $staticSegment->getSubscribersList()->getOriginId(), 'seg_id' => (int) $staticSegment->getOriginId(), 'batch' => array_map(function ($email) {
         return ['email' => $email];
     }, $emails), 'delete_member' => $deleteMember]);
     $this->handleResponse($response, function ($response, LoggerInterface $logger) use($staticSegment) {
         $logger->info(sprintf('Segment #%s [origin_id=%s] Members: [%s] add, [%s] error', $staticSegment->getId(), $staticSegment->getOriginId(), $response['success_count'], $response['error_count']));
     });
     $emailsWithErrors = $this->getArrayData($response, 'errors');
     /** @var StaticSegmentMember[]|ArrayCollection $items */
     $items = new ArrayCollection($items);
     $items->filter(function (StaticSegmentMember $segmentMember) use($emailsWithErrors) {
         return !in_array($segmentMember->getMember()->getEmail(), $emailsWithErrors, true);
     });
     foreach ($items as $item) {
         $item->setState($itemState);
         $this->logger->debug(sprintf('Member with id "%s" and email "%s" got "%s" state', $item->getMember()->getOriginId(), $item->getMember()->getEmail(), $itemState));
         $itemsToWrite[] = $item;
     }
     return $itemsToWrite;
 }
 /**
  * @param StaticSegment $staticSegment
  */
 protected function handleDroppedMembers(StaticSegment $staticSegment)
 {
     $qb = $this->doctrineHelper->getEntityRepository($this->staticSegmentMember)->createQueryBuilder('smmb');
     $qb->delete($this->staticSegmentMember, 'smmb')->where($qb->expr()->andX($qb->expr()->eq('smmb.staticSegment', $staticSegment->getId()), $qb->expr()->in('smmb.state', ':states')))->setParameter('states', [StaticSegmentMember::STATE_DROP, StaticSegmentMember::STATE_UNSUBSCRIBE_DELETE])->getQuery()->execute();
 }
 public function testId()
 {
     $this->assertNull($this->entity->getId());
 }