Completed
Branch master (a35590)
by Anton
04:28 queued 01:35
created

Event::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 11
nc 2
nop 1
1
<?php
2
3
namespace Covery\Client\Requests;
4
5
use Covery\Client\EnvelopeInterface;
6
use Covery\Client\TransportInterface;
7
use GuzzleHttp\Psr7\Request;
8
9
/**
10
 * Class Event
11
 *
12
 * Contains event data, that must be stored on Covery without
13
 * decision making
14
 *
15
 * @package Covery\Client\Requests
16
 */
17
class Event extends Request
18
{
19
    public function __construct(EnvelopeInterface $envelope)
20
    {
21
        // Building request
22
        $ids = array();
23
        foreach ($envelope->getIdentities() as $id) {
24
            $ids[] = $id->getType() . '=' . $id->getId();
25
        }
26
27
        $packet = array('type' => $envelope->getType(), 'sequence_id' => $envelope->getSequenceId());
28
29
        parent::__construct(
30
            'POST',
31
            TransportInterface::DEFAULT_URL . 'api/sendEvent',
32
            array(
33
                'X-Identities' => implode('&', $ids)
34
            ),
35
            json_encode(array_merge($packet, $envelope->toArray()))
36
        );
37
    }
38
}
39