Issues (16)

src/Helper/DB/SQLServer.php (4 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * neuralyzer : Data Anonymization Library and CLI Tool
7
 *
8
 * PHP Version 7.2
9
 *
10
 * @author Emmanuel Dyan
11
 *
12
 * @copyright 2020 Emmanuel Dyan
13
 *
14
 * @package edyan/neuralyzer
15
 *
16
 * @license GNU General Public License v2.0
17
 *
18
 * @link https://github.com/edyan/neuralyzer
19
 */
20
21
namespace Edyan\Neuralyzer\Helper\DB;
22
23
use Edyan\Neuralyzer\Exception\NeuralyzerException;
24
25
/**
26
 * Various methods related to SQLServer
27
 */
28
class SQLServer extends AbstractDBHelper
29
{
30
    /**
31 1
     * Set the right enclosure
32
     */
33 1
    public function getEnclosureForCSV(): string
34
    {
35
        return chr(0);
36
    }
37
38
    /**
39 2
     * {@inheritdoc}
40
     */
41 2
    public function loadData(string $table, string $fname, array $fields, string $mode): string
42 1
    {
43
        if (substr(gethostbyname($this->conn->getHost()), 0, 3) !== '127') {
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Connection::getHost() has been deprecated. ( Ignorable by Annotation )

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

43
        if (substr(gethostbyname(/** @scrutinizer ignore-deprecated */ $this->conn->getHost()), 0, 3) !== '127') {
Loading history...
It seems like $this->conn->getHost() can also be of type null; however, parameter $hostname of gethostbyname() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

43
        if (substr(gethostbyname(/** @scrutinizer ignore-type */ $this->conn->getHost()), 0, 3) !== '127') {
Loading history...
44
            throw new NeuralyzerException('SQL Server must be on the same host than PHP');
45 1
        }
46 1
47
        $sql = "BULK INSERT {$table} FROM '{$fname}' WITH (
48
            FIELDTERMINATOR = '|', DATAFILETYPE = 'widechar', ROWTERMINATOR = '" . PHP_EOL . "'
49 1
        )";
50
51
        if ($this->pretend === false) {
52
            if ($mode === 'update') {
53
                $this->conn->query("TRUNCATE TABLE {$table}");
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Connection::query() has been deprecated: Use {@link executeQuery()} instead. ( Ignorable by Annotation )

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

53
                /** @scrutinizer ignore-deprecated */ $this->conn->query("TRUNCATE TABLE {$table}");

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
54
            }
55
56
            $this->conn->query($sql);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Connection::query() has been deprecated: Use {@link executeQuery()} instead. ( Ignorable by Annotation )

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

56
            /** @scrutinizer ignore-deprecated */ $this->conn->query($sql);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
57 1
        }
58
59
        return $sql;
60
    }
61
}
62