Passed
Push — master ( f4dfed...a8b79e )
by Dieter
07:58
created

MsgBodyExtractor::getStringBetween()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
/**
3
 * amadeus-ws-client
4
 *
5
 * Copyright 2015 Amadeus Benelux NV
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 *
19
 * @package Amadeus
20
 * @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
21
 */
22
23
namespace Amadeus\Client\Util;
24
25
/**
26
 * MsgBodyExtractor
27
 *
28
 * @package Amadeus\Client\Util
29
 * @author Dieter Devlieghere <[email protected]>
30
 */
31
class MsgBodyExtractor
32
{
33
    /**
34
     * Extracts the message content from the soap envelope (i.e. everything under the soap body)
35
     *
36
     * @param string $soapResponse
37
     * @return string|null
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
38
     */
39 44
    public function extract($soapResponse)
40
    {
41 44
        $messageBody = null;
0 ignored issues
show
Unused Code introduced by
$messageBody is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
42
43 44
        $messageBody = $this->getStringBetween($soapResponse, '<SOAP-ENV:Body>', '</SOAP-ENV:Body>');
44
45 44
        if (empty($messageBody) || false === $messageBody) {
46 8
            $messageBody = $this->getStringBetween($soapResponse, '<soap:Body>', '</soap:Body>');
47 4
        }
48
49 44
        return $messageBody;
50
    }
51
52
    /**
53
     * Get substring between two strings
54
     *
55
     * @param $string
56
     * @param $start
57
     * @param $end
58
     * @return bool|string
59
     */
60 44
    private function getStringBetween($string, $start, $end)
61
    {
62 44
        $startPos = strpos($string, $start) + strlen($start);
63
64 44
        $endPos = strlen($string) - strpos($string, $end);
65
66 44
        return substr($string, $startPos, -$endPos);
67
    }
68
}
69