BodyNormalizer::normalize()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 3
nop 2
crap 4
1
<?php
2
3
/*
4
 * This file is part of the Ivory Http Adapter package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\HttpAdapter\Normalizer;
13
14
use Ivory\HttpAdapter\Asset\AbstractUninstantiableAsset;
15
use Ivory\HttpAdapter\Message\RequestInterface;
16
17
/**
18
 * @author GeLo <[email protected]>
19
 */
20
class BodyNormalizer extends AbstractUninstantiableAsset
21
{
22
    /**
23
     * @param mixed  $body
24
     * @param string $method
25
     *
26
     * @return mixed
27
     */
28 12213
    public static function normalize($body, $method)
29
    {
30 12213
        if ($method === RequestInterface::METHOD_HEAD || empty($body)) {
31 1227
            return;
32
        }
33
34 11286
        if (is_callable($body)) {
35 6084
            return call_user_func($body);
36
        }
37
38 5202
        return $body;
39
    }
40
}
41