Passed
Push — master ( 3a0301...45c7a2 )
by Aimeos
02:41
created

PgSQL   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 19
c 1
b 0
f 0
dl 0
loc 37
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B escape() 0 27 9
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018-2023
6
 * @package Base
7
 * @subpackage Common
8
 */
9
10
11
namespace Aimeos\Base\Criteria\Expression\Sort;
12
13
14
/**
15
 * PostgreSQL implementation for sorting entries
16
 *
17
 * @package Base
18
 * @subpackage Common
19
 */
20
class PgSQL extends SQL
21
{
22
	/**
23
	 * Escapes the value so it can be inserted into a SQL statement
24
	 *
25
	 * @param string $operator Operator used for the expression
26
	 * @param string $type Type constant
27
	 * @param mixed $value Value that the variable or column should be compared to
28
	 * @return double|string|integer Escaped value
29
	 */
30
	protected function escape( string $operator, string $type, $value )
31
	{
32
		$value = $this->translateValue( $this->getName(), $value, $type );
33
34
		switch( $type )
35
		{
36
			case \Aimeos\Base\DB\Statement\Base::PARAM_NULL:
37
				$value = 'null'; break;
38
			case \Aimeos\Base\DB\Statement\Base::PARAM_BOOL:
39
				$value = ( $value ? "'t'" : "'f'" ); break;
40
			case \Aimeos\Base\DB\Statement\Base::PARAM_INT:
41
				$value = (int) $value; break;
42
			case \Aimeos\Base\DB\Statement\Base::PARAM_FLOAT:
43
				$value = (double) $value; break;
44
			case \Aimeos\Base\DB\Statement\Base::PARAM_STR:
45
				if( $operator === '~=' ) {
46
					$value = '\'%' . str_replace( ['#', '%', '_', '['], ['##', '#%', '#_', '#['], $this->getConnection()->escape( (string) $value ) ) . '%\''; break;
0 ignored issues
show
Bug introduced by
The method getConnection() does not exist on Aimeos\Base\Criteria\Expression\Sort\PgSQL. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
					$value = '\'%' . str_replace( ['#', '%', '_', '['], ['##', '#%', '#_', '#['], $this->/** @scrutinizer ignore-call */ getConnection()->escape( (string) $value ) ) . '%\''; break;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
				}
48
				if( $operator === '=~' ) {
49
					$value = '\'' . str_replace( ['#', '%', '_', '['], ['##', '#%', '#_', '#['], $this->getConnection()->escape( (string) $value ) ) . '%\''; break;
50
				}
51
				// all other operators: escape in default case
52
			default:
53
				$value = '\'' . $this->getConnection()->escape( (string) $value ) . '\'';
54
		}
55
56
		return $value;
57
	}
58
}
59