QueryDoubleTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 63
loc 63
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testDoubleRow() 8 8 1
A testDoubleMap() 11 11 1
A testDoubleSet() 18 18 1
A testDoubleList() 18 18 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace evseevnn\Cassandra\Tests;
4
5
use evseevnn\Cassandra;
6
7 View Code Duplication
class QueryDoubleTest extends Setup\QueryTestCase
0 ignored issues
show
Duplication introduced by
This class 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...
8
{
9
10
		public function testDoubleRow()
11
		{
12
				self::$connection->query('CREATE TABLE DoubleTest (foo double PRIMARY KEY, bar double)');
13
				self::$connection->query('INSERT INTO DoubleTest (foo, bar) VALUES (:foo, :bar)', ['foo' => 0.2, 'bar' => 5.2]);
14
				$result = self::$connection->query('SELECT * FROM DoubleTest WHERE foo = :foo', ['foo' => 0.2]);
15
				$this->assertFloatEquals(5.2, $result[0]['bar']);
16
				$this->assertFloatEquals(0.2, $result[0]['foo']);
17
		}
18
19
		public function testDoubleMap()
20
		{
21
				self::$connection->query('CREATE TABLE DoubleMapTest (foo double PRIMARY KEY, bar map<double,double>)');
22
				self::$connection->query(
23
						'INSERT INTO DoubleMapTest (foo, bar) VALUES (:foo, :bar)',
24
						['foo' => 0.2, 'bar' => [5.2 => 2.5]]
25
				);
26
				$result = self::$connection->query('SELECT * FROM DoubleMapTest WHERE foo = :foo', ['foo' => 0.2]);
27
				$this->assertFloatEquals([5.2 => 2.5], $result[0]['bar']);
28
				$this->assertFloatEquals(0.2, $result[0]['foo']);
29
		}
30
31
		public function testDoubleSet()
32
		{
33
				self::$connection->query('CREATE TABLE DoubleSetTest (foo double PRIMARY KEY, bar set<double>)');
34
				self::$connection->query(
35
						'INSERT INTO DoubleSetTest (foo, bar) VALUES (:foo, :bar)',
36
						['foo' => 0.2, 'bar' => [2.5, 5.2]]
37
				);
38
				$result = self::$connection->query('SELECT * FROM DoubleSetTest WHERE foo = :foo', ['foo' => 0.2]);
39
				$this->assertFloatEquals([2.5, 5.2], $result[0]['bar']);
40
				$this->assertFloatEquals(0.2, $result[0]['foo']);
41
				//according to Spec, this should always be returned alphabetically.
42
				self::$connection->query(
43
						'INSERT INTO DoubleSetTest (foo, bar) VALUES (:foo, :bar)',
44
						['foo' => 2.2, 'bar' => [5.2, 2.5]]
45
				);
46
				$result = self::$connection->query('SELECT * FROM DoubleSetTest WHERE foo = :foo', ['foo' => 2.2]);
47
				$this->assertFloatEquals([2.5, 5.2], $result[0]['bar']);
48
		}
49
50
		public function testDoubleList()
51
		{
52
				self::$connection->query('CREATE TABLE DoubleListTest (foo double PRIMARY KEY, bar list<double>)');
53
				self::$connection->query(
54
						'INSERT INTO DoubleListTest (foo, bar) VALUES (:foo, :bar)',
55
						['foo' => 0.2, 'bar' => [5.2, 2.5]]
56
				);
57
				$result = self::$connection->query('SELECT * FROM DoubleListTest WHERE foo = :foo', ['foo' => 0.2]);
58
				$this->assertFloatEquals([5.2, 2.5], $result[0]['bar']);
59
				$this->assertFloatEquals(0.2, $result[0]['foo']);
60
				//according to Spec, this should be returned in index order
61
				self::$connection->query(
62
						'INSERT INTO DoubleListTest (foo, bar) VALUES (:foo, :bar)',
63
						['foo' => 2.2, 'bar' => [2.5, 5.2]]
64
				);
65
				$result = self::$connection->query('SELECT * FROM DoubleListTest WHERE foo = :foo', ['foo' => 2.2]);
66
				$this->assertFloatEquals([2.5, 5.2], $result[0]['bar']);
67
		}
68
69
}