Completed
Push — 1.0 ( 5a6c04...f17e34 )
by Valentin
05:45 queued 02:26
created

Transaction::setHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
/*
4
 * This file is part of Transfer.
5
 *
6
 * For the full copyright and license information, please view the LICENSE file located
7
 * in the root directory.
8
 */
9
10
namespace Transfer\Adapter\Transaction;
11
12
/**
13
 * Common transaction model for requests and responses.
14
 */
15
abstract class Transaction extends DataAggregate
16
{
17
    /**
18
     * @var array Header collection
19
     */
20
    protected $headers;
21
22
    /**
23
     * @param array|\Iterator|\Traversable $data    Data collection
24
     * @param array                        $headers Header collection
25
     */
26 24
    public function __construct($data = array(), $headers = array())
27
    {
28 24
        parent::__construct($data);
29
30 24
        $this->headers = $headers;
31 24
    }
32
33
    /**
34
     * Gets header collection.
35
     *
36
     * @return array Header collection
37
     */
38 3
    public function getHeaders()
39
    {
40 3
        return $this->headers;
41
    }
42
43
    /**
44
     * Gets header by key.
45
     *
46
     * @param string $key
47
     *
48
     * @return mixed
49
     */
50 1
    public function getHeader($key)
51
    {
52 1
        return array_key_exists($key, $this->headers) ? $this->headers[$key] : null;
53
    }
54
55
    /**
56
     * Sets a header collection.
57
     *
58
     * @param array $headers Header collection
59
     */
60 1
    public function setHeaders($headers)
61
    {
62 1
        $this->headers = $headers;
63 1
    }
64
65
    /**
66
     * Sets a header.
67
     *
68
     * @param string $key   Key
69
     * @param mixed  $value Value
70
     */
71
    public function setHeader($key, $value)
72
    {
73
        $this->headers[$key] = $value;
74
    }
75
}
76