WithBodyTrait   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 22
c 2
b 1
f 1
lcom 1
cbo 0
dl 0
loc 37
ccs 7
cts 7
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setBody() 0 5 1
A getBody() 0 4 1
A getBodyLength() 0 4 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