Test Failed
Push — master ( 5904eb...0e6af8 )
by Phaniraj
05:25
created

ImportExportLog   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 15
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLogs() 0 4 1
A logImportError() 0 6 1
1
<?php
2
3
namespace LWS\ImportExport;
4
5
use LWS\ImportExport\Models\Import;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, LWS\ImportExport\Import. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
7
class ImportExportLog
8
{
9
    public function logImportError(Import $import, $data, $message)
10
    {
11
        // Create new log
12
        return $import->importLogs()->create([
0 ignored issues
show
Bug introduced by
Are you sure the usage of $import->importLogs() targeting LWS\ImportExport\Models\Import::importLogs() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
13
            'data' => $data,
14
            'message' => $message,
15
        ]);
16
    }
17
18
    public function getLogs($id)
19
    {
20
        // Get all logs of a import or export process
21
        return Import::findOrFail($id)->importLogs()->get(['data', 'message'])->toArray();
22
    }
23
}
24