1
|
|
|
<?php |
2
|
|
|
namespace Wabel\Zoho\CRM\Copy\Log; |
3
|
|
|
|
4
|
|
|
use Doctrine\DBAL\Connection; |
5
|
|
|
use Doctrine\DBAL\Logging\SQLLogger; |
6
|
|
|
use Doctrine\DBAL\SQLParserUtils; |
7
|
|
|
use function PHPSTORM_META\type; |
8
|
|
|
use Psr\Log\LoggerInterface; |
9
|
|
|
|
10
|
|
|
class ZohoSyncSQLLogger implements SQLLogger |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var LoggerInterface |
15
|
|
|
*/ |
16
|
|
|
private $logger; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var Connection |
20
|
|
|
*/ |
21
|
|
|
private $connection; |
22
|
|
|
/** |
23
|
|
|
* @var bool |
24
|
|
|
*/ |
25
|
|
|
private $authorizedSQLWithoutParams; |
26
|
|
|
/** |
27
|
|
|
* @var bool |
28
|
|
|
*/ |
29
|
|
|
private $authorizedSQLWithParams; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* ZohoSyncSQLLogger constructor. |
33
|
|
|
* @param LoggerInterface $logger |
34
|
|
|
* @param Connection $connection |
35
|
|
|
* @param bool $authorizedSQLWithoutParams |
36
|
|
|
* @param bool $authorizedSQLWithParams |
37
|
|
|
*/ |
38
|
|
|
public function __construct(LoggerInterface $logger, Connection $connection, $authorizedSQLWithoutParams = false, $authorizedSQLWithParams = false) |
39
|
|
|
{ |
40
|
|
|
$this->logger = $logger; |
41
|
|
|
$this->connection = $connection; |
42
|
|
|
$this->authorizedSQLWithoutParams = $authorizedSQLWithoutParams; |
43
|
|
|
$this->authorizedSQLWithParams = $authorizedSQLWithParams; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Logs a SQL statement somewhere. |
48
|
|
|
* |
49
|
|
|
* @param string $sql The SQL to be executed. |
50
|
|
|
* @param array|null $params The SQL parameters. |
51
|
|
|
* @param array|null $types The SQL parameter types. |
52
|
|
|
* |
53
|
|
|
* @return void |
54
|
|
|
*/ |
55
|
|
|
public function startQuery($sql, array $params = null, array $types = null) |
56
|
|
|
{ |
57
|
|
|
$query = null; |
|
|
|
|
58
|
|
|
if ($params && $this->authorizedSQLWithParams) { |
59
|
|
|
$this->logger->debug($sql.' -- Params : {params} - Types : {types}', ['params' => json_encode($params), 'types' => json_encode($types)]); |
60
|
|
|
} elseif($this->authorizedSQLWithoutParams) { |
61
|
|
|
$this->logger->debug($sql); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Marks the last started query as stopped. This can be used for timing of queries. |
67
|
|
|
* |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
|
|
public function stopQuery() |
71
|
|
|
{ |
72
|
|
|
} |
73
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.