Issues (3627)

Swiftmailer/SendGrid/Callback/ResponseItems.php (1 issue)

1
<?php
2
3
/*
4
 * @copyright   2014 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\EmailBundle\Swiftmailer\SendGrid\Callback;
13
14
use Mautic\EmailBundle\Swiftmailer\SendGrid\Exception\ResponseItemException;
15
use Symfony\Component\HttpFoundation\Request;
16
17
class ResponseItems implements \Iterator
18
{
19
    /**
20
     * @var int
21
     */
22
    private $position = 0;
23
24
    /**
25
     * @var ResponseItem[]
26
     */
27
    private $items = [];
28
29
    public function __construct(Request $request)
30
    {
31
        $payload = $request->request->all();
32
        foreach ($payload as $item) {
33
            if (empty($item['event']) || !CallbackEnum::shouldBeEventProcessed($item['event'])) {
34
                continue;
35
            }
36
            try {
37
                $this->items[] = new ResponseItem($item);
38
            } catch (ResponseItemException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
39
            }
40
        }
41
    }
42
43
    /**
44
     * Return the current element.
45
     *
46
     * @see  http://php.net/manual/en/iterator.current.php
47
     *
48
     * @return ResponseItem
49
     */
50
    public function current()
51
    {
52
        return $this->items[$this->position];
53
    }
54
55
    /**
56
     * Move forward to next element.
57
     *
58
     * @see  http://php.net/manual/en/iterator.next.php
59
     */
60
    public function next()
61
    {
62
        ++$this->position;
63
    }
64
65
    /**
66
     * Return the key of the current element.
67
     *
68
     * @see  http://php.net/manual/en/iterator.key.php
69
     *
70
     * @return int
71
     */
72
    public function key()
73
    {
74
        return $this->position;
75
    }
76
77
    /**
78
     * Checks if current position is valid.
79
     *
80
     * @see  http://php.net/manual/en/iterator.valid.php
81
     *
82
     * @return bool
83
     */
84
    public function valid()
85
    {
86
        return isset($this->items[$this->position]);
87
    }
88
89
    /**
90
     * Rewind the Iterator to the first element.
91
     *
92
     * @see  http://php.net/manual/en/iterator.rewind.php
93
     */
94
    public function rewind()
95
    {
96
        $this->position = 0;
97
    }
98
}
99