WithBodyTrait::getBody()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of the bee4/transport package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @copyright Bee4 2015
8
 * @author Stephane HULARD <[email protected]>
9
 * @package Bee4\Transport\Message
10
 */
11
namespace Bee4\Transport\Message;
12
13
/**
14
 * Add body capability to the current request
15
 * @package Bee4\Transport\Message
16
 */
17
trait WithBodyTrait
18
{
19
    /**
20
     * Request body
21
     * @var string
22
     */
23
    protected $body = false;
24
25
    /**
26
     * Set the body for the current request
27
     * @param string $body
28
     * @return WithBodyTrait
0 ignored issues
show
Comprehensibility Bug introduced by
The return type WithBodyTrait is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?

In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.

If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.

Loading history...
29
     */
30 13
    public function setBody($body)
31
    {
32 13
        $this->body = $body;
33 13
        return $this;
34
    }
35
36
    /**
37
     * Return the body property
38
     * @return string
39
     */
40 8
    public function getBody()
41
    {
42 8
        return $this->body;
43
    }
44
45
    /**
46
     * Retrieve the body length
47
     * @return integer
48
     */
49 1
    public function getBodyLength()
50
    {
51 1
        return strlen($this->body);
52
    }
53
}
54