FileRegistrator::returnFile()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
1
<?php
2
namespace Finder\Spider\Registrator;
3
4
use Finder\Contracts\Spider\TargetManager;
5
6
use Stalker\Models\File;
7
use Finder\Models\Digital\Internet\ComputerFile;
8
9
/**
10
 * Run all script analysers and outputs their result.
11
 */
12
class FileRegistrator extends TargetManager
13
{
14
    protected $file = false;
15
    protected $computerFile = false;
16
17
    public function __construct($target, $parent = false)
18
    {
19
        parent::__construct($target, $parent);
20
21
        $computer = $this->returnComputerFile();
0 ignored issues
show
Unused Code introduced by
$computer is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
22
        // @todo Verificar se alterou o arquivo e gravar o novo arquivo
23
    }
24
25
    private function returnComputerFile()
26
    {
27
        if ($this->computerFile) {
28
            return $this->computerFile;
29
        }
30
31
        if (!$this->computerFile = ComputerFile::where('location', $this->getLocation())->first()) {
32
            $this->computerFile = ComputerFile::create($this->getArray());
33
        }
34
        
35
        return $this->computerFile;
36
    }
37
38
    protected function returnFile()
39
    {
40
        if ($this->file) {
41
            return $this->file;
42
        }
43
44
        $md5 = md5($this->getTarget()->getContents());
0 ignored issues
show
Bug introduced by
The method getContents cannot be called on $this->getTarget() (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
45
46
        if ($this->file = File::where('location', $md5)->first()) {
47
            return $this->file;
48
        }
49
50
        return $this->file = File::create(
51
            [
52
            'location' => $md5,
53
            'name' => $this->getTarget()->getFilename()
0 ignored issues
show
Bug introduced by
The method getFilename cannot be called on $this->getTarget() (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
54
            ]
55
        );
56
    }
57
58
    private function getArray()
59
    {
60
        $target = $this->getTarget();
61
62
        $array = [
63
            'file_id' => $this->returnFile()->id,
64
        ];
65
66
        if ($this->isStringPath) {
67
            return array_merge(
68
                $array, [
69
                'location' => $target
70
                ]
71
            );
72
        }
73
74
        return array_merge(
75
            $array, [
76
        
77
            // dd($target);
78
            'location' => $this->getLocation(),
79
            'path' => self::clearUrl($target->getPath()),
0 ignored issues
show
Bug introduced by
The method getPath cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
80
            'filename' => self::clearUrl($target->getFilename()),
0 ignored issues
show
Bug introduced by
The method getFilename cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
81
            'basename' => self::clearUrl($target->getBasename()),
0 ignored issues
show
Bug introduced by
The method getBasename cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
82
            'pathname' => self::clearUrl($target->getPathname()),
0 ignored issues
show
Bug introduced by
The method getPathname cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
83
            'extension' => self::clearUrl($target->getExtension()),
0 ignored issues
show
Bug introduced by
The method getExtension cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
84
            'realPath' => self::clearUrl($target->getRealPath()),
0 ignored issues
show
Bug introduced by
The method getRealPath cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
85
            'aTime' => self::clearUrl($target->getATime()),
0 ignored issues
show
Bug introduced by
The method getATime cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
86
            'mTime' => self::clearUrl($target->getMTime()),
0 ignored issues
show
Bug introduced by
The method getMTime cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
87
            'cTime' => self::clearUrl($target->getCTime()),
0 ignored issues
show
Bug introduced by
The method getCTime cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
88
            'inode' => self::clearUrl($target->getInode()),
0 ignored issues
show
Bug introduced by
The method getInode cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
89
            'size' => self::clearUrl($target->getSize()),
0 ignored issues
show
Bug introduced by
The method getSize cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
90
            'perms' => self::clearUrl($target->getPerms()),
0 ignored issues
show
Bug introduced by
The method getPerms cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
91
            'owner' => self::clearUrl($target->getOwner()),
0 ignored issues
show
Bug introduced by
The method getOwner cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
92
            'group' => self::clearUrl($target->getGroup()),
0 ignored issues
show
Bug introduced by
The method getGroup cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
93
            'type' => self::clearUrl($target->getType()),
0 ignored issues
show
Bug introduced by
The method getType cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
94
            'writable' => $target->isWritable(),
0 ignored issues
show
Bug introduced by
The method isWritable cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
95
            'readable' => $target->isReadable(),
0 ignored issues
show
Bug introduced by
The method isReadable cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
96
            'executable' => $target->isExecutable(),
0 ignored issues
show
Bug introduced by
The method isExecutable cannot be called on $target (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
97
            // 'file' => $target->getFile(),
98
            // 'dir' => $target->getDir(),
99
            // 'link' => $target->getLink(),
100
            ]
101
        );
102
    }
103
}