ResourceAdapter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 33
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A supports() 0 4 2
A convert() 0 4 1
1
<?php
2
/*
3
 * This file is part of the runopencode/sax, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Sax\StreamAdapter;
11
12
use RunOpenCode\Sax\Contract\StreamAdapterInterface;
13
14
/**
15
 * Class ResourceAdapter
16
 *
17
 * PHP resource to stream adapter.
18
 *
19
 * @package RunOpenCode\Sax\Contract
20
 */
21
class ResourceAdapter implements StreamAdapterInterface
22
{
23
    /**
24
     * @var string
25
     */
26
    private $streamClass;
27
28
    /**
29
     * ResourceAdapter constructor.
30
     *
31
     * @param string $streamClass FQCN of StreamInterface implementation, GuzzleHttp\Psr7\Stream is used by default.
32
     */
33 5
    public function __construct($streamClass = 'GuzzleHttp\\Psr7\\Stream')
34
    {
35 5
        $this->streamClass = $streamClass;
36 5
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 5
    public function supports($xmlDocument)
42
    {
43 5
        return is_resource($xmlDocument) && get_resource_type($xmlDocument) === 'stream';
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 1
    public function convert($xmlDocument)
50
    {
51 1
        return new $this->streamClass($xmlDocument);
52
    }
53
}
54