File::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Maestriam\FileSystem\Foundation;
4
5
use Maestriam\FileSystem\Foundation\File\FileHandler;
6
use Maestriam\FileSystem\Foundation\File\FileInfo;
7
8
class File
9
{
10
    /**
11
     * Nome do arquivo
12
     */
13
    private string $name = '';
14
15
    /**
16
     * Diretório onde será armazenado
17
     */
18
    private string $folder = '';
19
20
    /**
21
     * Manipulador de arquivos no sistema
22
     */
23
    private FileHandler $handler;
0 ignored issues
show
introduced by
The private property $handler is not used, and could be removed.
Loading history...
24
25
    /**
26
     * Undocumented function
27
     *
28
     * @param string $name
29
     */
30
    public function __construct(string $name)
31
    {
32
        $this->setName($name);
33
    }
34
35
    /**
36
     * Retorna/Define o nome e a extensão do arquivo
37
     *
38
     * @param string $name
39
     * @return void
40
     */
41
    public function name(string $name = null)
42
    {
43
        return (! $name) ? $this->getName() : 
0 ignored issues
show
Bug Best Practice introduced by
The expression return ! $name ? $this->...: $this->setName($name) returns the type Maestriam\FileSystem\Foundation\File|string which is incompatible with the documented return type void.
Loading history...
44
                           $this->setName($name);
45
    }
46
47
    /**
48
     * Define o nome e a extensão do arquivo
49
     *
50
     * @param string $name
51
     * @return File
52
     */
53
    public function setName(string $name) : File
54
    {
55
        $this->name = $name;        
56
        return $this;
57
    }
58
    
59
    /**
60
     * Retorna o nome e a extensão do arquivo
61
     *
62
     * @return string
63
     */
64
    public function getName() : string
65
    {
66
        return $this->name;
67
    }
68
69
    /**
70
     * Retorna/Define o diretório onde 
71
     *
72
     * @param string $folder
73
     * @return void
74
     */
75
    public function folder(string $folder = null)
76
    {
77
        return (! $folder) ? $this->getFolder() : 
0 ignored issues
show
Bug Best Practice introduced by
The expression return ! $folder ? $this...his->setFolder($folder) returns the type Maestriam\FileSystem\Foundation\File|string which is incompatible with the documented return type void.
Loading history...
78
                             $this->setFolder($folder);
79
    }    
80
81
    /**
82
     * Retorna o diretório do arquivo
83
     *
84
     * @param string $folder
85
     * @return void
86
     */
87
    public function setFolder(string $folder) : File
88
    {
89
        $this->folder = $folder; 
90
               
91
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Maestriam\FileSystem\Foundation\File which is incompatible with the documented return type void.
Loading history...
92
    }
93
94
    /**
95
     * Retorna o nome e a extensão do arquivo
96
     *
97
     * @return string
98
     */
99
    public function getFolder() : string
100
    {
101
        return $this->folder;
102
    }
103
104
    /**
105
     * Instancia o manipulador para a criação de arquivos
106
     *
107
     * @return FileHandler
108
     */
109
    private function initHandler() : FileHandler
110
    {
111
        if (! $this->folder || ! $this->name) {
112
            throw new \Exception("Error Processing Request");            
113
        }
114
115
        return new FileHandler($this->folder, $this->name);
116
    }
117
    
118
    /**
119
     * Cria um novo arquivo, de acordo com o conteúdo informado
120
     *
121
     * @param string $content
122
     * @return FileInfo
123
     */
124
    public function create(string $content) : FileInfo
125
    {
126
        return $this->initHandler()->create($content);
127
    }
128
}