AbstractParser::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * Copyright (c) 2010–2019 Ryan Parman <http://ryanparman.com>.
4
 * Copyright (c) 2016–2019 Contributors.
5
 *
6
 * http://opensource.org/licenses/Apache2.0
7
 */
8
9
declare(strict_types=1);
10
11
namespace SimplePie\UtilityPack\Parser;
12
13
use Psr\Http\Message\StreamInterface;
14
15
/**
16
 * The base parser class that all other parser classes extend from. It handles low-level functionality that is shared
17
 * across all parser classes.
18
 */
19
abstract class AbstractParser implements ParserInterface
20
{
21
    /**
22
     * Returns an opaque string representing the object.
23
     *
24
     * Note: Use of MD5 here is not cryptographically significant.
25
     *
26
     * @see http://php.net/manual/en/language.oop5.magic.php#object.tostring
27
     */
28 1
    public function __toString(): string
29
    {
30 1
        return \sprintf('<%s: resource %s>', \get_called_class(), \md5(\spl_object_hash($this)));
31
    }
32
33
    /**
34
     * Reads the contents of the stream resource.
35
     *
36
     * @param StreamInterface $stream A PSR-7 `StreamInterface` which is typically returned by the
37
     *                                `getBody()` method of a `ResponseInterface` class.
38
     *
39
     * @throws \RuntimeException
40
     *
41
     * @return string The raw contents of the steam resource.
42
     */
43 1
    public function readStream(StreamInterface $stream): string
44
    {
45 1
        return $stream->getContents();
46
    }
47
}
48