Completed
Push — master ( 983101...820d65 )
by Valentin
03:34
created

XmlResponseParser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
eloc 8
c 3
b 0
f 0
dl 0
loc 21
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseResponse() 0 11 2
1
<?php
2
3
namespace Pheanstalk;
4
5
use Pheanstalk\Response\ArrayResponse;
6
7
/**
8
 * A response parser for commands that return a subset of XML.
9
 *
10
 * Expected response is 'OK', 'NOT_FOUND' response is also handled.
11
 * Parser expects either a YAML list or dictionary, depending on mode.
12
 *
13
 * @author  Paul Annesley
14
 * @package Pheanstalk
15
 * @license http://www.opensource.org/licenses/mit-license.php
16
 */
17
class XmlResponseParser implements \Pheanstalk\ResponseParser
18
{
19
20
    /**
21
     * @param string $responseLine
22
     * @param string $responseData
23
     *
24
     * @throws Exception\ServerException
25
     * @return Response\ArrayResponse
26
     */
27 5
    public function parseResponse($responseLine, $responseData)
28
    {
29 5
        if ($responseLine == Response::RESPONSE_NOT_FOUND) {
30 1
            throw new Exception\ServerException(sprintf(
31 1
                'Server reported %s',
32 1
                $responseLine
33
            ));
34
        }
35 4
        unset($responseData['@attributes']);
36 4
        $content = $responseData;
0 ignored issues
show
Unused Code introduced by
The assignment to $content is dead and can be removed.
Loading history...
37 4
        return new Response\ArrayResponse('OK', $responseData);
0 ignored issues
show
Bug introduced by
$responseData of type string is incompatible with the type array expected by parameter $data of Pheanstalk\Response\ArrayResponse::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        return new Response\ArrayResponse('OK', /** @scrutinizer ignore-type */ $responseData);
Loading history...
38
    }
39
}
40