for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Maketok\DataMigration\Storage\Db;
class DBALMysqlResourceInsertNoLoad extends DBALMysqlResource
{
/**
* {@inheritdoc}
* override, add support for inserts
* if server does not support Local Infile option
*/
public function loadData(
A high number of parameters is generally an indication that you should consider creating a dedicated object for the parameters.
Let’s take a look at an example:
<?php class SomeClass { public function doSomething(A $a, B $b, C $c, D $d, E $e, F $f) { // .. } } class AnotherClass { public function doSomething(A $a, B $b, C $c, D $d, E $e, F $f) { // ... } }
could be refactored to:
class Context { private $a; private $b; private $c; private $d; private $e; private $f; public function __construct(A $a, B $b, C $c, D $d, E $e, F $f) { // ... } } class SomeClass { public function doSomething(Context $context) { // ... } } class AnotherClass { public function doSomething(Context $context) { // ... } }
$table,
$file,
$local = false,
array $columns = [],
array $set = [],
$delimiter = ",",
$enclosure = '"',
$escape = '\\',
$termination = '\n',
$optionallyEnclosed = true
) {
$csv = new \SplFileObject($file, 'r');
$table = $this->connection->quoteIdentifier($table);
$columnsPart = '';
if (!empty($columns)) {
$columns = array_map([$this->connection, 'quoteIdentifier'], $columns);
$columnsPart = '(' . implode(',', $columns) . ')';
}
$valuesPart = '';
$row = $csv->fgetcsv($delimiter, $enclosure, $escape);
$csv->rewind();
if (!empty($row)) {
$row = array_map(function () {
return '?';
}, $row);
$valuesPart = '(' . implode(',', $row) . ')';
$sql = <<<MYSQL
INSERT INTO $table $columnsPart
VALUES $valuesPart
MYSQL;
$count = 0;
while (
($row = $csv->fgetcsv($delimiter, $enclosure, $escape)) !== null &&
$row != [null] &&
$row !== false
$row = array_map(function ($var) {
if ($var === '\N') {
return null;
return $var;
$count += $this->connection->executeUpdate($sql, $row);
return $count;
A high number of parameters is generally an indication that you should consider creating a dedicated object for the parameters.
Let’s take a look at an example:
could be refactored to: