Skip to content

Commit b48d432

Browse files
committed
magento-engcom/magento2ce#2639: Minor coding practices improvements
1 parent 68a2508 commit b48d432

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

app/code/Magento/Backup/Model/Db.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use Magento\Backup\Helper\Data as Helper;
99
use Magento\Backup\Model\ResourceModel\Table\GetListTables;
10-
use Magento\Backup\Model\ResourceModel\View\GetViewsBackup;
10+
use Magento\Backup\Model\ResourceModel\View\CreateViewsBackup;
1111
use Magento\Framework\App\ObjectManager;
1212
use Magento\Framework\Exception\RuntimeException;
1313

@@ -51,7 +51,7 @@ class Db implements \Magento\Framework\Backup\Db\BackupDbInterface
5151
private $getListTables;
5252

5353
/**
54-
* @var GetViewsBackup
54+
* @var CreateViewsBackup
5555
*/
5656
private $getViewsBackup;
5757

@@ -61,20 +61,20 @@ class Db implements \Magento\Framework\Backup\Db\BackupDbInterface
6161
* @param \Magento\Framework\App\ResourceConnection $resource
6262
* @param Helper|null $helper
6363
* @param GetListTables|null $getListTables
64-
* @param GetViewsBackup|null $getViewsBackup
64+
* @param CreateViewsBackup|null $getViewsBackup
6565
*/
6666
public function __construct(
67-
\Magento\Backup\Model\ResourceModel\Db $resourceDb,
67+
ResourceModel\Db $resourceDb,
6868
\Magento\Framework\App\ResourceConnection $resource,
6969
?Helper $helper = null,
70-
GetListTables $getListTables = null,
71-
GetViewsBackup $getViewsBackup = null
70+
?GetListTables $getListTables = null,
71+
?CreateViewsBackup $getViewsBackup = null
7272
) {
7373
$this->_resourceDb = $resourceDb;
7474
$this->_resource = $resource;
7575
$this->helper = $helper ?? ObjectManager::getInstance()->get(Helper::class);
76-
$this->getListTables = $getListTables ?: ObjectManager::getInstance()->get(GetListTables::class);
77-
$this->getViewsBackup = $getViewsBackup ?: ObjectManager::getInstance()->get(GetViewsBackup::class);
76+
$this->getListTables = $getListTables ?? ObjectManager::getInstance()->get(GetListTables::class);
77+
$this->getViewsBackup = $getViewsBackup ?? ObjectManager::getInstance()->get(CreateViewsBackup::class);
7878
}
7979

8080
/**

app/code/Magento/Backup/Model/ResourceModel/Table/GetListTables.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Framework\App\ResourceConnection;
1111

1212
/**
13-
* Class GetListTables
13+
* Provides full list of tables in the database. This list excludes views, to allow different backup process.
1414
*/
1515
class GetListTables
1616
{
@@ -30,11 +30,11 @@ public function __construct(ResourceConnection $resource)
3030
}
3131

3232
/**
33-
* Get base tables
33+
* Get list of database tables excluding views.
3434
*
3535
* @return array
3636
*/
37-
public function execute()
37+
public function execute(): array
3838
{
3939
return $this->resource->getConnection('backup')->fetchCol(
4040
"SHOW FULL TABLES WHERE `Table_type` = ?",

app/code/Magento/Backup/Model/ResourceModel/View/GetViewsBackup.php renamed to app/code/Magento/Backup/Model/ResourceModel/View/CreateViewsBackup.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
use Magento\Framework\DB\Adapter\AdapterInterface;
1313

1414
/**
15-
* Class GetViewsBackup
15+
* Creates backup of Views in the database.
1616
*/
17-
class GetViewsBackup
17+
class CreateViewsBackup
1818
{
1919
/**
2020
* @var GetListViews
@@ -44,27 +44,27 @@ public function __construct(
4444
}
4545

4646
/**
47-
* Backup
47+
* Write backup data to backup file.
4848
*
4949
* @param BackupInterface $backup
5050
*/
51-
public function execute(BackupInterface $backup)
51+
public function execute(BackupInterface $backup): void
5252
{
5353
$views = $this->getListViews->execute();
5454

5555
foreach ($views as $view) {
5656
$backup->write($this->getViewHeader($view));
5757
$backup->write($this->getDropViewSql($view));
58-
$backup->write($this->getShowCreateView($view));
58+
$backup->write($this->getCreateView($view));
5959
}
6060
}
6161

6262
/**
63-
* Get connection
63+
* Retrieve Database connection for Backup.
6464
*
6565
* @return AdapterInterface
6666
*/
67-
private function getConnection()
67+
private function getConnection(): AdapterInterface
6868
{
6969
if (!$this->connection) {
7070
$this->connection = $this->resourceConnection->getConnection('backup');
@@ -74,12 +74,12 @@ private function getConnection()
7474
}
7575

7676
/**
77-
* Get show create view
77+
* Get CREATE VIEW query for the specific view.
7878
*
7979
* @param string $viewName
8080
* @return string
8181
*/
82-
private function getShowCreateView($viewName)
82+
private function getCreateView(string $viewName): string
8383
{
8484
$quotedViewName = $this->getConnection()->quoteIdentifier($viewName);
8585
$query = 'SHOW CREATE VIEW ' . $quotedViewName;
@@ -91,26 +91,26 @@ private function getShowCreateView($viewName)
9191
}
9292

9393
/**
94-
* Get view header
94+
* Prepare a header for View being dumped.
9595
*
9696
* @param string $viewName
9797
* @return string
9898
*/
99-
public function getViewHeader($viewName)
99+
public function getViewHeader(string $viewName): string
100100
{
101101
$quotedViewName = $this->getConnection()->quoteIdentifier($viewName);
102102
return "\n--\n" . "-- Structure for view {$quotedViewName}\n" . "--\n\n";
103103
}
104104

105105
/**
106-
* Get drop view SQL
106+
* Make sure that View being created is deleted if already exists.
107107
*
108108
* @param string $viewName
109109
* @return string
110110
*/
111-
public function getDropViewSql($viewName)
111+
public function getDropViewSql(string $viewName): string
112112
{
113113
$quotedViewName = $this->getConnection()->quoteIdentifier($viewName);
114-
return sprintf('DROP VIEW IF EXISTS %s;' . "\n", $quotedViewName);
114+
return sprintf('DROP VIEW IF EXISTS %s;\n', $quotedViewName);
115115
}
116116
}

app/code/Magento/Backup/Model/ResourceModel/View/GetListViews.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
use Magento\Framework\App\ResourceConnection;
1111

1212
/**
13-
* Class GetListViews
13+
* Get list of database views.
1414
*/
1515
class GetListViews
1616
{
1717
private const TABLE_TYPE = 'VIEW';
18+
1819
/**
1920
* @var ResourceConnection
2021
*/
@@ -29,11 +30,11 @@ public function __construct(ResourceConnection $resource)
2930
}
3031

3132
/**
32-
* Get view tables
33+
* Get list of database views.
3334
*
3435
* @return array
3536
*/
36-
public function execute()
37+
public function execute(): array
3738
{
3839
return $this->resource->getConnection('backup')->fetchCol(
3940
"SHOW FULL TABLES WHERE `Table_type` = ?",

app/code/Magento/Elasticsearch6/Block/Adminhtml/System/Config/TestConnection.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
namespace Magento\Elasticsearch6\Block\Adminhtml\System\Config;
77

88
/**
9-
* Elasticsearch 6x test connection block
10-
* @codeCoverageIgnore
9+
* Elasticsearch 6.x test connection block
1110
*/
1211
class TestConnection extends \Magento\AdvancedSearch\Block\Adminhtml\System\Config\TestConnection
1312
{

0 commit comments

Comments
 (0)