Completed
Push — master ( be72f0...b6ccc1 )
by Alex
17s queued 14s
created

ODataReaderRegistry::getReader()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
nc 3
nop 2
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace POData\Readers;
7
8
use POData\Common\Version;
9
use POData\Writers\IODataWriter;
10
11
class ODataReaderRegistry
12
{
13
    /** @var IODataReader[] */
14
    private $readers = [];
15
16
    /**
17
     * @param IODataReader $reader
18
     */
19
    public function register(IODataReader $reader)
20
    {
21
        $this->readers[] = $reader;
22
    }
23
24
    /**
25
     * @param Version $responseVersion
26
     * @param $contentType
27
     *
28
     * @return IODataReader|null the writer that can handle the given criteria, or null
29
     */
30
    public function getReader(Version $responseVersion, $contentType)
31
    {
32
        foreach ($this->readers as $reader) {
33
            if ($reader->canHandle($responseVersion, $contentType)) {
34
                return $reader;
35
            }
36
        }
37
        return null;
38
    }
39
}
40