Skip to content

Commit

Permalink
Fix PhpStan
Browse files Browse the repository at this point in the history
  • Loading branch information
blankse committed Apr 23, 2024
1 parent 8105221 commit 83297c9
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 93 deletions.
55 changes: 0 additions & 55 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
count: 1
path: src/ActionTrigger/EventHandler/DefaultEventHandler.php

-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
count: 1
path: src/Controller/Admin/ActivitiesController.php

-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
count: 2
path: src/Controller/Admin/CustomersController.php

-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
count: 1
path: src/Controller/Admin/DuplicatesController.php

-
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\\.$#"
reportUnmatched: false
Expand All @@ -37,11 +17,6 @@ parameters:
count: 1
path: src/CustomerView/DefaultCustomerView.php

-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
count: 1
path: src/DuplicatesIndex/DefaultMariaDbDuplicatesIndex.php

-
message: "#^Result of && is always false\\.$#"
count: 1
Expand Down Expand Up @@ -107,41 +82,11 @@ parameters:
count: 1
path: src/Newsletter/ProviderHandler/Mailchimp/CliSyncProcessor.php

-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
count: 2
path: src/Newsletter/Queue/DefaultNewsletterQueue.php

-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
count: 1
path: src/RESTApi/CustomersHandler.php

-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
count: 1
path: src/RESTApi/SegmentGroupsHandler.php

-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
count: 1
path: src/RESTApi/SegmentsHandler.php

-
message: "#^Call to an undefined method CustomerManagementFrameworkBundle\\\\RESTApi\\\\SegmentsOfCustomerHandler\\:\\:createRoute\\(\\)\\.$#"
count: 1
path: src/RESTApi/SegmentsOfCustomerHandler.php

-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
count: 1
path: src/SegmentBuilder/AgeSegmentBuilder.php

-
message: "#^Call to an undefined method Knp\\\\Component\\\\Pager\\\\Pagination\\\\PaginationInterface\\:\\:getPaginationData\\(\\)\\.$#"
count: 1
path: src/SegmentManager/SegmentBuilderExecutor/DefaultSegmentBuilderExecutor.php

-
message: "#^If condition is always false\\.$#"
count: 1
Expand Down
17 changes: 10 additions & 7 deletions src/ActionTrigger/EventHandler/DefaultEventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use CustomerManagementFrameworkBundle\Model\ActionTrigger\Rule;
use CustomerManagementFrameworkBundle\Model\CustomerInterface;
use CustomerManagementFrameworkBundle\Traits\LoggerAware;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
use Knp\Component\Pager\PaginatorInterface;
use Pimcore;
use Pimcore\Model\DataObject\Service;
Expand Down Expand Up @@ -114,15 +115,17 @@ public function handleCustomerListEvent(CustomerListEventInterface $event, RuleE
sprintf('handleCustomerListEvent: found %s matching customers', $paginator->getTotalItemCount())
);

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

foreach ($paginator as $customer) {
$this->handleActionsForCustomer($rule, $customer, $environment);
}
foreach ($paginator as $customer) {
$this->handleActionsForCustomer($rule, $customer, $environment);
}

Pimcore::collectGarbage();
Pimcore::collectGarbage();
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/Admin/ActivitiesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use CustomerManagementFrameworkBundle\ActivityStore\MariaDb;
use CustomerManagementFrameworkBundle\CustomerProvider\CustomerProviderInterface;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
use Knp\Component\Pager\PaginatorInterface;
use Pimcore\Controller\KernelControllerEventInterface;
use Pimcore\Controller\UserAwareController;
Expand Down Expand Up @@ -78,7 +79,7 @@ public function listAction(Request $request, CustomerProviderInterface $customer
'types' => $types,
'selectedType' => $type,
'activities' => $paginator,
'paginationVariables' => $paginator->getPaginationData(),
'paginationVariables' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData() : [],
'customer' => $customer,
'activityView' => \Pimcore::getContainer()->get('cmf.activity_view'),
]
Expand Down
21 changes: 12 additions & 9 deletions src/DuplicatesIndex/DefaultMariaDbDuplicatesIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use CustomerManagementFrameworkBundle\Factory;
use CustomerManagementFrameworkBundle\Model\CustomerInterface;
use CustomerManagementFrameworkBundle\Traits\LoggerAware;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
use Knp\Component\Pager\PaginatorInterface;
use Pimcore\Db;
use Pimcore\Logger;
Expand Down Expand Up @@ -107,18 +108,20 @@ public function recreateIndex()
$paginator = $this->paginator->paginate($customerList);
$paginator->setItemNumberPerPage(200);

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

foreach ($paginator as $customer) {
$logger->notice(sprintf('update index for %s', (string)$customer));
foreach ($paginator as $customer) {
$logger->notice(sprintf('update index for %s', (string)$customer));

$this->updateDuplicateIndexForCustomer($customer, true);
}
$this->updateDuplicateIndexForCustomer($customer, true);
}

\Pimcore::collectGarbage();
\Pimcore::collectGarbage();
}
}
}

Expand Down
31 changes: 17 additions & 14 deletions src/Newsletter/Queue/DefaultNewsletterQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use CustomerManagementFrameworkBundle\Newsletter\Queue\Item\DefaultNewsletterQueueItem;
use CustomerManagementFrameworkBundle\Newsletter\Queue\Item\NewsletterQueueItemInterface;
use CustomerManagementFrameworkBundle\Traits\ApplicationLoggerAware;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
use Knp\Component\Pager\PaginatorInterface;
use Pimcore\Db;
use Pimcore\Model\DataObject\Service;
Expand Down Expand Up @@ -213,24 +214,26 @@ protected function processAllItems(array $newsletterProviderHandlers, $forceUpda
$list = $customerProvider->getList();

$paginator = $this->paginator->paginate($list, 1, $this->maxItemsPerRound);
$pageCount = $paginator->getPaginationData()['pageCount'];
if ($paginator instanceof SlidingPaginationInterface) {
$pageCount = $paginator->getPaginationData()['pageCount'];

for ($i = 1; $i <= $pageCount; $i++) {
$paginator = $this->paginator->paginate($list, $i, $this->maxItemsPerRound);
$items = [];
foreach ($paginator as $customer) {
if ($item = $this->createUpdateItem($customer)) {
$items[] = $item;
}
}

for ($i = 1; $i <= $pageCount; $i++) {
$paginator = $this->paginator->paginate($list, $i, $this->maxItemsPerRound);
$items = [];
foreach ($paginator as $customer) {
if ($item = $this->createUpdateItem($customer)) {
$items[] = $item;
try {
$this->processQueueItems($newsletterProviderHandlers, $items, $forceUpdate);
} catch (\Exception $e) {
$this->getLogger()->error('newsletter queue processing exception: ' . $e->getMessage());
}
}

try {
$this->processQueueItems($newsletterProviderHandlers, $items, $forceUpdate);
} catch (\Exception $e) {
$this->getLogger()->error('newsletter queue processing exception: ' . $e->getMessage());
\Pimcore::collectGarbage();
}

\Pimcore::collectGarbage();
}
}

Expand Down
15 changes: 9 additions & 6 deletions src/SegmentBuilder/AgeSegmentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use CustomerManagementFrameworkBundle\Model\CustomerInterface;
use CustomerManagementFrameworkBundle\SegmentManager\SegmentManagerInterface;
use CustomerManagementFrameworkBundle\Traits\LoggerAware;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
use Pimcore\Model\Tool\TmpStore;

class AgeSegmentBuilder extends AbstractSegmentBuilder
Expand Down Expand Up @@ -143,13 +144,15 @@ public function maintenance(SegmentManagerInterface $segmentManager)

$paginator = $this->paginator->paginate($list, 1, 100);

$pageCount = $paginator->getPaginationData()['pageCount'];
for ($i = 1; $i <= $pageCount; $i++) {
$paginator = $this->paginator->paginate($list, $i, 100);
if ($paginator instanceof SlidingPaginationInterface) {
$pageCount = $paginator->getPaginationData()['pageCount'];
for ($i = 1; $i <= $pageCount; $i++) {
$paginator = $this->paginator->paginate($list, $i, 100);

foreach ($paginator as $customer) {
$this->calculateSegments($customer, $segmentManager);
$segmentManager->saveMergedSegments($customer);
foreach ($paginator as $customer) {
$this->calculateSegments($customer, $segmentManager);
$segmentManager->saveMergedSegments($customer);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use CustomerManagementFrameworkBundle\SegmentBuilder\SegmentBuilderInterface;
use CustomerManagementFrameworkBundle\SegmentManager\SegmentManagerInterface;
use CustomerManagementFrameworkBundle\Traits\LoggerAware;
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
use Knp\Component\Pager\PaginatorInterface;
use Pimcore\Db;
use Pimcore\Model\DataObject\Concrete;
Expand Down Expand Up @@ -166,7 +167,10 @@ public function buildCalculatedSegments(
$paginator = $this->paginator->paginate($idList, 1, $pageSize);

$totalAmount = $paginator->getTotalItemCount();
$totalPages = $paginator->getPaginationData()['pageCount'];
$totalPages = 0;
if ($paginator instanceof SlidingPaginationInterface) {
$totalPages = $paginator->getPaginationData()['pageCount'];
}

$startPage = $desiredStartPage !== null && $desiredStartPage > 0 ? min($totalPages, $desiredStartPage) : 1;
$endPage = $totalPages;
Expand Down

0 comments on commit 83297c9

Please sign in to comment.