1 | <?php |
||||||
2 | |||||||
3 | namespace EDouna\LaravelDBBackup\Databases; |
||||||
4 | |||||||
5 | use EDouna\LaravelDBBackup\ProcessHandler; |
||||||
6 | use Illuminate\Support\Facades\Config; |
||||||
7 | use SQLiteDatabase; |
||||||
0 ignored issues
–
show
|
|||||||
8 | |||||||
9 | class Database |
||||||
10 | { |
||||||
11 | /** |
||||||
12 | * @var mixed |
||||||
13 | */ |
||||||
14 | protected $database; |
||||||
15 | |||||||
16 | /** |
||||||
17 | * @var array |
||||||
18 | */ |
||||||
19 | public $realDatabase; |
||||||
20 | |||||||
21 | protected $processHandler; |
||||||
22 | |||||||
23 | public $backupFilename; |
||||||
24 | |||||||
25 | protected $storageFolder; |
||||||
26 | |||||||
27 | /** |
||||||
28 | * @var array |
||||||
29 | */ |
||||||
30 | protected $supportedDatabaseDrivers = ['mysql', 'sqlite']; |
||||||
31 | |||||||
32 | public function __construct() |
||||||
33 | { |
||||||
34 | $this->database = Config::get('database.default'); |
||||||
35 | $this->realDatabase = Config::get('database.connections.'.$this->database); |
||||||
36 | $this->processHandler = new ProcessHandler(); |
||||||
37 | } |
||||||
38 | |||||||
39 | public function buildDatabaseClass(): void |
||||||
40 | { |
||||||
41 | switch ($this->realDatabase['driver']) { |
||||||
42 | case 'mysql': |
||||||
43 | $this->realDatabase = $this->buildMySQL($this->realDatabase); |
||||||
0 ignored issues
–
show
It seems like
$this->buildMySQL($this->realDatabase) of type EDouna\LaravelDBBackup\Databases\MySQLDatabase is incompatible with the declared type array of property $realDatabase .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. ![]() |
|||||||
44 | break; |
||||||
45 | case 'sqlite': |
||||||
46 | $this->realDatabase = $this->buildSQLite($this->realDatabase); |
||||||
47 | break; |
||||||
48 | } |
||||||
49 | } |
||||||
50 | |||||||
51 | /** |
||||||
52 | * @return bool |
||||||
53 | */ |
||||||
54 | public function isDatabaseSupported(): bool |
||||||
55 | { |
||||||
56 | return (in_array($this->realDatabase->getDatabaseIdentifier(), $this->supportedDatabaseDrivers)) ? true : false; |
||||||
57 | } |
||||||
58 | |||||||
59 | /** |
||||||
60 | * @return object |
||||||
61 | */ |
||||||
62 | public function getRealDatabase(): object |
||||||
63 | { |
||||||
64 | return $this->realDatabase; |
||||||
0 ignored issues
–
show
|
|||||||
65 | } |
||||||
66 | |||||||
67 | public function setBackupFilename(string $backupFilename): void |
||||||
68 | { |
||||||
69 | $this->backupFilename = $backupFilename; |
||||||
70 | } |
||||||
71 | |||||||
72 | /** |
||||||
73 | * @return string |
||||||
74 | */ |
||||||
75 | public function getBackupFilename(): string |
||||||
76 | { |
||||||
77 | return $this->backupFilename; |
||||||
78 | } |
||||||
79 | |||||||
80 | /** |
||||||
81 | * @param array $database |
||||||
82 | * |
||||||
83 | * @return MySQLDatabase |
||||||
84 | */ |
||||||
85 | protected function buildMySQL(array $database): MySQLDatabase |
||||||
86 | { |
||||||
87 | $this->database = new MySQLDatabase( |
||||||
88 | $database['database'], |
||||||
89 | $database['username'], |
||||||
90 | $database['password'], |
||||||
91 | $database['host'], |
||||||
92 | $database['port'], |
||||||
93 | $this->processHandler |
||||||
94 | ); |
||||||
95 | |||||||
96 | return $this->database; |
||||||
97 | } |
||||||
98 | |||||||
99 | /** |
||||||
100 | * Create an SQLite database instance. |
||||||
101 | * |
||||||
102 | * @param array $database |
||||||
103 | * |
||||||
104 | * @return Databases\SQLiteDatabase |
||||||
0 ignored issues
–
show
The type
EDouna\LaravelDBBackup\D...atabases\SQLiteDatabase was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
105 | */ |
||||||
106 | protected function buildSQLite(array $database): SQLiteDatabase |
||||||
107 | { |
||||||
108 | $this->database = new SQLiteDatabase($database['database']); |
||||||
109 | |||||||
110 | $this->generateBackupFilename(); |
||||||
0 ignored issues
–
show
The method
generateBackupFilename() does not exist on EDouna\LaravelDBBackup\Databases\Database .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
111 | |||||||
112 | return $this->database; |
||||||
0 ignored issues
–
show
|
|||||||
113 | } |
||||||
114 | } |
||||||
115 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: