keboola/php-csv

View on GitHub

Showing 12 of 13 total issues

Remove error control operator '@' on line 95.
Open

    public function writeRow(array $row)
    {
        $str = $this->rowToStr($row);
        try {
            $ret = @fwrite($this->getFilePointer(), $str);
Severity: Minor
Found in src/CsvWriter.php by phpmd

ErrorControlOperator

Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

Example

function foo($filePath) {
    $file = @fopen($filPath); // hides exceptions
    $key = @$array[$notExistingKey]; // assigns null to $key
}

Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

Remove error control operator '@' on line 127.
Open

    protected function detectLineBreak()
    {
        @rewind($this->getFilePointer());
        $sample = @fread($this->getFilePointer(), self::SAMPLE_SIZE);
        if (substr((string) $sample, -1) === "\r") {
Severity: Minor
Found in src/CsvReader.php by phpmd

ErrorControlOperator

Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

Example

function foo($filePath) {
    $file = @fopen($filPath); // hides exceptions
    $key = @$array[$notExistingKey]; // assigns null to $key
}

Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

Remove error control operator '@' on line 148.
Open

    protected function readLine()
    {
        // allow empty enclosure hack
        $enclosure = !$this->getEnclosure() ? chr(0) : $this->getEnclosure();
        $escapedBy = !$this->getEscapedBy() ? chr(0) : $this->getEscapedBy();
Severity: Minor
Found in src/CsvReader.php by phpmd

ErrorControlOperator

Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

Example

function foo($filePath) {
    $file = @fopen($filPath); // hides exceptions
    $key = @$array[$notExistingKey]; // assigns null to $key
}

Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

Remove error control operator '@' on line 132.
Open

    protected function detectLineBreak()
    {
        @rewind($this->getFilePointer());
        $sample = @fread($this->getFilePointer(), self::SAMPLE_SIZE);
        if (substr((string) $sample, -1) === "\r") {
Severity: Minor
Found in src/CsvReader.php by phpmd

ErrorControlOperator

Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

Example

function foo($filePath) {
    $file = @fopen($filPath); // hides exceptions
    $key = @$array[$notExistingKey]; // assigns null to $key
}

Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

Remove error control operator '@' on line 70.
Open

    protected function openCsvFile($fileName)
    {
        try {
            $this->filePointer = @fopen($fileName, 'w');
        } catch (ValueError $e) {
Severity: Minor
Found in src/CsvWriter.php by phpmd

ErrorControlOperator

Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

Example

function foo($filePath) {
    $file = @fopen($filPath); // hides exceptions
    $key = @$array[$notExistingKey]; // assigns null to $key
}

Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

Remove error control operator '@' on line 113.
Open

    protected function openCsvFile($fileName)
    {
        if (!is_file($fileName)) {
            throw new Exception(
                'Cannot open file ' . $fileName,
Severity: Minor
Found in src/CsvReader.php by phpmd

ErrorControlOperator

Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

Example

function foo($filePath) {
    $file = @fopen($filPath); // hides exceptions
    $key = @$array[$notExistingKey]; // assigns null to $key
}

Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

Remove error control operator '@' on line 131.
Open

    protected function detectLineBreak()
    {
        @rewind($this->getFilePointer());
        $sample = @fread($this->getFilePointer(), self::SAMPLE_SIZE);
        if (substr((string) $sample, -1) === "\r") {
Severity: Minor
Found in src/CsvReader.php by phpmd

ErrorControlOperator

Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

Example

function foo($filePath) {
    $file = @fopen($filPath); // hides exceptions
    $key = @$array[$notExistingKey]; // assigns null to $key
}

Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

Remove error control operator '@' on line 128.
Open

    protected function detectLineBreak()
    {
        @rewind($this->getFilePointer());
        $sample = @fread($this->getFilePointer(), self::SAMPLE_SIZE);
        if (substr((string) $sample, -1) === "\r") {
Severity: Minor
Found in src/CsvReader.php by phpmd

ErrorControlOperator

Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

Example

function foo($filePath) {
    $file = @fopen($filPath); // hides exceptions
    $key = @$array[$notExistingKey]; // assigns null to $key
}

Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

Function detectAndRemoveBOM has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public static function detectAndRemoveBOM($header)
    {
        if (!is_array($header) || empty($header) || $header[0] === null) {
            return $header;
        }
Severity: Minor
Found in src/UTF8BOMHelper.php - About 25 mins to fix

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

The method setFile uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            throw new InvalidArgumentException('Invalid file: ' . var_export($file, true));
        }
Severity: Minor
Found in src/AbstractCsvFile.php by phpmd

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 'Keboola\Csv\LineBreaksHelper' in method 'detectLineBreak'.
Open

        return LineBreaksHelper::detectLineBreaks($sample, $this->getEnclosure(), $this->getEscapedBy());
Severity: Minor
Found in src/CsvReader.php by phpmd

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 'Keboola\Csv\UTF8BOMHelper' in method '__construct'.
Open

        $header = UTF8BOMHelper::detectAndRemoveBOM($this->readLine());
Severity: Minor
Found in src/CsvReader.php by phpmd

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

Severity
Category
Status
Source
Language