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

ODataReaderRegistry   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 7
c 3
b 0
f 0
dl 0
loc 27
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 3 1
A getReader() 0 8 3
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