Completed
Push — master ( 1cb211...95ea2a )
by Evgenij
03:22
created

WriteOperation::hasData()   A

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 0 Features 0
Metric Value
c 1
b 0
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
 * Async sockets
4
 *
5
 * @copyright Copyright (c) 2015, Efimov Evgenij <[email protected]>
6
 *
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
namespace AsyncSockets\Operation;
11
12
/**
13
 * Class WriteOperation
14
 */
15
class WriteOperation implements OperationInterface
16
{
17
    /**
18
     * Data to write
19
     *
20
     * @var string
21
     */
22
    private $data;
23
24
    /**
25
     * WriteOperation constructor.
26
     *
27
     * @param string $data Data to send
28
     */
29 26
    public function __construct($data = null)
30
    {
31 26
        $this->data = $data !== null ? (string) $data : null;
32 26
    }
33
34
35
    /** {@inheritdoc} */
36 53
    public function getType()
37
    {
38 53
        return self::OPERATION_WRITE;
39
    }
40
41
    /**
42
     * Return Data
43
     *
44
     * @return string
45
     */
46 12
    public function getData()
47
    {
48 12
        return $this->data;
49
    }
50
51
    /**
52
     * Sets Data
53
     *
54
     * @param string $data Data to send
55
     *
56
     * @return void
57
     */
58 9
    public function setData($data)
59
    {
60 9
        $this->data = $data;
61 9
    }
62
63
    /**
64
     * Checks whether request has data
65
     *
66
     * @return bool
67
     */
68 34
    public function hasData()
69
    {
70 34
        return $this->data !== null;
71
    }
72
73
    /**
74
     * Clear send data
75
     *
76
     * @return void
77
     */
78 1
    public function clearData()
79
    {
80 1
        $this->data = null;
81 1
    }
82
}
83