Issues (14)

src/Service/CustomerManager.php (1 issue)

Labels
Severity
1
<?php
2
3
4
namespace PTS\SyliusReferralPlugin\Service;
5
6
7
use Doctrine\ORM\EntityManager;
8
use PTS\SyliusReferralPlugin\Entity\Customer;
9
use Sylius\Component\Core\Model\ShopUser;
10
use Symfony\Component\HttpFoundation\Request;
11
12
class CustomerManager
13
{
14
    private $entityManager;
15
16
    public function __construct(EntityManager $entityManager)
17
    {
18
        $this->entityManager = $entityManager;
19
    }
20
21
    public function getCustomerReferrals(Request $request, $route, $id)
22
    {
23
        $customer = $this->entityManager->getRepository(Customer::class)->findOneBy(['id' => $id]);
24
        if ($customer) {
25
            $page = $request->get('page');
26
            $data = $this->getPaginatedCustomers($customer, $page, $route, $id);
27
            return $data;
28
        }
29
    }
30
    public function getEnroller($id) {
31
        $customerRepo = $this->entityManager->getRepository(Customer::class);
32
        /** @var Customer $customer */
33
        $customer = $customerRepo->findOneBy(['id' => $id]);
34
        if ($enroller = $customer->getEnroller()) {
35
            return $enroller;
36
        }
37
        return null;
38
    }
39
40
    public function getPaginatedCustomers($enroller, $page, $routeName, $id = null)
41
    {
42
        if (!$page || $page < 0) {
43
            $page = 1;
44
        }
45
        $limit = 7;
46
        $customers = $this->entityManager
47
            ->getRepository(Customer::class)
48
            ->getEnrolled($enroller, $limit, floor($page));
0 ignored issues
show
The method getEnrolled() does not exist on Doctrine\Common\Persistence\ObjectRepository. It seems like you code against a sub-type of Doctrine\Common\Persistence\ObjectRepository such as Doctrine\ORM\EntityRepository or Sylius\Bundle\ResourceBu...ne\ORM\EntityRepository or Sylius\Bundle\CoreBundle...\ORM\ShipmentRepository or Sylius\Bundle\CoreBundle...ppingCategoryRepository or Sylius\Bundle\PromotionB...omotionCouponRepository or Sylius\Bundle\TaxationBu...M\TaxCategoryRepository or Sylius\Bundle\TaxonomyBu...ine\ORM\TaxonRepository or Sylius\Bundle\CoreBundle...\ProductTaxonRepository or Sylius\Bundle\CoreBundle...e\ORM\PaymentRepository or Sylius\Bundle\ShippingBu...hippingMethodRepository or Sylius\Bundle\CoreBundle...hippingMethodRepository or Sylius\Bundle\ProductBun...roductVariantRepository or Sylius\Bundle\CoreBundle...roductVariantRepository or Sylius\Bundle\PromotionB...ORM\PromotionRepository or Sylius\Bundle\CoreBundle...ORM\PromotionRepository or Sylius\Bundle\ChannelBun...e\ORM\ChannelRepository or Sylius\Bundle\OrderBundl...ine\ORM\OrderRepository or Sylius\Bundle\CoreBundle...ine\ORM\OrderRepository or Sylius\Bundle\PaymentBun...PaymentMethodRepository or Sylius\Bundle\CoreBundle...PaymentMethodRepository or Sylius\Bundle\CoreBundle...M\AvatarImageRepository or Sylius\Bundle\ProductBun...ProductOptionRepository or Sylius\Bundle\CoreBundle...ProductReviewRepository or Sylius\Bundle\OrderBundl...ORM\OrderItemRepository or Sylius\Bundle\CoreBundle...e\ORM\AddressRepository or Sylius\Bundle\ProductBun...ttributeValueRepository or Sylius\Bundle\ProductBun...e\ORM\ProductRepository or Sylius\Bundle\CoreBundle...e\ORM\ProductRepository or Sylius\Bundle\CoreBundle...rine\ORM\UserRepository or Sylius\Bundle\UserBundle...rine\ORM\UserRepository or Sylius\Bundle\CoreBundle...\ORM\CustomerRepository or Sylius\Bundle\CurrencyBu...\ExchangeRateRepository or Sylius\Bundle\ProductBun...sociationTypeRepository. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
            ->/** @scrutinizer ignore-call */ getEnrolled($enroller, $limit, floor($page));
Loading history...
49
        $maxPages = ceil($customers->count() / $limit);
50
        $thisPage = (int)$page;
51
        if ($maxPages < $thisPage) {
52
            $thisPage = $maxPages;
53
        }
54
55
        return [
56
            'customers' => iterator_to_array($customers->getIterator()),
57
            'pagination' => [
58
                'maxPages' => $maxPages,
59
                'thisPage' => $thisPage,
60
                'route' => $routeName,
61
                'id' => $id
62
            ]
63
        ];
64
    }
65
    public function changeCustomerEnroller($customerId, $enrollerId)
66
    {
67
        $customerRepo = $this->entityManager
68
            ->getRepository(Customer::class);
69
        /** @var Customer $customer */
70
        $customer = $customerRepo
71
            ->findOneBy(['id' => $customerId]);
72
        $enroller = $customerRepo
73
            ->findOneBy(['id' => $enrollerId]);
74
        $customer->setEnroller($enroller);
75
        $this->entityManager->flush();
76
    }
77
78
}