Skip to content

Commit 3bc2cbe

Browse files
authored
Fix PhpStan (#533)
1 parent 8105221 commit 3bc2cbe

File tree

13 files changed

+79
-112
lines changed

13 files changed

+79
-112
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
5-
count: 1
6-
path: src/ActionTrigger/EventHandler/DefaultEventHandler.php
7-
8-
-
9-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
10-
count: 1
11-
path: src/Controller/Admin/ActivitiesController.php
12-
13-
-
14-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
15-
count: 2
16-
path: src/Controller/Admin/CustomersController.php
17-
18-
-
19-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
20-
count: 1
21-
path: src/Controller/Admin/DuplicatesController.php
22-
233
-
244
message: "#^Parameter \\#1 \\$segments of class CustomerManagementFrameworkBundle\\\\CustomerList\\\\Filter\\\\CustomerSegment constructor expects array\\<Pimcore\\\\Model\\\\DataObject\\\\CustomerSegment\\>, array\\<int\\<0, max\\>, CustomerManagementFrameworkBundle\\\\Model\\\\CustomerSegmentInterface\\> given\\.$#"
255
reportUnmatched: false
@@ -37,11 +17,6 @@ parameters:
3717
count: 1
3818
path: src/CustomerView/DefaultCustomerView.php
3919

40-
-
41-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
42-
count: 1
43-
path: src/DuplicatesIndex/DefaultMariaDbDuplicatesIndex.php
44-
4520
-
4621
message: "#^Result of && is always false\\.$#"
4722
count: 1
@@ -107,41 +82,11 @@ parameters:
10782
count: 1
10883
path: src/Newsletter/ProviderHandler/Mailchimp/CliSyncProcessor.php
10984

110-
-
111-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
112-
count: 2
113-
path: src/Newsletter/Queue/DefaultNewsletterQueue.php
114-
115-
-
116-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
117-
count: 1
118-
path: src/RESTApi/CustomersHandler.php
119-
120-
-
121-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
122-
count: 1
123-
path: src/RESTApi/SegmentGroupsHandler.php
124-
125-
-
126-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
127-
count: 1
128-
path: src/RESTApi/SegmentsHandler.php
129-
13085
-
13186
message: "#^Call to an undefined method CustomerManagementFrameworkBundle\\\\RESTApi\\\\SegmentsOfCustomerHandler\\:\\:createRoute\\(\\)\\.$#"
13287
count: 1
13388
path: src/RESTApi/SegmentsOfCustomerHandler.php
13489

135-
-
136-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
137-
count: 1
138-
path: src/SegmentBuilder/AgeSegmentBuilder.php
139-
140-
-
141-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
142-
count: 1
143-
path: src/SegmentManager/SegmentBuilderExecutor/DefaultSegmentBuilderExecutor.php
144-
14590
-
14691
message: "#^If condition is always false\\.$#"
14792
count: 1

src/ActionTrigger/EventHandler/DefaultEventHandler.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use CustomerManagementFrameworkBundle\Model\ActionTrigger\Rule;
2727
use CustomerManagementFrameworkBundle\Model\CustomerInterface;
2828
use CustomerManagementFrameworkBundle\Traits\LoggerAware;
29+
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
2930
use Knp\Component\Pager\PaginatorInterface;
3031
use Pimcore;
3132
use Pimcore\Model\DataObject\Service;
@@ -114,15 +115,17 @@ public function handleCustomerListEvent(CustomerListEventInterface $event, RuleE
114115
sprintf('handleCustomerListEvent: found %s matching customers', $paginator->getTotalItemCount())
115116
);
116117

117-
$totalPages = $paginator->getPaginationData()['totalCount'];
118-
for ($i = 1; $i <= $totalPages; $i++) {
119-
$paginator = $this->paginator->paginate($listing, $i, 100);
118+
if ($paginator instanceof SlidingPaginationInterface) {
119+
$totalPages = $paginator->getPaginationData()['totalCount'];
120+
for ($i = 1; $i <= $totalPages; $i++) {
121+
$paginator = $this->paginator->paginate($listing, $i, 100);
120122

121-
foreach ($paginator as $customer) {
122-
$this->handleActionsForCustomer($rule, $customer, $environment);
123-
}
123+
foreach ($paginator as $customer) {
124+
$this->handleActionsForCustomer($rule, $customer, $environment);
125+
}
124126

125-
Pimcore::collectGarbage();
127+
Pimcore::collectGarbage();
128+
}
126129
}
127130
}
128131
}

src/Controller/Admin/ActivitiesController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
use CustomerManagementFrameworkBundle\ActivityStore\MariaDb;
1919
use CustomerManagementFrameworkBundle\CustomerProvider\CustomerProviderInterface;
20+
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
2021
use Knp\Component\Pager\PaginatorInterface;
2122
use Pimcore\Controller\KernelControllerEventInterface;
2223
use Pimcore\Controller\UserAwareController;
@@ -78,7 +79,7 @@ public function listAction(Request $request, CustomerProviderInterface $customer
7879
'types' => $types,
7980
'selectedType' => $type,
8081
'activities' => $paginator,
81-
'paginationVariables' => $paginator->getPaginationData(),
82+
'paginationVariables' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData() : [],
8283
'customer' => $customer,
8384
'activityView' => \Pimcore::getContainer()->get('cmf.activity_view'),
8485
]

src/Controller/Admin/CustomersController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use CustomerManagementFrameworkBundle\Model\CustomerInterface;
2828
use CustomerManagementFrameworkBundle\Model\CustomerSegmentInterface;
2929
use CustomerManagementFrameworkBundle\Model\CustomerView\FilterDefinition;
30+
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
3031
use Pimcore\Db;
3132
use Pimcore\Model\DataObject\AbstractObject;
3233
use Pimcore\Model\DataObject\Concrete;
@@ -96,7 +97,7 @@ public function listAction(Request $request): Response
9697
if ($request->isXmlHttpRequest()) {
9798
return $this->render($customerView->getOverviewWrapperTemplate(), [
9899
'paginator' => $paginator,
99-
'paginationVariables' => $paginator->getPaginationData(),
100+
'paginationVariables' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData() : [],
100101
'customerView' => $customerView,
101102
'idField' => Service::getVersionDependentDatabaseColumnName('id')
102103
]);
@@ -108,7 +109,7 @@ public function listAction(Request $request): Response
108109
'filters' => $filters,
109110
'errors' => $errors,
110111
'paginator' => $paginator,
111-
'paginationVariables' => $paginator->getPaginationData(),
112+
'paginationVariables' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData() : [],
112113
'customerView' => $customerView,
113114
'searchBarFields' => $this->getSearchHelper()->getConfiguredSearchBarFields(),
114115
'request' => $request,

src/Controller/Admin/DuplicatesController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use CustomerManagementFrameworkBundle\Controller\Admin;
1919
use CustomerManagementFrameworkBundle\CustomerList\SearchHelper;
2020
use CustomerManagementFrameworkBundle\DuplicatesIndex\DuplicatesIndexInterface;
21+
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
2122
use Pimcore\Model\DataObject\AbstractObject;
2223
use Pimcore\Model\DataObject\Service;
2324
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -76,7 +77,7 @@ public function listAction(Request $request, DuplicatesIndexInterface $duplicate
7677
'@PimcoreCustomerManagementFramework/admin/duplicates/list.html.twig',
7778
[
7879
'paginator' => $paginator,
79-
'paginationVariables' => $paginator->getPaginationData(),
80+
'paginationVariables' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData() : [],
8081
'duplicates' => $paginator->getItems(),
8182
'duplicatesView' => \Pimcore::getContainer()->get('cmf.customer_duplicates_view'),
8283
'searchBarFields' => $this->getSearchHelper()->getConfiguredSearchBarFields(),

src/DuplicatesIndex/DefaultMariaDbDuplicatesIndex.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use CustomerManagementFrameworkBundle\Factory;
2222
use CustomerManagementFrameworkBundle\Model\CustomerInterface;
2323
use CustomerManagementFrameworkBundle\Traits\LoggerAware;
24+
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
2425
use Knp\Component\Pager\PaginatorInterface;
2526
use Pimcore\Db;
2627
use Pimcore\Logger;
@@ -107,18 +108,20 @@ public function recreateIndex()
107108
$paginator = $this->paginator->paginate($customerList);
108109
$paginator->setItemNumberPerPage(200);
109110

110-
$totalPages = $paginator->getPaginationData()['pageCount'];
111-
for ($pageNumber = 1; $pageNumber <= $totalPages; $pageNumber++) {
112-
$logger->notice(sprintf('execute page %s of %s', $pageNumber, $totalPages));
113-
$paginator = $this->paginator->paginate($customerList, $pageNumber, 200);
111+
if ($paginator instanceof SlidingPaginationInterface) {
112+
$totalPages = $paginator->getPaginationData()['pageCount'];
113+
for ($pageNumber = 1; $pageNumber <= $totalPages; $pageNumber++) {
114+
$logger->notice(sprintf('execute page %s of %s', $pageNumber, $totalPages));
115+
$paginator = $this->paginator->paginate($customerList, $pageNumber, 200);
114116

115-
foreach ($paginator as $customer) {
116-
$logger->notice(sprintf('update index for %s', (string)$customer));
117+
foreach ($paginator as $customer) {
118+
$logger->notice(sprintf('update index for %s', (string)$customer));
117119

118-
$this->updateDuplicateIndexForCustomer($customer, true);
119-
}
120+
$this->updateDuplicateIndexForCustomer($customer, true);
121+
}
120122

121-
\Pimcore::collectGarbage();
123+
\Pimcore::collectGarbage();
124+
}
122125
}
123126
}
124127

src/Newsletter/Queue/DefaultNewsletterQueue.php

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use CustomerManagementFrameworkBundle\Newsletter\Queue\Item\DefaultNewsletterQueueItem;
2323
use CustomerManagementFrameworkBundle\Newsletter\Queue\Item\NewsletterQueueItemInterface;
2424
use CustomerManagementFrameworkBundle\Traits\ApplicationLoggerAware;
25+
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
2526
use Knp\Component\Pager\PaginatorInterface;
2627
use Pimcore\Db;
2728
use Pimcore\Model\DataObject\Service;
@@ -213,24 +214,26 @@ protected function processAllItems(array $newsletterProviderHandlers, $forceUpda
213214
$list = $customerProvider->getList();
214215

215216
$paginator = $this->paginator->paginate($list, 1, $this->maxItemsPerRound);
216-
$pageCount = $paginator->getPaginationData()['pageCount'];
217-
218-
for ($i = 1; $i <= $pageCount; $i++) {
219-
$paginator = $this->paginator->paginate($list, $i, $this->maxItemsPerRound);
220-
$items = [];
221-
foreach ($paginator as $customer) {
222-
if ($item = $this->createUpdateItem($customer)) {
223-
$items[] = $item;
217+
if ($paginator instanceof SlidingPaginationInterface) {
218+
$pageCount = $paginator->getPaginationData()['pageCount'];
219+
220+
for ($i = 1; $i <= $pageCount; $i++) {
221+
$paginator = $this->paginator->paginate($list, $i, $this->maxItemsPerRound);
222+
$items = [];
223+
foreach ($paginator as $customer) {
224+
if ($item = $this->createUpdateItem($customer)) {
225+
$items[] = $item;
226+
}
224227
}
225-
}
226228

227-
try {
228-
$this->processQueueItems($newsletterProviderHandlers, $items, $forceUpdate);
229-
} catch (\Exception $e) {
230-
$this->getLogger()->error('newsletter queue processing exception: ' . $e->getMessage());
231-
}
229+
try {
230+
$this->processQueueItems($newsletterProviderHandlers, $items, $forceUpdate);
231+
} catch (\Exception $e) {
232+
$this->getLogger()->error('newsletter queue processing exception: ' . $e->getMessage());
233+
}
232234

233-
\Pimcore::collectGarbage();
235+
\Pimcore::collectGarbage();
236+
}
234237
}
235238
}
236239

@@ -249,20 +252,22 @@ protected function processItemsFromQueue(array $newsletterProviderHandlers, $for
249252
$rows = $db->fetchAllAssociative((string)$select);
250253

251254
$paginator = $this->paginator->paginate($rows, 1, $this->maxItemsPerRound);
252-
$pageCount = $paginator->getPaginationData()['pageCount'];
253-
254-
for ($i = 1; $i <= $pageCount; $i++) {
255-
$paginator = $this->paginator->paginate($rows, $i, $this->maxItemsPerRound);
256-
$items = [];
257-
foreach ($paginator as $row) {
258-
if ($item = $this->createItemFromData($row)) {
259-
$items[] = $item;
255+
if ($paginator instanceof SlidingPaginationInterface) {
256+
$pageCount = $paginator->getPaginationData()['pageCount'];
257+
258+
for ($i = 1; $i <= $pageCount; $i++) {
259+
$paginator = $this->paginator->paginate($rows, $i, $this->maxItemsPerRound);
260+
$items = [];
261+
foreach ($paginator as $row) {
262+
if ($item = $this->createItemFromData($row)) {
263+
$items[] = $item;
264+
}
260265
}
261-
}
262266

263-
$this->processQueueItems($newsletterProviderHandlers, $items, $forceUpdate);
267+
$this->processQueueItems($newsletterProviderHandlers, $items, $forceUpdate);
264268

265-
\Pimcore::collectGarbage();
269+
\Pimcore::collectGarbage();
270+
}
266271
}
267272
}
268273

src/RESTApi/ActivitiesHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use CustomerManagementFrameworkBundle\RESTApi\Traits\ResourceUrlGenerator;
2525
use CustomerManagementFrameworkBundle\RESTApi\Traits\ResponseGenerator;
2626
use CustomerManagementFrameworkBundle\Traits\LoggerAware;
27+
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
2728
use Symfony\Component\HttpFoundation\Request;
2829

2930
class ActivitiesHandler extends AbstractHandler implements CrudHandlerInterface
@@ -56,7 +57,7 @@ public function listRecords(Request $request)
5657

5758
$result = [
5859
'page' => $page,
59-
'totalPages' => $paginator->getPaginationData()['pageCount'],
60+
'totalPages' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData()['pageCount'] : 0,
6061
'timestamp' => $timestamp,
6162
'data' => [],
6263
];

src/RESTApi/CustomersHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use CustomerManagementFrameworkBundle\RESTApi\Traits\ResourceUrlGenerator;
2323
use CustomerManagementFrameworkBundle\RESTApi\Traits\ResponseGenerator;
2424
use CustomerManagementFrameworkBundle\Traits\LoggerAware;
25+
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
2526
use Knp\Component\Pager\PaginatorInterface;
2627
use Pimcore\Model\DataObject\Customer;
2728
use Pimcore\Model\DataObject\Service;
@@ -89,7 +90,7 @@ public function listRecords(Request $request)
8990
return new Response(
9091
[
9192
'page' => $paginator->getCurrentPageNumber(),
92-
'totalPages' => $paginator->getPaginationData()['pageCount'],
93+
'totalPages' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData()['pageCount'] : 0,
9394
'timestamp' => $timestamp,
9495
'data' => $result,
9596
]

src/RESTApi/SegmentGroupsHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use CustomerManagementFrameworkBundle\RESTApi\Traits\ResponseGenerator;
2121
use CustomerManagementFrameworkBundle\Service\ObjectToArray;
2222
use CustomerManagementFrameworkBundle\Traits\LoggerAware;
23+
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
2324
use Pimcore\Model\DataObject\CustomerSegmentGroup;
2425
use Pimcore\Model\DataObject\Service;
2526
use Symfony\Component\HttpFoundation\Request;
@@ -57,7 +58,7 @@ public function listRecords(Request $request)
5758
return new Response(
5859
[
5960
'page' => $paginator->getCurrentPageNumber(),
60-
'totalPages' => $paginator->getPaginationData()['pageCount'],
61+
'totalPages' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData()['pageCount'] : 0,
6162
'timestamp' => $timestamp,
6263
'data' => $result,
6364
]

0 commit comments

Comments
 (0)