LocalFileDeletion   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 39
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteLocalFileIfEnabled() 0 4 2
A deleteLocalFileAfterUpload() 0 5 1
A isLocalFileDeletingEnabled() 0 3 1
1
<?php
2
3
namespace Sfneal\Helpers\Aws\S3\Utils\Traits;
4
5
trait LocalFileDeletion
6
{
7
    /**
8
     * @var bool Enable/disable deleting the local file after it's been uploaded
9
     */
10
    protected $deleteLocalFileAfterUpload = false;
11
12
    /**
13
     * Enable deleting the local file after it's been uploaded.
14
     *
15
     * @return $this
16
     */
17
    public function deleteLocalFileAfterUpload(): self
18
    {
19
        $this->deleteLocalFileAfterUpload = true;
20
21
        return $this;
22
    }
23
24
    /**
25
     * Delete the local file path if post upload file deletion is enabled.
26
     *
27
     * @param string $localFilePath
28
     */
29
    protected function deleteLocalFileIfEnabled(string $localFilePath): void
30
    {
31
        if ($this->isLocalFileDeletingEnabled()) {
32
            unlink($localFilePath);
33
        }
34
    }
35
36
    /**
37
     * Determine if deleting the local file after it's been uploaded is enabled.
38
     *
39
     * @return bool
40
     */
41
    private function isLocalFileDeletingEnabled(): bool
42
    {
43
        return $this->deleteLocalFileAfterUpload;
44
    }
45
}
46