Execute::getBody()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 7
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
namespace Cassandra\Request;
3
use Cassandra\Protocol\Frame;
4
5
class Execute extends Request{
6
	
7
	protected $opcode = Frame::OPCODE_EXECUTE;
8
	
9
	/**
10
	 * 
11
	 * @var int
12
	 */
13
	protected $_queryId;
14
	
15
	/**
16
	 * 
17
	 * @var int
18
	 */
19
	protected $_consistency;
20
	
21
	/**
22
	 * 
23
	 * @var array
24
	 */
25
	protected $_values;
26
	
27
	/**
28
	 * 
29
	 * @var array
30
	 */
31
	protected $_options;
32
	
33
	/**
34
	 * EXECUTE
35
	 *
36
	 * Executes a prepared query. The body of the message must be:
37
	 * <id><n><value_1>....<value_n><consistency>
38
	 * where:
39
	 * - <id> is the prepared query ID. It's the [short bytes] returned as a
40
	 * response to a PREPARE message.
41
	 * - <n> is a [short] indicating the number of following values.
42
	 * - <value_1>...<value_n> are the [bytes] to use for bound variables in the
43
	 * prepared query.
44
	 * - <consistency> is the [consistency] level for the operation.
45
	 * Note that the consistency is ignored by some (prepared) queries (USE, CREATE,
46
	 * ALTER, TRUNCATE, ...).
47
	 * The response from the server will be a RESULT message.
48
	 *
49
	 * @param int $queryId
50
	 * @param array $values
51
	 * @param int $consistency
52
	 * @param array $options
53
	 */
54 View Code Duplication
	public function __construct($queryId, array $values, $consistency = null, $options = []) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
		$this->_queryId = $queryId;
56
		$this->_values = $values;
57
		 
58
		$this->_consistency = $consistency === null ? Request::CONSISTENCY_ONE : $consistency;
59
		$this->_options = $options;
60
	}
61
	
62
	public function getBody(){
63
		$body = pack('n', strlen($this->_queryId)) . $this->_queryId;
64
		
65
		$body .= Request::queryParameters($this->_consistency, $this->_values, $this->_options);
66
		
67
		return $body;
68
	}
69
}
70