Method getDbInfo
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getDbInfo(): array
{
$return = [
'isFileSize' => false,
'size' => 0,
Method getInfo
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getInfo()
{
$pdo = $this->getSlavePdo();
$statement = $pdo->prepare('SHOW VARIABLES');
$statement->execute();
Function getDbInfo
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function getDbInfo(): array
{
$return = [
'isFileSize' => false,
'size' => 0,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Missing class import via use statement (line '275', column '25'). Open
$pdoCollector = new \DebugBar\DataCollector\PDO\PDOCollector();
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '303', column '15'). Open
$id = (new \App\Db\Query())
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
The method getUniqueID has a boolean flag argument $columnName, which is a certain sign of a Single Responsibility Principle violation. Open
public function getUniqueID($tableName, $columnName = false, $seq = true)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Missing class import via use statement (line '297', column '15'). Open
$id = (new \App\Db\Query())->from($tableName)->scalar($this);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
The method getUniqueID has a boolean flag argument $seq, which is a certain sign of a Single Responsibility Principle violation. Open
public function getUniqueID($tableName, $columnName = false, $seq = true)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Avoid using static access to class 'App\Config' in method 'getConfig'. Open
self::$config[$type] = Config::db($type) ?? Config::db('base');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method createPdoInstance uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$pdoCollector = new \DebugBar\DataCollector\PDO\PDOCollector();
$pdoCollector->addConnection($pdo, $this->dbType);
$bebugBar->addCollector($pdoCollector);
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class 'App\Cache' in method 'getTableKeys'. Open
if (Cache::has('getTableKeys', $tableName)) {
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'App\Cache' in method 'getTableKeys'. Open
return Cache::get('getTableKeys', $tableName);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'App\Debuger' in method 'createPdoInstance'. Open
if (Debuger::isDebugBar()) {
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'App\Debuger' in method 'createPdoInstance'. Open
$bebugBar = Debuger::getDebugBar();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method getUniqueID uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$id = (new \App\Db\Query())
->from($tableName)
->max($columnName, $this);
++$id;
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class 'App\Config' in method 'getConfig'. Open
self::$config[$type] = Config::db($type) ?? Config::db('base');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'App\Cache' in method 'getPrimaryKey'. Open
Cache::save('getPrimaryKey', $tableName, $key, Cache::LONG);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'App\Cache' in method 'getPrimaryKey'. Open
if (Cache::has('getPrimaryKey', $tableName)) {
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'App\Cache' in method 'getTableKeys'. Open
Cache::save('getTableKeys', $tableName, $keys, Cache::LONG);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'App\Cache' in method 'getPrimaryKey'. Open
return Cache::get('getPrimaryKey', $tableName);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Define a constant instead of duplicating this literal "getPrimaryKey" 3 times. Open
if (Cache::has('getPrimaryKey', $tableName)) {
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "yii\db\mssql\Schema" 3 times. Open
'sqlsrv' => 'yii\db\mssql\Schema', // newer MSSQL driver on MS Windows hosts
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "Data_length" 3 times. Open
'dataSize' => $row['Data_length'],
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "indexSize" 3 times. Open
'indexSize' => 0,
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "version_comment" 3 times. Open
$conf['version_comment'] = $conf['version_comment'] . '|' . $fullVersion;
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "mysql" 4 times. Open
'mysql' => 'App\Db\Drivers\Mysql\Schema', // MySQL
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "tables" 4 times. Open
'tables' => [],
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "PRIMARY" 3 times. Open
$key = isset($tableKeys['PRIMARY']) ? ['PRIMARY' => array_keys($tableKeys['PRIMARY'])] : [];
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "ALLOCATED_SIZE" 3 times. Open
if (!empty($row['ALLOCATED_SIZE'])) {
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "Index_length" 3 times. Open
'indexSize' => $row['Index_length'],
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "dataSize" 3 times. Open
'dataSize' => 0,
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "getTableKeys" 3 times. Open
if (Cache::has('getTableKeys', $tableName)) {
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Avoid using empty try-catch blocks in getDbInfo. Open
} catch (\Throwable $th) {
}
- Read upRead up
- Exclude checks
EmptyCatchBlock
Since: 2.7.0
Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.
Example
class Foo {
public function bar()
{
try {
// ...
} catch (Exception $e) {} // empty catch block
}
}
Source https://phpmd.org/rules/design.html#emptycatchblock
Call with 1 arg(s) to \App\Db::__construct()
which only takes 0 arg(s) defined at /code/app/Db.php:15
Open
$db = new self(self::getConfig($type));
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$id = (new \App\Db\Query())->from($tableName)->scalar($this);
- Exclude checks
Call to undeclared method \App\Db::getDriverName
Open
if ('mysql' === $this->getDriverName()) {
- Exclude checks
Call to undeclared method \App\Db::quoteTableName
Open
$tableName = $this->quoteTableName(str_replace('#__', $this->tablePrefix, $tableName));
- Exclude checks
Reference to undeclared property \App\Db->tablePrefix
Open
return str_replace('#__', $this->tablePrefix, $sql);
- Exclude checks
Method \App\Db::createTable
is declared to return bool
but has no return value Open
public function createTable($tableName, $columns)
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$dataReader = $this->createCommand()->setSql('SHOW KEYS FROM ' . $tableName)->query();
- Exclude checks
Call to undeclared method \App\Db::getSchema
Open
return \in_array(str_replace('#__', $this->tablePrefix, $tableName), $this->getSchema()->getTableNames());
- Exclude checks
Assigning false
to property but \App\Db->schemaCache
is \App\Cache|string
Open
public $schemaCache = false;
- Exclude checks
Reference to undeclared class \yii\db\Connection
Open
return parent::createPdoInstance();
- Exclude checks
Parameter $tableName
has undeclared type \App\type
Open
public function getPrimaryKey($tableName)
- Exclude checks
Argument 1 (tableName)
is \App\type
but \App\Db::getTableKeys()
takes string
defined at /code/app/Db.php:347
Open
$tableKeys = $this->getTableKeys($tableName);
- Exclude checks
Call to undeclared method \App\Db::getSlavePdo
Open
$statement = $this->getSlavePdo()->prepare("SHOW TABLE STATUS FROM `{$this->dbName}`");
- Exclude checks
Reference to undeclared class \yii\db\Connection
Open
$pdo = new Debug\DebugBar\TraceablePDO(parent::createPdoInstance());
- Exclude checks
Reference to undeclared property \App\Db->tablePrefix
Open
$tableName = $this->quoteTableName(str_replace('#__', $this->tablePrefix, $tableName));
- Exclude checks
Class extends undeclared class \yii\db\Connection
Open
class Db extends \yii\db\Connection
- Exclude checks
Call to method __construct
from undeclared class \DebugBar\DataCollector\PDO\PDOCollector
Open
$pdoCollector = new \DebugBar\DataCollector\PDO\PDOCollector();
- Exclude checks
Call to undeclared method \App\Debug\DebugBar\DebugBar::addCollector
Open
$bebugBar->addCollector($pdoCollector);
- Exclude checks
Call to undeclared method \App\Db::getSlavePdo
Open
$pdo = $this->getSlavePdo();
- Exclude checks
Reference to undeclared property \App\Db->tablePrefix
Open
return parent::getLastInsertID(str_replace('#__', $this->tablePrefix, $sequenceName));
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$this->createCommand()->createTable($tableName, $columns, $tableOptions)->execute();
- Exclude checks
Argument 2 (key)
is \App\type
but \App\Cache::save()
takes string
defined at /code/app/Cache.php:89
Open
Cache::save('getPrimaryKey', $tableName, $key, Cache::LONG);
- Exclude checks
Call to undeclared method \App\Debug\DebugBar\DebugBar::getCollector
Open
$pdoCollector = $bebugBar->getCollector('pdo');
- Exclude checks
Assigning array{}
to property but \App\Db::$cache
is \App\Db
Open
private static $cache = [];
- Exclude checks
Call to undeclared method \App\Debug\DebugBar\DebugBar::hasCollector
Open
if ($bebugBar->hasCollector('pdo')) {
- Exclude checks
Argument 2 (key)
is \App\type
but \App\Cache::has()
takes string
defined at /code/app/Cache.php:74
Open
if (Cache::has('getPrimaryKey', $tableName)) {
- Exclude checks
Argument 2 (key)
is \App\type
but \App\Cache::get()
takes string
defined at /code/app/Cache.php:61
Open
return Cache::get('getPrimaryKey', $tableName);
- Exclude checks
Call to undeclared method \App\Db::getDriverName
Open
'driver' => $this->getDriverName(),
- Exclude checks
Returning type \App\Debug\DebugBar\TraceablePDO
but createPdoInstance()
is declared to return \App\PDO
Open
return $pdo;
- Exclude checks
Reference to undeclared class \yii\db\Connection
Open
return parent::getLastInsertID(str_replace('#__', $this->tablePrefix, $sequenceName));
- Exclude checks
Call to undeclared method \App\Db::getDriverName
Open
if ('mysql' === $this->getDriverName()) {
- Exclude checks
Call to method addConnection
from undeclared class \DebugBar\DataCollector\PDO\PDOCollector
Open
$pdoCollector->addConnection($pdo, $this->dbType);
- Exclude checks
Return type of getPrimaryKey()
is undeclared type \App\type
Open
public function getPrimaryKey($tableName)
- Exclude checks
Call to undeclared method \App\Db::getSlavePdo
Open
$statement = $this->getSlavePdo()->prepare("SELECT * FROM `information_schema`.`INNODB_SYS_TABLESPACES` WHERE `NAME` LIKE '{$this->dbName}/%'");
- Exclude checks
Return type of createPdoInstance()
is undeclared type \App\PDO
(Did you mean class \PDO) Open
protected function createPdoInstance()
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$this->createCommand()->update($tableName, [
- Exclude checks
Call to undeclared method \App\Db::getDriverName
Open
if ('mysql' === $this->getDriverName()) {
- Exclude checks
Returning type array{PRIMARY:array<int>|array<int>}|array{}</int></int>
but getPrimaryKey()
is declared to return \App\type
Open
return $key;
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$id = (new \App\Db\Query())
- Exclude checks
Reference to undeclared property \App\Db->tablePrefix
Open
return \in_array(str_replace('#__', $this->tablePrefix, $tableName), $this->getSchema()->getTableNames());
- Exclude checks
Either remove or fill this block of code. Open
} catch (\Throwable $th) {
}
- Read upRead up
- Exclude checks
Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.
Noncompliant Code Example
for ($i = 0; $i < 42; $i++){} // Empty on purpose or missing piece of code ?
Exceptions
When a block contains a comment, this block is not considered to be empty.
Avoid classes with short names like Db. Configured minimum length is 3. Open
class Db extends \yii\db\Connection
{
/**
* Sorting order flag.
*/
- Read upRead up
- Exclude checks
ShortClassName
Since: 2.9
Detects when classes or interfaces have a very short name.
Example
class Fo {
}
interface Fo {
}
Source https://phpmd.org/rules/naming.html#shortclassname
Avoid variables with short names like $db. Configured minimum length is 3. Open
$db = new self(self::getConfig($type));
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $id. Configured minimum length is 3. Open
$id = (new \App\Db\Query())->from($tableName)->scalar($this);
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Sorting order flag.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var string Database Name
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $dbName;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var string Host database server
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'mysqli' => 'yii\db\mysql\Schema', // MySQL
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'sqlite' => 'yii\db\sqlite\Schema', // sqlite 3
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Creates the Db connection instance.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $type Name of database connection
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set database connection configuration.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $type
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$statement = $pdo->prepare('SHOW VARIABLES');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$typeDb = 'MySQL';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'maximumMemorySize' => $memory,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $emulatePrepare = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'pgsql' => 'App\Db\Drivers\Pgsql\Schema', // PostgreSQL
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var string the class used to create new database [[Command]] objects. If you want to extend the [[Command]] class,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return \App\Db
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdo = $this->getSlavePdo();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$statement->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return \array_merge($conf, [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'filesSize' => 0,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Sorting order flag.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const ASC = 'ASC';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var bool whether to turn on prepare emulation. Defaults to false, meaning PDO
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$db = new self(self::getConfig($type));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
self::$config[$type] = $config;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$memory = $conf['key_buffer_size'] + ($conf['query_cache_size'] ?? 0) + $conf['tmp_table_size'] + $conf['innodb_buffer_pool_size'] +
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'size' => 0,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
try {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Creates the PDO instance.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$bebugBar = Debuger::getDebugBar();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $tableName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $tableName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get table keys.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $tableName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getInstance($type = 'base')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$statement = $pdo->prepare('SHOW STATUS');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return str_replace('#__', $this->tablePrefix, $sql);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $sequenceName name of the sequence object (required by some DBMS) ex. table vtiger_picklist >>> vtiger_picklist_picklistid_seq
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $pdo;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return parent::createPdoInstance();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return int
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->max($columnName, $this);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return \in_array(str_replace('#__', $this->tablePrefix, $tableName), $this->getSchema()->getTableNames());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function createTable($tableName, $columns)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var bool Enable caching database instance
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return self::$cache[$type];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
self::$cache[$type] = $db;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return self::$config[$type];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
+ $conf['read_buffer_size'] + $conf['read_rnd_buffer_size'] + $conf['join_buffer_size'] + $conf['thread_stack'] + $conf['binlog_cache_size']));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return['size'] += $row['Data_length'] += $row['Index_length'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string the quoted SQL
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($bebugBar->hasCollector('pdo')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$bebugBar->addCollector($pdoCollector);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $dbType;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset(self::$cache[$type])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get info database server.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getInfo()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conf = array_merge($conf, $statement->fetchAll(\PDO::FETCH_KEY_PAIR));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'tables' => [],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$statement = $this->getSlavePdo()->prepare("SHOW TABLE STATUS FROM `{$this->dbName}`");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Line exceeds 120 characters; contains 147 characters Open
* @param string $sequenceName name of the sequence object (required by some DBMS) ex. table vtiger_picklist >>> vtiger_picklist_picklistid_seq
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return PDO the pdo instance
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'id' => $id,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private static $config = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $schemaCache = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
self::$config[$type] = Config::db($type) ?? Config::db('base');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$typeDb = 'MariaDb';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'serverVersion' => $version,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$statement->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return['dataSize'] += $row['Data_length'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
++$id;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$id = (new \App\Db\Query())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $id;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static $connectCache = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var int Port database server
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getConfig(string $type)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$statement->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
[$version] = explode('-', $conf['version']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($row['ALLOCATED_SIZE'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Also, the percentage character "%" at the beginning or ending of a table name will be replaced
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (Debuger::isDebugBar()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$id = (new \App\Db\Query())->from($tableName)->scalar($this);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $columns
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* this may need to be set true so that PDO can emulate the prepare support to bypass
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'mssql' => 'yii\db\mssql\Schema', // older MSSQL driver on MS Windows hosts
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!isset(self::$config[$type])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
($conf['innodb_additional_mem_pool_size'] ?? 0) + $conf['innodb_log_buffer_size'] + ($conf['max_connections'] * ($conf['sort_buffer_size']
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'connectionStatus' => $pdo->getAttribute(\PDO::ATTR_CONNECTION_STATUS),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'rows' => $row['Rows'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'engine' => $row['Engine'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$statement->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* The default implementation will create a PHP PDO instance.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Creating a new DB table.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* the buggy native prepare support.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private static $cache = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'mysql' => 'App\Db\Drivers\Mysql\Schema', // MySQL
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'sqlite2' => 'yii\db\sqlite\Schema', // sqlite 2
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'oci' => 'yii\db\oci\Schema', // Oracle driver
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @see enableSchemaCache
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $db;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Load database connection configuration.
- Exclude checks
Line exceeds 120 characters; contains 159 characters Open
+ $conf['read_buffer_size'] + $conf['read_rnd_buffer_size'] + $conf['join_buffer_size'] + $conf['thread_stack'] + $conf['binlog_cache_size']));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'clientVersion' => $pdo->getAttribute(\PDO::ATTR_CLIENT_VERSION),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'format' => $row['Row_format'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return['indexSize'] += $row['Index_length'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tableName = str_replace($this->dbName . '/', '', $row['NAME']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return['filesSize'] += $row['ALLOCATED_SIZE'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Processes a SQL statement by quoting table and column names that are enclosed within double brackets.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Returns the ID of the last inserted row or sequence value.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdoCollector->addConnection($pdo, $this->dbType);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param false|string $columnName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->createCommand()->createTable($tableName, $columns, $tableOptions)->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var string Database section
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
* @var string the class used to create new database [[Command]] objects. If you want to extend the [[Command]] class,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var Cache|string the cache object or the ID of the cache application component that
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $schemaMap = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'dblib' => 'yii\db\mssql\Schema', // dblib drivers on GNU/Linux (and maybe other OSes) hosts
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* you may configure this property to use your extended version of the class
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$statement->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$statement = $pdo->prepare('SELECT VERSION()');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getDbInfo(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'dataSize' => 0,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'indexSize' => 0,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function setConfig($config, $type = 'base')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'collation' => $row['Collation'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return['tables'][$tableName]['fileSize'] = $row['ALLOCATED_SIZE'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* You may override this method if the default PDO needs to be adapted for certain DBMS.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Line exceeds 120 characters; contains 146 characters Open
($conf['innodb_additional_mem_pool_size'] ?? 0) + $conf['innodb_log_buffer_size'] + ($conf['max_connections'] * ($conf['sort_buffer_size']
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getTableKeys($tableName)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'serverInfo' => $pdo->getAttribute(\PDO::ATTR_SERVER_INFO),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return Cache::get('getTableKeys', $tableName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} catch (\Throwable $th) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$this->isTableExists($tableName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdo = new Debug\DebugBar\TraceablePDO(parent::createPdoInstance());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdoCollector = $bebugBar->getCollector('pdo');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tableName .= '_seq';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tableOptions = null;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('mysql' === $this->getDriverName()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tableName = $this->quoteTableName(str_replace('#__', $this->tablePrefix, $tableName));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const DESC = 'DESC';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $host;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'sqlsrv' => 'yii\db\mssql\Schema', // newer MSSQL driver on MS Windows hosts
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* is used to cache the table metadata
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conf['version_comment'] = $conf['version_comment'] . '|' . $fullVersion;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'isFileSize' => false,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'dataSize' => $row['Data_length'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'indexSize' => $row['Index_length'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $return;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* with [[tablePrefix]].
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* This method is called by [[open]] to establish a DB connection.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $seq
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Check if table is present in database.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* will use the native prepare support if available. For some databases (such as MySQL),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var \App\Db Table of connections with database
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $port;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $commandClass = '\App\Db\Command';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$db->dbType = $type;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $type
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fullVersion = $statement->fetch(\PDO::FETCH_COLUMN);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false !== stripos($conf['version_comment'], 'MariaDb')) {
- Exclude checks
Line exceeds 120 characters; contains 140 characters Open
$memory = $conf['key_buffer_size'] + ($conf['query_cache_size'] ?? 0) + $conf['tmp_table_size'] + $conf['innodb_buffer_pool_size'] +
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'typeDb' => $typeDb,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset($return['tables'][$tableName])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return['isFileSize'] = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $sql the SQL to be quoted
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getLastInsertID($sequenceName = '')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getUniqueID($tableName, $columnName = false, $seq = true)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->createCommand()->update($tableName, [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from($tableName)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function isTableExists($tableName)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return['tables'][$row['Name']] = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$statement = $this->getSlavePdo()->prepare("SELECT * FROM `information_schema`.`INNODB_SYS_TABLESPACES` WHERE `NAME` LIKE '{$this->dbName}/%'");
- Exclude checks
Line exceeds 120 characters; contains 156 characters Open
$statement = $this->getSlavePdo()->prepare("SELECT * FROM `information_schema`.`INNODB_SYS_TABLESPACES` WHERE `NAME` LIKE '{$this->dbName}/%'");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function quoteSql($sql)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdoCollector = new \DebugBar\DataCollector\PDO\PDOCollector();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $tableName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($seq) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* The default value is null, which means the PDO ATTR_EMULATE_PREPARES value will not be changed
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var array Configuration with database
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'cubrid' => 'yii\db\cubrid\Schema', // CUBRID
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array with database configuration
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $config
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conf = $statement->fetchAll(\PDO::FETCH_KEY_PAIR);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'driver' => $this->getDriverName(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get database info.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @see https://www.php.net/manual/en/function.PDO-lastInsertId.php
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return parent::getLastInsertID(str_replace('#__', $this->tablePrefix, $sequenceName));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdoCollector->addConnection($pdo, $this->dbType);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
++$id;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tableOptions = 'CHARACTER SET utf8 ENGINE=InnoDB';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$key = isset($tableKeys['PRIMARY']) ? ['PRIMARY' => array_keys($tableKeys['PRIMARY'])] : [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $key;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $keys;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get table primary keys.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tableKeys = $this->getTableKeys($tableName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* tokens enclosed within double square brackets are column names. They will be quoted accordingly.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get table unique ID. Temporary function.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (Cache::has('getTableKeys', $tableName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$key = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return type
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getPrimaryKey($tableName)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return Cache::get('getPrimaryKey', $tableName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('mysql' === $this->getDriverName()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Cache::save('getPrimaryKey', $tableName, $key, Cache::LONG);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($row = $dataReader->read()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Cache::save('getTableKeys', $tableName, $keys, Cache::LONG);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$keys = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('mysql' === $this->getDriverName()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = $this->createCommand()->setSql('SHOW KEYS FROM ' . $tableName)->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param type $tableName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 140 characters Open
$keys[$row['Key_name']][$row['Column_name']] = ['columnName' => $row['Column_name'], 'unique' => empty($row['Non_unique'])];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (Cache::has('getPrimaryKey', $tableName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Tokens enclosed within double curly brackets are treated as table names, while
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string the row ID of the last row inserted, or the last value retrieved from the sequence object
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected function createPdoInstance()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$keys[$row['Key_name']][$row['Column_name']] = ['columnName' => $row['Column_name'], 'unique' => empty($row['Non_unique'])];
- Exclude checks