Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added shell/ to checks #2848

Merged
merged 5 commits into from
Dec 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@
- .phpstorm.meta.php/*

'phpcs':
- phpcs*
- .phpcs*
- .github/workflows/phpcs.yml

'php-cs-fixer':
Expand Down
3 changes: 2 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
'app/code/core/Mage/',
'lib/Mage/',
'lib/Magento/',
'lib/Varien/'
'lib/Varien/',
'shell/',
])
->name('*.php')
->ignoreDotFiles(true)
Expand Down
1 change: 1 addition & 0 deletions .phpcs.ecg.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<file>lib/Mage/</file>
<file>lib/Magento/</file>
<file>lib/Varien/</file>
<file>shell/</file>
<!--
<rule ref="Ecg" />
-->
Expand Down
1 change: 1 addition & 0 deletions .phpcs.php.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<file>lib/Mage/</file>
<file>lib/Magento/</file>
<file>lib/Varien/</file>
<file>shell/</file>
<rule ref="PHPCompatibility" />
<rule ref="PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore">
<exclude-pattern>*/Varien/Object.php*</exclude-pattern>
Expand Down
5 changes: 5 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<file>lib/Mage/</file>
<file>lib/Magento/</file>
<file>lib/Varien/</file>
<file>shell/</file>
<!-- file contains include/include_once/... -->
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<!-- controllers -->
Expand All @@ -26,6 +27,10 @@
<exclude-pattern>*/core/Mage/Downloadable/controllers/Adminhtml/Downloadable/Product/EditController.php*</exclude-pattern>
<exclude-pattern>*/core/Mage/Downloadable/controllers/Product/EditController.php*</exclude-pattern>
<exclude-pattern>*/core/Mage/Downloadable/controllers/FileController.php*</exclude-pattern>
<exclude-pattern>*/shell/indexer.php*</exclude-pattern>
<exclude-pattern>*/shell/log.php*</exclude-pattern>
<exclude-pattern>*/shell/translations.php*</exclude-pattern>
<exclude-pattern>*/shell/update-copyright.php*</exclude-pattern>
<!-- others (@todo check) -->
<exclude-pattern>*/lib/Varien/Db/Tree/Exception.php*</exclude-pattern>
<exclude-pattern>*/lib/Varien/Db/Tree/Node.php*</exclude-pattern>
Expand Down
5 changes: 5 additions & 0 deletions phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7859,3 +7859,8 @@ parameters:
message: "#^Strict comparison using \\=\\=\\= between string and false will always evaluate to false\\.$#"
count: 1
path: lib/Varien/Simplexml/Config.php

-
message: "#^Strict comparison using \\=\\=\\= between '' and 'dump' will always evaluate to false\\.$#"
count: 1
path: shell/update-copyright.php
1 change: 1 addition & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ parameters:
- lib/Mage
- lib/Magento
- lib/Varien
- shell
excludePaths:
# removed and fixed modules (OM-2811, OM-2813)
- app/code/core/Mage/Backup/*
Expand Down
10 changes: 5 additions & 5 deletions shell/abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ abstract class Mage_Shell_Abstract
/**
* Magento Root path
*
* @var string
* @var string|null
*/
protected $_rootPath;

Expand All @@ -61,7 +61,7 @@ abstract class Mage_Shell_Abstract
*
* @var array
*/
protected $_args = array();
protected $_args = [];

/**
* Factory instance
Expand Down Expand Up @@ -112,7 +112,7 @@ protected function _applyPhpVariables()
if (file_exists($htaccess)) {
// parse htaccess file
$data = file_get_contents($htaccess);
$matches = array();
$matches = [];
preg_match_all('#^\s+?php_value\s+([a-z_]+)\s+(.+)$#siUm', $data, $matches, PREG_SET_ORDER);
if ($matches) {
foreach ($matches as $match) {
Expand All @@ -137,14 +137,14 @@ protected function _parseArgs()
{
$current = null;
foreach ($_SERVER['argv'] as $arg) {
$match = array();
$match = [];
if (preg_match('#^--([\w\d_-]{1,})$#', $arg, $match) || preg_match('#^-([\w\d_]{1,})$#', $arg, $match)) {
$current = $match[1];
$this->_args[$current] = true;
} else {
if ($current) {
$this->_args[$current] = $arg;
} else if (preg_match('#^([\w\d_]{1,})$#', $arg, $match)) {
} elseif (preg_match('#^([\w\d_]{1,})$#', $arg, $match)) {
$this->_args[$match[1]] = true;
}
}
Expand Down
30 changes: 14 additions & 16 deletions shell/indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Mage_Shell_Indexer extends Mage_Shell_Abstract
/**
* Get Indexer instance
*
* @return Mage_Index_Model_Indexer
* @return Mage_Core_Model_Abstract|Mage_Index_Model_Indexer
*/
protected function _getIndexer()
{
Expand All @@ -48,7 +48,7 @@ protected function _getIndexer()
*/
protected function _parseIndexerString($string)
{
$processes = array();
$processes = [];
if ($string == 'all') {
$collection = $this->_getIndexer()->getProcessesCollection();
foreach ($collection as $process) {
Expand All @@ -57,11 +57,11 @@ protected function _parseIndexerString($string)
}
$processes[] = $process;
}
} else if (!empty($string)) {
} elseif (!empty($string)) {
$codes = explode(',', $string);
$codes = array_map('trim', $codes);
$processes = $this->_getIndexer()->getProcessesCollectionByCodes($codes);
foreach($processes as $key => $process) {
foreach ($processes as $key => $process) {
if ($process->getIndexer()->getVisibility() === false) {
unset($processes[$key]);
}
Expand All @@ -79,22 +79,22 @@ protected function _parseIndexerString($string)
*/
public function run()
{
$_SESSION = array();
$_SESSION = [];
if ($this->getArg('info')) {
$processes = $this->_parseIndexerString('all');
/** @var Mage_Index_Model_Process $process */
foreach ($processes as $process) {
/* @var $process Mage_Index_Model_Process */
echo sprintf('%-30s', $process->getIndexerCode());
echo $process->getIndexer()->getName() . "\n";
}
} else if ($this->getArg('status') || $this->getArg('mode')) {
} elseif ($this->getArg('status') || $this->getArg('mode')) {
if ($this->getArg('status')) {
$processes = $this->_parseIndexerString($this->getArg('status'));
} else {
$processes = $this->_parseIndexerString($this->getArg('mode'));
}
/** @var Mage_Index_Model_Process $process */
foreach ($processes as $process) {
/* @var $process Mage_Index_Model_Process */
$status = 'unknown';
if ($this->getArg('status')) {
switch ($process->getStatus()) {
Expand Down Expand Up @@ -124,19 +124,18 @@ public function run()
break;
}
}
echo sprintf('%-35s ', $process->getIndexer()->getName() . ':') . $status ."\n";

echo sprintf('%-35s ', $process->getIndexer()->getName() . ':') . $status . "\n";
}
} else if ($this->getArg('mode-realtime') || $this->getArg('mode-manual')) {
} elseif ($this->getArg('mode-realtime') || $this->getArg('mode-manual')) {
if ($this->getArg('mode-realtime')) {
$mode = Mage_Index_Model_Process::MODE_REAL_TIME;
$processes = $this->_parseIndexerString($this->getArg('mode-realtime'));
} else {
$mode = Mage_Index_Model_Process::MODE_MANUAL;
$processes = $this->_parseIndexerString($this->getArg('mode-manual'));
}
/** @var Mage_Index_Model_Process $process */
foreach ($processes as $process) {
/* @var $process Mage_Index_Model_Process */
try {
$process->setMode($mode)->save();
echo $process->getIndexer()->getName() . " index was successfully changed index mode\n";
Expand All @@ -147,7 +146,7 @@ public function run()
echo $e . "\n";
}
}
} else if ($this->getArg('reindex') || $this->getArg('reindexall') || $this->getArg('reindexallrequired')) {
} elseif ($this->getArg('reindex') || $this->getArg('reindexall') || $this->getArg('reindexallrequired')) {
if ($this->getArg('reindex')) {
$processes = $this->_parseIndexerString($this->getArg('reindex'));
} else {
Expand All @@ -156,12 +155,12 @@ public function run()

try {
Mage::dispatchEvent('shell_reindex_init_process');
/** @var Mage_Index_Model_Process $process */
foreach ($processes as $process) {
//reindex only if required
if( $this->getArg('reindexallrequired') && $process->getStatus() == Mage_Index_Model_Process::STATUS_PENDING ) {
if ($this->getArg('reindexallrequired') && $process->getStatus() == Mage_Index_Model_Process::STATUS_PENDING) {
continue;
}
/* @var $process Mage_Index_Model_Process */
try {
$startTime = microtime(true);
$process->reindexEverything();
Expand All @@ -181,7 +180,6 @@ public function run()
Mage::dispatchEvent('shell_reindex_finalize_process');
echo $e->getMessage() . "\n";
}

} else {
echo $this->usageHelp();
}
Expand Down
33 changes: 20 additions & 13 deletions shell/log.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Mage_Shell_Log extends Mage_Shell_Abstract
/**
* Log instance
*
* @var Mage_Log_Model_Log
* @var Mage_Log_Model_Log|null
*/
protected $_log;

Expand All @@ -58,14 +58,17 @@ protected function _getLog()
protected function _humanCount($number)
{
if ($number < 1000) {
return $number;
} else if ($number >= 1000 && $number < 1000000) {
return (string)$number;
}
if ($number < 1000000) {
return sprintf('%.2fK', $number / 1000);
} else if ($number >= 1000000 && $number < 1000000000) {
}

if ($number < 1000000000) {
return sprintf('%.2fM', $number / 1000000);
} else {
return sprintf('%.2fB', $number / 1000000000);
}

return sprintf('%.2fB', $number / 1000000000);
}

/**
Expand All @@ -78,13 +81,17 @@ protected function _humanSize($number)
{
if ($number < 1000) {
return sprintf('%d b', $number);
} else if ($number >= 1000 && $number < 1000000) {
}

if ($number < 1000000) {
return sprintf('%.2fKb', $number / 1000);
} else if ($number >= 1000000 && $number < 1000000000) {
}

if ($number < 1000000000) {
return sprintf('%.2fMb', $number / 1000000);
} else {
return sprintf('%.2fGb', $number / 1000000000);
}

return sprintf('%.2fGb', $number / 1000000000);
}

/**
Expand All @@ -100,11 +107,11 @@ public function run()
}
$this->_getLog()->clean();
echo "Log cleaned\n";
} else if ($this->getArg('status')) {
} elseif ($this->getArg('status')) {
$resource = $this->_getLog()->getResource();
$adapter = $resource->getReadConnection();
// log tables
$tables = array(
$tables = [
$resource->getTable('log/customer'),
$resource->getTable('log/visitor'),
$resource->getTable('log/visitor_info'),
Expand All @@ -117,7 +124,7 @@ public function run()
$resource->getTable('reports/event'),

$resource->getTable('catalog/compare_item'),
);
];

$rows = 0;
$dataLengh = 0;
Expand Down
Loading