FileDumper::getExtension()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

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
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Cerbero\SqlDumper\Dumpers;
4
5
use Illuminate\Support\Facades\App;
6
use Illuminate\Support\Facades\Config;
7
8
/**
9
 * Abstract implementation of a file dumper.
10
 *
11
 */
12
abstract class FileDumper implements DumperInterface
13
{
14
    /**
15
     * The path of the file to generate.
16
     *
17
     * @var string
18
     */
19
    protected $path;
20
21
    /**
22
     * The file extension.
23
     *
24
     * @var string
25
     */
26
    protected $extension;
27
28
    /**
29
     * The file content.
30
     *
31
     * @var string
32
     */
33
    protected $content = '';
34
35
    /**
36
     * Instantiate the class.
37
     *
38
     * @param string $path
39
     */
40 24
    public function __construct(string $path = null)
41
    {
42 24
        $this->path = $path ?: $this->getDefaultPath();
43 24
    }
44
45
    /**
46
     * Retrieve the default file path
47
     *
48
     * @return string
49
     */
50 15
    protected function getDefaultPath(): string
51
    {
52 15
        if ($path = Config::get('sql_dumper.' . static::class . '.path')) {
53 6
            return $path;
54
        }
55
56 9
        return App::storagePath() . '/sql_dump_' . time() . '.' . $this->getExtension();
57
    }
58
59
    /**
60
     * Retrieve the file extension
61
     *
62
     * @return string
63
     */
64 9
    protected function getExtension(): string
65
    {
66 9
        return (string) $this->extension;
67
    }
68
69
    /**
70
     * Retrieve the file path
71
     *
72
     * @return string
73
     */
74 3
    public function getPath(): string
75
    {
76 3
        return $this->path;
77
    }
78
79
    /**
80
     * Retrieve the file content
81
     *
82
     * @return string
83
     */
84 3
    public function getContent(): string
85
    {
86 3
        return $this->content;
87
    }
88
89
    /**
90
     * Dump queries information
91
     *
92
     * @return mixed
93
     */
94 12
    public function dump()
95
    {
96 12
        file_put_contents($this->path, $this->content);
97
98 12
        $this->content = '';
99 12
    }
100
}
101