Test Failed
Push — master ( 8ae349...d51c96 )
by Stephen
01:07 queued 11s
created

LocalFileDeletion::isLocalFileDeletingEnabled()   A

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 0
dl 0
loc 3
rs 10
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