Skip to content

Commit 36d08f4

Browse files
authored
Merge pull request #2 from Codexshaper/analysis-7aW4N2
Apply fixes from StyleCI
2 parents 553b6e7 + 5395df2 commit 36d08f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+288
-418
lines changed

config/dbm.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
return [
34
/*
45
|-------------------------------------------------------------

routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
Route::group(['prefix' => 'database', 'namespace' => config('dbm.controller_namespace')], function () {
34
//Database Table
45
Route::get('/', 'DatabaseController@index');

src/Commands/DatabaseAdmin.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace CodexShaper\DBM\Commands;
34

45
use CodexShaper\DBM\Facades\Manager;
@@ -41,9 +42,10 @@ protected function getOptions()
4142
*/
4243
protected function findComposer()
4344
{
44-
if (file_exists(getcwd() . '/composer.phar')) {
45-
return '"' . PHP_BINARY . '" ' . getcwd() . '/composer.phar';
45+
if (file_exists(getcwd().'/composer.phar')) {
46+
return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar';
4647
}
48+
4749
return 'composer';
4850
}
4951

@@ -63,7 +65,7 @@ public function handle()
6365

6466
if ($this->argument('action') == 'drop') {
6567
$permissions = [];
66-
$successMessage = "Admin Deleted successfully";
68+
$successMessage = 'Admin Deleted successfully';
6769
}
6870

6971
$permissions = [];

src/Commands/DatabaseBackup.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace CodexShaper\DBM\Commands;
34

45
use CodexShaper\DBM\Facades\Driver;
@@ -43,23 +44,24 @@ protected function getOptions()
4344
*/
4445
protected function findComposer()
4546
{
46-
if (file_exists(getcwd() . '/composer.phar')) {
47-
return '"' . PHP_BINARY . '" ' . getcwd() . '/composer.phar';
47+
if (file_exists(getcwd().'/composer.phar')) {
48+
return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar';
4849
}
50+
4951
return 'composer';
5052
}
5153

5254
public function getFileName($table, $database)
5355
{
5456
$prefix = (strlen($table) > 0)
55-
? 'table_' . strtolower(str_replace('-', '_', $table)) . '_'
56-
: 'database_' . strtolower(str_replace('-', '_', $database)) . '_';
57+
? 'table_'.strtolower(str_replace('-', '_', $table)).'_'
58+
: 'database_'.strtolower(str_replace('-', '_', $database)).'_';
5759

5860
$extension = Driver::isMongoDB() ? '' : '.sql';
59-
$fileName = $prefix . 'backup_' . date('G_a_m_d_y_h_i_s') . $extension;
61+
$fileName = $prefix.'backup_'.date('G_a_m_d_y_h_i_s').$extension;
6062

6163
if (Driver::isSqlite()) {
62-
$fileName = 'backup_' . date('G_a_m_d_y_h_i_s') . $extension;
64+
$fileName = 'backup_'.date('G_a_m_d_y_h_i_s').$extension;
6365
}
6466

6567
return $fileName;
@@ -72,18 +74,18 @@ public function backup(Dumper $dumper, array $data)
7274
$compressBinaryPath = config('dbm.backup.compress_binary_path', '');
7375
$compressCommand = config('dbm.backup.compress_command', 'gzip');
7476
$compressExtension = config('dbm.backup.compress_extension', '.gz');
75-
$dumpBinaryPath = config('dbm.backup.' . $data['driver'] . '.binary_path', '');
77+
$dumpBinaryPath = config('dbm.backup.'.$data['driver'].'.binary_path', '');
7678

7779
switch ($data['driver']) {
7880
case 'mysql':
7981
case 'pgsql':
80-
if (!empty($data['table'])) {
82+
if (! empty($data['table'])) {
8183
$dumper->setTables($data['table']);
8284
}
8385
break;
8486
case 'mongodb':
8587
$dsn = config('dbm.backup.mongodb.dsn', '');
86-
if (!empty($dsn) && method_exists($dumper, 'setUri')) {
88+
if (! empty($dsn) && method_exists($dumper, 'setUri')) {
8789
$dumper->setUri($dsn);
8890
}
8991
break;
@@ -115,17 +117,17 @@ public function handle(Filesystem $filesystem, Dumper $dumper)
115117
$this->info('Start Database Backup');
116118

117119
$driver = dbm_driver();
118-
$database = config('database.connections.' . $driver . '.database', 'dbm');
120+
$database = config('database.connections.'.$driver.'.database', 'dbm');
119121
$table = ($this->option('table') != null) ? $this->option('table') : '';
120122

121123
try {
122124
$directory = (config('dbm.backup.dir', 'backups') != '')
123-
? DIRECTORY_SEPARATOR . config('dbm.backup.dir', 'backups')
125+
? DIRECTORY_SEPARATOR.config('dbm.backup.dir', 'backups')
124126
: '';
125-
$directoryPath = storage_path('app') . $directory . DIRECTORY_SEPARATOR . $driver;
126-
$filePath = $directoryPath . DIRECTORY_SEPARATOR . $this->getFileName($table, $database);
127+
$directoryPath = storage_path('app').$directory.DIRECTORY_SEPARATOR.$driver;
128+
$filePath = $directoryPath.DIRECTORY_SEPARATOR.$this->getFileName($table, $database);
127129

128-
if (!File::isDirectory($directoryPath)) {
130+
if (! File::isDirectory($directoryPath)) {
129131
File::makeDirectory($directoryPath, 0777, true, true);
130132
}
131133

@@ -138,8 +140,6 @@ public function handle(Filesystem $filesystem, Dumper $dumper)
138140
$this->info('Backup completed');
139141
} catch (\Exception $e) {
140142
throw new \Exception($e->getMessage(), 1);
141-
142143
}
143-
144144
}
145145
}

src/Commands/DatabaseRestore.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace CodexShaper\DBM\Commands;
34

45
use CodexShaper\Dumper\Contracts\Dumper;
@@ -43,9 +44,10 @@ protected function getOptions()
4344
*/
4445
protected function findComposer()
4546
{
46-
if (file_exists(getcwd() . '/composer.phar')) {
47-
return '"' . PHP_BINARY . '" ' . getcwd() . '/composer.phar';
47+
if (file_exists(getcwd().'/composer.phar')) {
48+
return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar';
4849
}
50+
4951
return 'composer';
5052
}
5153

@@ -67,29 +69,29 @@ public function handle(Filesystem $filesystem, Dumper $dumper)
6769
$password = config('database.connections.mysql.password', '');
6870

6971
$driver = dbm_driver();
70-
$directory = 'backups' . DIRECTORY_SEPARATOR . $driver;
72+
$directory = 'backups'.DIRECTORY_SEPARATOR.$driver;
7173

7274
if ($this->option('path') != null) {
7375
$path = $this->option('path');
7476
} elseif ($this->option('file') != null) {
75-
$path = $directory . DIRECTORY_SEPARATOR . $this->option('file');
77+
$path = $directory.DIRECTORY_SEPARATOR.$this->option('file');
7678
} else {
7779
$files = array_reverse(Storage::files($directory));
7880
$path = $files[0];
7981
}
8082

81-
$filePath = storage_path('app') . DIRECTORY_SEPARATOR . $path;
83+
$filePath = storage_path('app').DIRECTORY_SEPARATOR.$path;
8284
$isCompress = config('dbm.backup.compress', false);
8385
$compressBinaryPath = config('dbm.backup.compress_binary_path', '');
8486
$compressCommand = config('dbm.backup.uncompress_command', 'gunzip');
8587
$compressExtension = config('dbm.backup.compress_extension', '.gz');
86-
$dumpBinaryPath = config('dbm.backup.' . $driver . '.binary_path', '');
88+
$dumpBinaryPath = config('dbm.backup.'.$driver.'.binary_path', '');
8789

8890
try {
8991
switch ($driver) {
9092
case 'mongodb':
9193
$dsn = config('dbm.backup.mongodb.dsn', '');
92-
if (!empty($dsn)) {
94+
if (! empty($dsn)) {
9395
$dumper->setUri($dsn);
9496
}
9597
break;
@@ -103,11 +105,8 @@ public function handle(Filesystem $filesystem, Dumper $dumper)
103105
->restore();
104106

105107
$this->info('Restored Completed');
106-
107108
} catch (\Exception $e) {
108-
109109
throw new \Exception($e->getMessage(), 1);
110-
111110
}
112111
}
113112
}

src/Commands/InstallDatabaseManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace CodexShaper\DBM\Commands;
34

45
use CodexShaper\DBM\ManagerServiceProvider;
@@ -50,6 +51,7 @@ protected function findComposer()
5051
if (file_exists(getcwd().'/composer.phar')) {
5152
return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar';
5253
}
54+
5355
return 'composer';
5456
}
5557

src/Contracts/Relationships.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace CodexShaper\DBM\Contracts;
34

45
use Illuminate\Database\Eloquent\Relations\BelongsTo;

src/Database/Drivers/MongoDB.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function getDB()
7575
*/
7676
public function getNamespace($databaseName, $collectionName)
7777
{
78-
return $databaseName . '.' . $collectionName;
78+
return $databaseName.'.'.$collectionName;
7979
}
8080

8181
/**
@@ -157,12 +157,11 @@ public function getCollection($collectionName)
157157
*/
158158
public function updateCollection($collection)
159159
{
160-
161160
$newName = $collection['name'];
162161
$oldName = $collection['oldName'];
163162
$collectionName = $oldName;
164163
$connection = config('database.default');
165-
$database = config('database.connections.' . $connection . '.database');
164+
$database = config('database.connections.'.$connection.'.database');
166165
$fromNs = $this->getNamespace($database, $oldName);
167166
$toNs = $this->getNamespace($database, $newName);
168167

@@ -175,7 +174,6 @@ public function updateCollection($collection)
175174
Index::setIndexes($this->selectCollection($collectionName), $collection['indexes']);
176175

177176
return true;
178-
179177
}
180178

181179
/**
@@ -195,7 +193,6 @@ public function renameColumns($collectionName, $fields)
195193
if ($field->oldName != $field->name) {
196194
$renames[$field->oldName] = $field->name;
197195
}
198-
199196
}
200197
}
201198
$update = [];
@@ -246,7 +243,7 @@ public function addColumns($collectionName)
246243
$columnNames[] = $columnName;
247244
}
248245

249-
if ($id != '' && !in_array($newField, $columnNames)) {
246+
if ($id != '' && ! in_array($newField, $columnNames)) {
250247
$update['$set'] = [$newField => ''];
251248
$collection->updateOne(
252249
['_id' => new \MongoDB\BSON\ObjectID($id)],
@@ -256,7 +253,6 @@ public function addColumns($collectionName)
256253
}
257254
}
258255
}
259-
260256
}
261257
}
262258

@@ -276,7 +272,7 @@ public function removeColumns($collectionName)
276272
$unsets = [];
277273

278274
foreach ($columns as $column) {
279-
if (!in_array($column, $newFields)) {
275+
if (! in_array($column, $newFields)) {
280276
$unsets[$column] = '';
281277
}
282278
}
@@ -363,7 +359,6 @@ public function getColumns($collectionName)
363359
$columns = [];
364360

365361
if ($collection = DBM_Collection::where('name', $collectionName)->first()) {
366-
367362
$fields = $collection->fields;
368363
foreach ($fields as $field) {
369364
$columns[] = (object) [
@@ -407,5 +402,4 @@ public function getColumnsName($collectionName)
407402
{
408403
return DBM_Collection::where('name', $collectionName)->first()->fields->pluck('name')->toArray();
409404
}
410-
411405
}

src/Database/Drivers/MongoDB/Index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static function setIndexes(Collection $collection, $indexes)
8383
$indexType = $indexDetails['type'];
8484
$options = $indexDetails['options'];
8585

86-
$options['name'] = strtolower($collection->getCollectionName() . '_' . $column . '_' . $type);
86+
$options['name'] = strtolower($collection->getCollectionName().'_'.$column.'_'.$type);
8787

8888
$options['ns'] = $collection->getNamespace();
8989

@@ -150,6 +150,7 @@ public static function getIndexDetails($type)
150150
$indexType = -1;
151151
break;
152152
}
153+
153154
return ['type' => $indexType, 'options' => $options];
154155
}
155156
}

src/Database/Drivers/MongoDB/Traits/IndexTrait.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ protected static function getCommonType(IndexInfo $index)
1717

1818
if ($index->isText()) {
1919
$type = 'TEXT';
20-
} else if ($index->is2dSphere()) {
20+
} elseif ($index->is2dSphere()) {
2121
$type = '2DSPARSE';
22-
} else if ($index->isTtl()) {
22+
} elseif ($index->isTtl()) {
2323
$type = 'TTL';
24-
} else if ($index->isGeoHaystack()) {
24+
} elseif ($index->isGeoHaystack()) {
2525
$type = 'GEOHAYSTACK';
2626
}
2727

@@ -73,11 +73,12 @@ protected static function getDefaultType(IndexInfo $index)
7373

7474
if ($type == 'asc') {
7575
return 'ASC';
76-
} else if ($type == 'index') {
76+
} elseif ($type == 'index') {
7777
return 'INDEX';
78-
} else if ($type == 'desc') {
78+
} elseif ($type == 'desc') {
7979
return 'DESC';
8080
}
81+
8182
return '';
8283
}
8384

@@ -88,7 +89,7 @@ protected static function getDefaultType(IndexInfo $index)
8889
*/
8990
protected static function checkUnique(IndexInfo $index)
9091
{
91-
return $index->isUnique() && !$index->isSparse() && !static::checkDescending($index) ? true : false;
92+
return $index->isUnique() && ! $index->isSparse() && ! static::checkDescending($index) ? true : false;
9293
}
9394

9495
/**
@@ -98,7 +99,7 @@ protected static function checkUnique(IndexInfo $index)
9899
*/
99100
protected static function checkUniqueDesc(IndexInfo $index)
100101
{
101-
return $index->isUnique() && !$index->isSparse() && static::checkDescending($index) ? true : false;
102+
return $index->isUnique() && ! $index->isSparse() && static::checkDescending($index) ? true : false;
102103
}
103104

104105
/**
@@ -108,7 +109,7 @@ protected static function checkUniqueDesc(IndexInfo $index)
108109
*/
109110
protected static function checkSparse(IndexInfo $index)
110111
{
111-
return $index->isSparse() && !static::checkDescending($index) ? true : false;
112+
return $index->isSparse() && ! static::checkDescending($index) ? true : false;
112113
}
113114

114115
/**
@@ -118,7 +119,7 @@ protected static function checkSparse(IndexInfo $index)
118119
*/
119120
protected static function checkSparseUnique(IndexInfo $index)
120121
{
121-
return $index->isSparse() && $index->isUnique() && !static::checkDescending($index) ? true : false;
122+
return $index->isSparse() && $index->isUnique() && ! static::checkDescending($index) ? true : false;
122123
}
123124

124125
/**
@@ -155,6 +156,7 @@ protected static function checkDescending(IndexInfo $index)
155156
return true;
156157
}
157158
}
159+
158160
return false;
159161
}
160162
}

0 commit comments

Comments
 (0)