ErroneousMessageIterator::findNextMessages()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\NotificationBundle\Iterator;
15
16
use Sonata\NotificationBundle\Model\MessageInterface;
17
use Sonata\NotificationBundle\Model\MessageManagerInterface;
18
19
class ErroneousMessageIterator extends MessageManagerMessageIterator
20
{
21
    /**
22
     * @var int
23
     */
24
    protected $maxAttempts;
25
26
    /**
27
     * @var int
28
     */
29
    protected $attemptDelay;
30
31
    /**
32
     * @param array $types
33
     * @param int   $pause
34
     * @param int   $batchSize
35
     * @param int   $maxAttempts
36
     * @param int   $attemptDelay
37
     */
38
    public function __construct(MessageManagerInterface $messageManager, $types = [], $pause = 500000, $batchSize = 10, $maxAttempts = 5, $attemptDelay = 10)
39
    {
40
        parent::__construct($messageManager, $types, $pause, $batchSize);
41
42
        $this->maxAttempts = $maxAttempts;
43
        $this->attemptDelay = $attemptDelay;
44
    }
45
46
    /**
47
     * Find messages in error.
48
     *
49
     * @param $types
50
     *
51
     * @return mixed
52
     */
53
    protected function findNextMessages($types)
54
    {
55
        return $this->messageManager->findByAttempts(
56
            $this->types,
57
            MessageInterface::STATE_ERROR,
58
            $this->batchSize,
59
            $this->maxAttempts,
60
            $this->attemptDelay
61
        );
62
    }
63
}
64