Use PHPStan generics
[MAILPOET-2900]
This commit is contained in:
@ -6,11 +6,7 @@ use MailPoet\Doctrine\Repository;
|
|||||||
use MailPoet\Entities\NewsletterLinkEntity;
|
use MailPoet\Entities\NewsletterLinkEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method NewsletterLinkEntity[] findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null)
|
* @extends Repository<NewsletterLinkEntity>
|
||||||
* @method NewsletterLinkEntity|null findOneBy(array $criteria, array $orderBy = null)
|
|
||||||
* @method NewsletterLinkEntity|null findOneById(mixed $id)
|
|
||||||
* @method void persist(NewsletterLinkEntity $entity)
|
|
||||||
* @method void remove(NewsletterLinkEntity $entity)
|
|
||||||
*/
|
*/
|
||||||
class NewsletterLinkRepository extends Repository {
|
class NewsletterLinkRepository extends Repository {
|
||||||
protected function getEntityClassName() {
|
protected function getEntityClassName() {
|
||||||
|
@ -7,6 +7,9 @@ use MailPoet\Entities\ScheduledTaskEntity;
|
|||||||
use MailPoet\Entities\StatsNotificationEntity;
|
use MailPoet\Entities\StatsNotificationEntity;
|
||||||
use MailPoetVendor\Carbon\Carbon;
|
use MailPoetVendor\Carbon\Carbon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends Repository<StatsNotificationEntity>
|
||||||
|
*/
|
||||||
class StatsNotificationsRepository extends Repository {
|
class StatsNotificationsRepository extends Repository {
|
||||||
protected function getEntityClassName() {
|
protected function getEntityClassName() {
|
||||||
return StatsNotificationEntity::class;
|
return StatsNotificationEntity::class;
|
||||||
|
@ -6,12 +6,7 @@ use MailPoet\Doctrine\Repository;
|
|||||||
use MailPoet\Entities\CustomFieldEntity;
|
use MailPoet\Entities\CustomFieldEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method CustomFieldEntity[] findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null)
|
* @extends Repository<CustomFieldEntity>
|
||||||
* @method CustomFieldEntity[] findAll()
|
|
||||||
* @method CustomFieldEntity|null findOneBy(array $criteria, array $orderBy = null)
|
|
||||||
* @method CustomFieldEntity|null findOneById(mixed $id)
|
|
||||||
* @method void persist(CustomFieldEntity $entity)
|
|
||||||
* @method void remove(CustomFieldEntity $entity)
|
|
||||||
*/
|
*/
|
||||||
class CustomFieldsRepository extends Repository {
|
class CustomFieldsRepository extends Repository {
|
||||||
protected function getEntityClassName() {
|
protected function getEntityClassName() {
|
||||||
|
@ -7,6 +7,9 @@ use MailPoetVendor\Doctrine\ORM\EntityManager;
|
|||||||
use MailPoetVendor\Doctrine\ORM\EntityRepository as DoctrineEntityRepository;
|
use MailPoetVendor\Doctrine\ORM\EntityRepository as DoctrineEntityRepository;
|
||||||
use MailPoetVendor\Doctrine\ORM\Mapping\ClassMetadata;
|
use MailPoetVendor\Doctrine\ORM\Mapping\ClassMetadata;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template T of object
|
||||||
|
*/
|
||||||
abstract class Repository {
|
abstract class Repository {
|
||||||
/** @var EntityManager */
|
/** @var EntityManager */
|
||||||
protected $entityManager;
|
protected $entityManager;
|
||||||
@ -28,7 +31,7 @@ abstract class Repository {
|
|||||||
* @param array|null $orderBy
|
* @param array|null $orderBy
|
||||||
* @param int|null $limit
|
* @param int|null $limit
|
||||||
* @param int|null $offset
|
* @param int|null $offset
|
||||||
* @return array
|
* @return T[]
|
||||||
*/
|
*/
|
||||||
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) {
|
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) {
|
||||||
return $this->doctrineRepository->findBy($criteria, $orderBy, $limit, $offset);
|
return $this->doctrineRepository->findBy($criteria, $orderBy, $limit, $offset);
|
||||||
@ -37,7 +40,7 @@ abstract class Repository {
|
|||||||
/**
|
/**
|
||||||
* @param array $criteria
|
* @param array $criteria
|
||||||
* @param array|null $orderBy
|
* @param array|null $orderBy
|
||||||
* @return object|null
|
* @return T|null
|
||||||
*/
|
*/
|
||||||
public function findOneBy(array $criteria, array $orderBy = null) {
|
public function findOneBy(array $criteria, array $orderBy = null) {
|
||||||
return $this->doctrineRepository->findOneBy($criteria, $orderBy);
|
return $this->doctrineRepository->findOneBy($criteria, $orderBy);
|
||||||
@ -45,21 +48,21 @@ abstract class Repository {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $id
|
* @param mixed $id
|
||||||
* @return object|null
|
* @return T|null
|
||||||
*/
|
*/
|
||||||
public function findOneById($id) {
|
public function findOneById($id) {
|
||||||
return $this->doctrineRepository->find($id);
|
return $this->doctrineRepository->find($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return T[]
|
||||||
*/
|
*/
|
||||||
public function findAll() {
|
public function findAll() {
|
||||||
return $this->doctrineRepository->findAll();
|
return $this->doctrineRepository->findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param object $entity
|
* @param T $entity
|
||||||
*/
|
*/
|
||||||
public function persist($entity) {
|
public function persist($entity) {
|
||||||
$this->entityManager->persist($entity);
|
$this->entityManager->persist($entity);
|
||||||
@ -78,7 +81,7 @@ abstract class Repository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param object $entity
|
* @param T $entity
|
||||||
*/
|
*/
|
||||||
public function remove($entity) {
|
public function remove($entity) {
|
||||||
$this->entityManager->remove($entity);
|
$this->entityManager->remove($entity);
|
||||||
@ -89,7 +92,7 @@ abstract class Repository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return class-string<T>
|
||||||
*/
|
*/
|
||||||
abstract protected function getEntityClassName();
|
abstract protected function getEntityClassName();
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,7 @@ use MailPoet\Doctrine\Repository;
|
|||||||
use MailPoet\Entities\FeatureFlagEntity;
|
use MailPoet\Entities\FeatureFlagEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method FeatureFlagEntity[] findAll()
|
* @extends Repository<FeatureFlagEntity>
|
||||||
* @method FeatureFlagEntity|null findOneBy(array $criteria, array $orderBy = null)
|
|
||||||
* @method void persist(FeatureFlagEntity $entity)
|
|
||||||
* @method void remove(FeatureFlagEntity $entity)
|
|
||||||
*/
|
*/
|
||||||
class FeatureFlagsRepository extends Repository {
|
class FeatureFlagsRepository extends Repository {
|
||||||
protected function getEntityClassName() {
|
protected function getEntityClassName() {
|
||||||
|
@ -6,12 +6,7 @@ use MailPoet\Doctrine\Repository;
|
|||||||
use MailPoet\Entities\FormEntity;
|
use MailPoet\Entities\FormEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method FormEntity[] findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null)
|
* @extends Repository<FormEntity>
|
||||||
* @method FormEntity[] findAll()
|
|
||||||
* @method FormEntity|null findOneBy(array $criteria, array $orderBy = null)
|
|
||||||
* @method FormEntity|null findOneById(mixed $id)
|
|
||||||
* @method void persist(FormEntity $entity)
|
|
||||||
* @method void remove(FormEntity $entity)
|
|
||||||
*/
|
*/
|
||||||
class FormsRepository extends Repository {
|
class FormsRepository extends Repository {
|
||||||
protected function getEntityClassName() {
|
protected function getEntityClassName() {
|
||||||
|
@ -6,11 +6,7 @@ use MailPoet\Doctrine\Repository;
|
|||||||
use MailPoet\Entities\NewsletterEntity;
|
use MailPoet\Entities\NewsletterEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method NewsletterEntity[] findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null)
|
* @extends Repository<NewsletterEntity>
|
||||||
* @method NewsletterEntity|null findOneBy(array $criteria, array $orderBy = null)
|
|
||||||
* @method NewsletterEntity|null findOneById(mixed $id)
|
|
||||||
* @method void persist(NewsletterEntity $entity)
|
|
||||||
* @method void remove(NewsletterEntity $entity)
|
|
||||||
*/
|
*/
|
||||||
class NewslettersRepository extends Repository {
|
class NewslettersRepository extends Repository {
|
||||||
protected function getEntityClassName() {
|
protected function getEntityClassName() {
|
||||||
|
@ -6,11 +6,7 @@ use MailPoet\Doctrine\Repository;
|
|||||||
use MailPoet\Entities\NewsletterOptionFieldEntity;
|
use MailPoet\Entities\NewsletterOptionFieldEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method NewsletterOptionFieldEntity[] findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null)
|
* @extends Repository<NewsletterOptionFieldEntity>
|
||||||
* @method NewsletterOptionFieldEntity|null findOneBy(array $criteria, array $orderBy = null)
|
|
||||||
* @method NewsletterOptionFieldEntity|null findOneById(mixed $id)
|
|
||||||
* @method void persist(NewsletterOptionFieldEntity $entity)
|
|
||||||
* @method void remove(NewsletterOptionFieldEntity $entity)
|
|
||||||
*/
|
*/
|
||||||
class NewsletterOptionFieldsRepository extends Repository {
|
class NewsletterOptionFieldsRepository extends Repository {
|
||||||
protected function getEntityClassName() {
|
protected function getEntityClassName() {
|
||||||
|
@ -6,11 +6,7 @@ use MailPoet\Doctrine\Repository;
|
|||||||
use MailPoet\Entities\NewsletterOptionEntity;
|
use MailPoet\Entities\NewsletterOptionEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method NewsletterOptionEntity[] findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null)
|
* @extends Repository<NewsletterOptionEntity>
|
||||||
* @method NewsletterOptionEntity|null findOneBy(array $criteria, array $orderBy = null)
|
|
||||||
* @method NewsletterOptionEntity|null findOneById(mixed $id)
|
|
||||||
* @method void persist(NewsletterOptionEntity $entity)
|
|
||||||
* @method void remove(NewsletterOptionEntity $entity)
|
|
||||||
*/
|
*/
|
||||||
class NewsletterOptionsRepository extends Repository {
|
class NewsletterOptionsRepository extends Repository {
|
||||||
protected function getEntityClassName() {
|
protected function getEntityClassName() {
|
||||||
|
@ -6,11 +6,7 @@ use MailPoet\Doctrine\Repository;
|
|||||||
use MailPoet\Entities\SendingQueueEntity;
|
use MailPoet\Entities\SendingQueueEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method SendingQueueEntity[] findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null)
|
* @extends Repository<SendingQueueEntity>
|
||||||
* @method SendingQueueEntity|null findOneBy(array $criteria, array $orderBy = null)
|
|
||||||
* @method SendingQueueEntity|null findOneById(mixed $id)
|
|
||||||
* @method void persist(SendingQueueEntity $entity)
|
|
||||||
* @method void remove(SendingQueueEntity $entity)
|
|
||||||
*/
|
*/
|
||||||
class SendingQueuesRepository extends Repository {
|
class SendingQueuesRepository extends Repository {
|
||||||
protected function getEntityClassName() {
|
protected function getEntityClassName() {
|
||||||
|
@ -13,6 +13,9 @@ use MailPoet\WooCommerce\Helper as WCHelper;
|
|||||||
use MailPoetVendor\Doctrine\ORM\EntityManager;
|
use MailPoetVendor\Doctrine\ORM\EntityManager;
|
||||||
use MailPoetVendor\Doctrine\ORM\UnexpectedResultException;
|
use MailPoetVendor\Doctrine\ORM\UnexpectedResultException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends Repository<NewsletterEntity>
|
||||||
|
*/
|
||||||
class NewsletterStatisticsRepository extends Repository {
|
class NewsletterStatisticsRepository extends Repository {
|
||||||
|
|
||||||
/** @var WCHelper */
|
/** @var WCHelper */
|
||||||
|
@ -9,11 +9,7 @@ use MailPoet\Entities\NewsletterTemplateEntity;
|
|||||||
use function MailPoetVendor\array_column;
|
use function MailPoetVendor\array_column;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method NewsletterTemplateEntity[] findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null)
|
* @extends Repository<NewsletterTemplateEntity>
|
||||||
* @method NewsletterTemplateEntity|null findOneBy(array $criteria, array $orderBy = null)
|
|
||||||
* @method NewsletterTemplateEntity|null findOneById(mixed $id)
|
|
||||||
* @method void persist(NewsletterTemplateEntity $entity)
|
|
||||||
* @method void remove(NewsletterTemplateEntity $entity)
|
|
||||||
*/
|
*/
|
||||||
class NewsletterTemplatesRepository extends Repository {
|
class NewsletterTemplatesRepository extends Repository {
|
||||||
const RECENTLY_SENT_CATEGORIES = '["recent"]';
|
const RECENTLY_SENT_CATEGORIES = '["recent"]';
|
||||||
|
@ -6,11 +6,7 @@ use MailPoet\Doctrine\Repository;
|
|||||||
use MailPoet\Entities\SegmentEntity;
|
use MailPoet\Entities\SegmentEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method SegmentEntity[] findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null)
|
* @extends Repository<SegmentEntity>
|
||||||
* @method SegmentEntity|null findOneBy(array $criteria, array $orderBy = null)
|
|
||||||
* @method SegmentEntity|null findOneById(mixed $id)
|
|
||||||
* @method void persist(SegmentEntity $entity)
|
|
||||||
* @method void remove(SegmentEntity $entity)
|
|
||||||
*/
|
*/
|
||||||
class SegmentsRepository extends Repository {
|
class SegmentsRepository extends Repository {
|
||||||
protected function getEntityClassName() {
|
protected function getEntityClassName() {
|
||||||
|
@ -8,12 +8,7 @@ use MailPoet\WP\Functions as WPFunctions;
|
|||||||
use MailPoetVendor\Carbon\Carbon;
|
use MailPoetVendor\Carbon\Carbon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method SettingEntity[] findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null)
|
* @extends Repository<SettingEntity>
|
||||||
* @method SettingEntity|null findOneBy(array $criteria, array $orderBy = null)
|
|
||||||
* @method SettingEntity|null findOneById(mixed $id)
|
|
||||||
* @method SettingEntity[] findAll()
|
|
||||||
* @method void persist(SettingEntity $entity)
|
|
||||||
* @method void remove(SettingEntity $entity)
|
|
||||||
*/
|
*/
|
||||||
class SettingsRepository extends Repository {
|
class SettingsRepository extends Repository {
|
||||||
public function findOneByName($name) {
|
public function findOneByName($name) {
|
||||||
|
@ -6,11 +6,7 @@ use MailPoet\Doctrine\Repository;
|
|||||||
use MailPoet\Entities\UserFlagEntity;
|
use MailPoet\Entities\UserFlagEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method UserFlagEntity[] findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null)
|
* @extends Repository<UserFlagEntity>
|
||||||
* @method UserFlagEntity|null findOneBy(array $criteria, array $orderBy = null)
|
|
||||||
* @method UserFlagEntity|null findOneById(mixed $id)
|
|
||||||
* @method void persist(UserFlagEntity $entity)
|
|
||||||
* @method void remove(UserFlagEntity $entity)
|
|
||||||
*/
|
*/
|
||||||
class UserFlagsRepository extends Repository {
|
class UserFlagsRepository extends Repository {
|
||||||
protected function getEntityClassName() {
|
protected function getEntityClassName() {
|
||||||
|
@ -6,11 +6,7 @@ use MailPoet\Doctrine\Repository;
|
|||||||
use MailPoet\Entities\StatisticsUnsubscribeEntity;
|
use MailPoet\Entities\StatisticsUnsubscribeEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method StatisticsUnsubscribeEntity[] findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null)
|
* @extends Repository<StatisticsUnsubscribeEntity>
|
||||||
* @method StatisticsUnsubscribeEntity|null findOneBy(array $criteria, array $orderBy = null)
|
|
||||||
* @method StatisticsUnsubscribeEntity|null findOneById(mixed $id)
|
|
||||||
* @method void persist(StatisticsUnsubscribeEntity $entity)
|
|
||||||
* @method void remove(StatisticsUnsubscribeEntity $entity)
|
|
||||||
*/
|
*/
|
||||||
class StatisticsUnsubscribesRepository extends Repository {
|
class StatisticsUnsubscribesRepository extends Repository {
|
||||||
protected function getEntityClassName() {
|
protected function getEntityClassName() {
|
||||||
|
@ -6,11 +6,7 @@ use MailPoet\Doctrine\Repository;
|
|||||||
use MailPoet\Entities\StatisticsWooCommercePurchaseEntity;
|
use MailPoet\Entities\StatisticsWooCommercePurchaseEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method StatisticsWooCommercePurchaseEntity[] findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null)
|
* @extends Repository<StatisticsWooCommercePurchaseEntity>
|
||||||
* @method StatisticsWooCommercePurchaseEntity|null findOneBy(array $criteria, array $orderBy = null)
|
|
||||||
* @method StatisticsWooCommercePurchaseEntity|null findOneById(mixed $id)
|
|
||||||
* @method void persist(StatisticsWooCommercePurchaseEntity $entity)
|
|
||||||
* @method void remove(StatisticsWooCommercePurchaseEntity $entity)
|
|
||||||
*/
|
*/
|
||||||
class StatisticsWooCommercePurchasesRepository extends Repository {
|
class StatisticsWooCommercePurchasesRepository extends Repository {
|
||||||
protected function getEntityClassName() {
|
protected function getEntityClassName() {
|
||||||
|
@ -6,11 +6,7 @@ use MailPoet\Doctrine\Repository;
|
|||||||
use MailPoet\Entities\SubscriberEntity;
|
use MailPoet\Entities\SubscriberEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method SubscriberEntity[] findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null)
|
* @extends Repository<SubscriberEntity>
|
||||||
* @method SubscriberEntity|null findOneBy(array $criteria, array $orderBy = null)
|
|
||||||
* @method SubscriberEntity|null findOneById(mixed $id)
|
|
||||||
* @method void persist(SubscriberEntity $entity)
|
|
||||||
* @method void remove(SubscriberEntity $entity)
|
|
||||||
*/
|
*/
|
||||||
class SubscribersRepository extends Repository {
|
class SubscribersRepository extends Repository {
|
||||||
protected function getEntityClassName() {
|
protected function getEntityClassName() {
|
||||||
|
@ -15,6 +15,9 @@ parameters:
|
|||||||
- '#Parameter \#1 \$function of function call_user_func_array expects callable(): mixed, .wc_.*. given.#'
|
- '#Parameter \#1 \$function of function call_user_func_array expects callable(): mixed, .wc_.*. given.#'
|
||||||
- '#Parameter \#1 \$reader of class MailPoetVendor\\Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver constructor expects MailPoetVendor\\Doctrine\\Common\\Annotations\\AnnotationReader, MailPoetVendor\\Doctrine\\Common\\Annotations\\CachedReader given#'
|
- '#Parameter \#1 \$reader of class MailPoetVendor\\Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver constructor expects MailPoetVendor\\Doctrine\\Common\\Annotations\\AnnotationReader, MailPoetVendor\\Doctrine\\Common\\Annotations\\CachedReader given#'
|
||||||
- '/(with|has) no (return )?typehint specified/' # exclude level 6 errors
|
- '/(with|has) no (return )?typehint specified/' # exclude level 6 errors
|
||||||
|
|
||||||
|
# Doctrine repository annotates return values as object|null, we override them to specific generics (T|null)
|
||||||
|
- '#Method MailPoet\\Doctrine\\Repository::findOneBy(Id)?\(\) should return T of object\|null but returns object\|null\.#'
|
||||||
reportUnmatchedIgnoredErrors: false
|
reportUnmatchedIgnoredErrors: false
|
||||||
dynamicConstantNames:
|
dynamicConstantNames:
|
||||||
- WP_DEBUG
|
- WP_DEBUG
|
||||||
|
Reference in New Issue
Block a user