Skip to content

Commit

Permalink
last fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel committed Dec 16, 2024
1 parent aeb94e4 commit a4480b5
Show file tree
Hide file tree
Showing 29 changed files with 97 additions and 80 deletions.
2 changes: 1 addition & 1 deletion src/N98/Magento/Command/Category/Create/DummyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private function askForArguments(InputInterface $input, OutputInterface $output)

$question = new ChoiceQuestion('Please select Store ID (default: 1)', $_store_ids, self::DEFAULT_STORE_ID);
$question->setErrorMessage('Store ID "%s" is invalid.');
$response = explode('|', $questionHelper->ask($input, $output, $question));
$response = explode('|', (string) $questionHelper->ask($input, $output, $question));
$input->setArgument('store-id', $response[0]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/N98/Magento/Command/Config/SetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$allowZeroScope = $input->getOption('force');
$scope = $input->getOption('scope');
$this->_validateScopeParam($scope);
$scopeId = (int) $this->_convertScopeIdParam($scope, $input->getOption('scope-id'), $allowZeroScope);
$scopeId = (int) $this->_convertScopeIdParam($scope, (string) $input->getOption('scope-id'), $allowZeroScope);
$valueDisplay = $input->getArgument('value');
$value = $valueDisplay;

Expand Down
10 changes: 9 additions & 1 deletion src/N98/Magento/Command/Customer/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace N98\Magento\Command\Customer;

use Mage_Customer_Model_Customer;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -55,8 +56,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$mageCustomerModelResourceCustomerCollection->setPageSize($config['limit']);

$table = [];
/** @var Mage_Customer_Model_Customer $customer */
foreach ($mageCustomerModelResourceCustomerCollection as $customer) {
$table[] = [$customer->getId(), $customer->getEmail(), $customer->getFirstname(), $customer->getLastname(), $this->_getWebsiteCodeById($customer->getwebsiteId())];
$table[] = [
$customer->getId(),
$customer->getEmail(),
$customer->getFirstname(),
$customer->getLastname(),
$this->_getWebsiteCodeById((int) $customer->getwebsiteId()),

Check failure on line 66 in src/N98/Magento/Command/Customer/ListCommand.php

View workflow job for this annotation

GitHub Actions / Analyze (20.10.2, ubuntu-latest, 7.4, 8.0)

Call to an undefined method Mage_Customer_Model_Customer::getwebsiteId().
];
}

if ($table !== []) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function getCompressionHelp(): string
/**
* @deprecated Since 1.97.29; use AbstractCompressor::create() instead
*/
protected function getCompressor(string $type): Compressor
protected function getCompressor(?string $type): Compressor
{
return AbstractCompressor::create($type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getDecompressingCommand(string $command, string $fileName, bool
* @param bool $pipe
* @return string
*/
public function getFileName(string $fileName, bool $pipe = true)
public function getFileName(string $fileName, bool $pipe = true): string
{
if ((string) $fileName === '') {
return $fileName;
Expand Down
9 changes: 4 additions & 5 deletions src/N98/Magento/Command/Database/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use N98\Util\Console\Enabler;
use N98\Util\Exec;
use N98\Util\VerifyOrDie;
use RectorPrefix202411\Symfony\Component\Finder\SplFileInfo;

Check failure on line 12 in src/N98/Magento/Command/Database/DumpCommand.php

View workflow job for this annotation

GitHub Actions / Analyze (20.10.2, ubuntu-latest, 7.4, 8.0)

Referencing prefixed Rector class: RectorPrefix202411\Symfony\Component\Finder\SplFileInfo.
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -466,10 +467,8 @@ protected function getFileName(InputInterface $input, OutputInterface $output, C
$optionAddTime = $input->getOption('add-time');
[$namePrefix, $nameSuffix] = $this->getFileNamePrefixSuffix($optionAddTime);

if ((
($fileName = $input->getArgument('filename')) === null
|| ($isDir = is_dir($fileName))
)
$fileName = $input->getArgument('filename');
if ($fileName === null || $isDir = is_dir((string) $fileName)
&& !$input->getOption('stdout')) {
$defaultName = VerifyOrDie::filename(
$namePrefix . $this->dbSettings['dbname'] . $nameSuffix . $nameExtension,
Expand Down Expand Up @@ -500,7 +499,7 @@ protected function getFileName(InputInterface $input, OutputInterface $output, C
. $pathPartsFilename;
}

return $compressor->getFileName($fileName);
return $compressor->getFileName((string) $fileName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class ClassUtil
{
private string $className;

private ?bool $exists;
private ?bool $exists = null;

public static function create(string $className): ClassUtil
{
Expand Down
4 changes: 2 additions & 2 deletions src/N98/Magento/Command/Eav/Attribute/Create/DummyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$dummyValues = new DummyValues();
for ($i = 0; $i < $argument['values-number']; ++$i) {
$value = $dummyValues->createValue($argument['values-type'], $argument['locale']);
$value = $dummyValues->createValue((string) $argument['values-type'], $argument['locale']);
if (!$this->attributeValueExists($attribute, $value)) {
try {
$attribute->setData('option', ['value' => ['option' => [$value, $value]]]);
Expand Down Expand Up @@ -124,7 +124,7 @@ private function askForArguments(InputInterface $input, OutputInterface $output)

$question = new ChoiceQuestion('Please select Attribute ID', $attribute_codes);
$question->setErrorMessage('Attribute ID "%s" is invalid.');
$response = explode('|', $questionHelper->ask($input, $output, $question));
$response = explode('|', (string) $questionHelper->ask($input, $output, $question));
$input->setArgument('attribute-id', $response[0]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/N98/Magento/Command/Eav/Attribute/Create/DummyValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class DummyValues
{
private ?Generator $generator;
private ?Generator $generator = null;

private array $sizes = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'];

Expand All @@ -41,7 +41,7 @@ public static function getValueTypeList(): array
*/
public function createValue(string $type, string $locale)
{
if (!$this->generator instanceof \Faker\Generator) {
if (!$this->generator instanceof Generator) {
$this->generator = Factory::create($locale);
}

Expand Down
2 changes: 1 addition & 1 deletion src/N98/Magento/Command/Eav/Attribute/ViewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$table[] = ['Frontend-Label', $attribute->getFrontend()->getLabel()];
$table[] = ['Frontend-Class', trim($attribute->getFrontend()->getClass())];
$table[] = ['Frontend-Input', trim($attribute->getFrontend()->getInputType())];
$table[] = ['Frontend-Input-Renderer-Class', trim($attribute->getFrontend()->getInputRendererClass())];
$table[] = ['Frontend-Input-Renderer-Class', trim((string) $attribute->getFrontend()->getInputRendererClass())];
}

$tableHelper = $this->getTableHelper();
Expand Down
18 changes: 9 additions & 9 deletions src/N98/Magento/Command/Indexer/AbstractIndexerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ protected function getIndexerList(): array
*/
protected function getRuntime(Mage_Index_Model_Process $mageIndexModelProcess): string
{
$dateTime = new DateTimeUtils();
$startTime = new DateTime($mageIndexModelProcess->getStartedAt());
$endTime = new DateTime($mageIndexModelProcess->getEndedAt());
$dateTime = new DateTimeUtils();
$startTime = new DateTime((string) $mageIndexModelProcess->getStartedAt());
$endTime = new DateTime((string) $mageIndexModelProcess->getEndedAt());
if ($startTime > $endTime) {
return 'index not finished';
}
Expand All @@ -84,8 +84,8 @@ protected function disableObservers(): void
*/
protected function getRuntimeInSeconds(Mage_Index_Model_Process $mageIndexModelProcess): int
{
$startTimestamp = strtotime($mageIndexModelProcess->getStartedAt());
$endTimestamp = strtotime($mageIndexModelProcess->getEndedAt());
$startTimestamp = strtotime((string) $mageIndexModelProcess->getStartedAt());
$endTimestamp = strtotime((string) $mageIndexModelProcess->getEndedAt());
return $endTimestamp - $startTimestamp;
}

Expand Down Expand Up @@ -145,17 +145,17 @@ protected function executeProcesses(OutputInterface $output, array $processes):
$isSuccessful = true;

try {
\Mage::dispatchEvent('shell_reindex_init_process');
Mage::dispatchEvent('shell_reindex_init_process');
foreach ($processes as $process) {
if (!$this->executeProcess($output, $process)) {
$isSuccessful = false;
}
}

\Mage::dispatchEvent('shell_reindex_finalize_process');
Mage::dispatchEvent('shell_reindex_finalize_process');
} catch (Exception $exception) {
$isSuccessful = false;
\Mage::dispatchEvent('shell_reindex_finalize_process');
Mage::dispatchEvent('shell_reindex_finalize_process');
}

return $isSuccessful;
Expand All @@ -175,7 +175,7 @@ private function executeProcess(OutputInterface $output, Mage_Index_Model_Proces

try {
$mageIndexModelProcess->reindexEverything();
\Mage::dispatchEvent($mageIndexModelProcess->getIndexerCode() . '_shell_reindex_after');
Mage::dispatchEvent($mageIndexModelProcess->getIndexerCode() . '_shell_reindex_after');
} catch (Exception $exception) {
$errorMessage = $exception->getMessage();
$isSuccessful = false;
Expand Down
5 changes: 2 additions & 3 deletions src/N98/Magento/Command/LocalConfig/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,11 @@ protected function _getLocalConfigFilename()
* in case the string has length and not the whole string can be wrapped in a CDATA section (because it contains
* a sequence that can not be part of a CDATA section "]]>") the part that can well be.
*
* @param string $string
*
* @return string CDATA section or equivalent
*/
protected function _wrapCData($string)
protected function _wrapCData(?string $string): string
{
$string = is_null($string) ? '' : $string;
$buffer = strtr($string, [']]>' => ']]>]]&gt;<![CDATA[']);
$buffer = '<![CDATA[' . $buffer . ']]>';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,26 @@ protected function initConfigPaths(): void
$this->registerStoreConfigPath('baseUrl', 'web/' . $this->class . '/base_url');
}

protected function checkSettings(Result $result, Mage_Core_Model_Store $mageCoreModelStore, string $baseUrl): void
protected function checkSettings(Result $result, ?Mage_Core_Model_Store $mageCoreModelStore, string $baseUrl): void
{
$errorMessage = 'Wrong hostname configured. <info>Hostname must contain a dot</info>';

/** @var string $host */
$host = parse_url($baseUrl, PHP_URL_HOST);
$isValid = (bool) strstr($host, '.');

$storeCode = $mageCoreModelStore ? $mageCoreModelStore->getCode() : 'n/a';

$result->setStatus($isValid);
if ($isValid) {
$result->setMessage(
'<info>' . ucfirst($this->class) . ' BaseURL: <comment>' . $baseUrl . '</comment> of Store: <comment>' .
$mageCoreModelStore->getCode() . '</comment> - OK',
$storeCode . '</comment> - OK',
);
} else {
$result->setMessage(
'<error>Invalid ' . ucfirst($this->class) . ' BaseURL: <comment>' . $baseUrl .
'</comment> of Store: <comment>' . $mageCoreModelStore->getCode() . '</comment> ' . $errorMessage . '</error>',
'</comment> of Store: <comment>' . $storeCode . '</comment> ' . $errorMessage . '</error>',
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,31 @@ protected function initConfigPaths(): void
$this->registerStoreConfigPath('cookieDomain', 'web/cookie/cookie_domain');
}

protected function checkSettings(Result $result, Mage_Core_Model_Store $mageCoreModelStore, string $baseUrl, string $cookieDomain): void
protected function checkSettings(Result $result, ?Mage_Core_Model_Store $mageCoreModelStore, string $baseUrl, ?string $cookieDomain): void
{
$errorMessage = 'cookie-domain and ' . $this->class . ' base-URL do not match';
$errorMessage = 'cookie-domain and ' . $this->class . ' base-URL do not match';
$websiteCode = $mageCoreModelStore ? $mageCoreModelStore->getCode() : '';

if (strlen($cookieDomain) !== 0) {
if ($cookieDomain && strlen($cookieDomain) !== 0) {
$isValid = $this->validateCookieDomainAgainstUrl($cookieDomain, $baseUrl);

$result->setStatus($isValid);

if ($isValid) {
$result->setMessage(
'<info>Cookie Domain (' . $this->class . '): <comment>' . $cookieDomain .
'</comment> of Store: <comment>' . $mageCoreModelStore->getCode() . '</comment> - OK</info>',
'</comment> of Store: <comment>' . $websiteCode . '</comment> - OK</info>',
);
} else {
$result->setMessage(
'<error>Cookie Domain (' . $this->class . '): <comment>' . $cookieDomain .
'</comment> of Store: <comment>' . $mageCoreModelStore->getCode() . '</comment> - ERROR: ' . $errorMessage .
'</comment> of Store: <comment>' . $websiteCode . '</comment> - ERROR: ' . $errorMessage .
'</error>',
);
}
} else {
$result->setMessage(
'<info>Empty cookie Domain (' . $this->class . ') of Store: <comment>' . $mageCoreModelStore->getCode() .
'<info>Empty cookie Domain (' . $this->class . ') of Store: <comment>' . $websiteCode .
'</comment> - OK</info>',
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/N98/Magento/Command/System/Cron/ServerEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class ServerEnvironment
{
private ?array $backup;
private ?array $backup = null;

private array $keys = ['SCRIPT_NAME', 'SCRIPT_FILENAME'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$time = microtime(true);
$modules = $config->getNode('modules');
/** @var Mage_Core_Model_Resource_Resource $mageCoreModelAbstract */
$mageCoreModelAbstract = Mage::getModel('core/resource');
$mageCoreModelAbstract = Mage::getModel('core/resource_resource');
/** @var Mage_Core_Model_Config_Element $node */
$node = $config->getNode('global/resources');
$setups = $node->children();
Expand Down
2 changes: 1 addition & 1 deletion src/N98/Magento/DbSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function setFile(string $file): void
);
}

$saved = libxml_use_internal_errors(true);
$saved = libxml_use_internal_errors(true);
$config = simplexml_load_file($file);
libxml_use_internal_errors($saved);

Expand Down
2 changes: 1 addition & 1 deletion src/N98/Util/AutoloadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class AutoloadHandler
*/
private $callback;

private bool $splRegistered;
private bool $splRegistered = false;

private bool $enabled;

Expand Down
2 changes: 1 addition & 1 deletion src/N98/Util/Console/Helper/DatabaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private function resolveTablesArray(?array $carry = null, $item = null): array
* @return array|false
* @throws RuntimeException
*/
public function getTables(bool $withoutPrefix = false)
public function getTables(?bool $withoutPrefix = false)
{
$pdo = $this->getConnection();
$prefix = $this->dbSettings['prefix'];
Expand Down
5 changes: 2 additions & 3 deletions src/N98/Util/Console/Helper/Table/Renderer/XmlRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ private function appendRowFields(DOMElement $domElement, array $fields): void
{
$index = 0;
foreach ($fields as $key => $value) {
/** @var string $header */
$header = $this->getHeader($index++, $key);
$element = $this->createField($domElement->ownerDocument, $header, (string) $value);
$element = $this->createField($domElement->ownerDocument, (string) $header, (string) $value);
$domElement->appendChild($element);
}
}
Expand All @@ -85,7 +84,7 @@ private function appendHeaders(DOMNode $domNode, ?array $headers = null): void
$domNode = $domNode->appendChild($doc->createElement('headers'));

foreach ($headers as $header) {
$domNode->appendChild($doc->createElement('header', $header));
$domNode->appendChild($doc->createElement('header', (string) $header));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/N98/Util/VerifyOrDie.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class VerifyOrDie
/**
* Portable basename
*/
public static function filename(string $basename, ?string $message = null): string
public static function filename(?string $basename, ?string $message = null): string
{
static::argumentType('basename', 'string', $basename);
if (null !== $message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace N98\Magento\Command\Admin\User;

use Mage_Admin_Model_Roles;
use Mage_Admin_Model_Rules;
use Mage_Admin_Model_User;
use N98\Magento\Command\TestCase;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Tester\CommandTester;
Expand All @@ -23,7 +26,7 @@ public function setUp(): void
->setMethods(['getUserModel', 'getRoleModel', 'getRulesModel'])
->getMock();

$this->userModel = $this->getMockBuilder('Mage_Admin_Model_User')
$this->userModel = $this->getMockBuilder(Mage_Admin_Model_User::class)
->setMethods(['setData', 'save', 'setRoleIds', 'getUserId', 'setRoleUserId', 'saveRelations'])
->disableOriginalConstructor()
->getMock();
Expand All @@ -32,7 +35,7 @@ public function setUp(): void
->method('getUserModel')
->willReturn($this->userModel);

$this->roleModel = $this->getMockBuilder('Mage_Admin_Model_Role')
$this->roleModel = $this->getMockBuilder(Mage_Admin_Model_Roles::class)
->setMethods(['load', 'getId', 'setName', 'setRoleType', 'save'])
->disableOriginalConstructor()
->getMock();
Expand All @@ -41,7 +44,7 @@ public function setUp(): void
->method('getRoleModel')
->willReturn($this->roleModel);

$this->rulesModel = $this->getMockBuilder('Mage_Admin_Model_Rules')
$this->rulesModel = $this->getMockBuilder(Mage_Admin_Model_Rules::class)
->setMethods(['setRoleId', 'setResources', 'saveRel'])
->disableOriginalConstructor()
->getMock();
Expand Down
Loading

0 comments on commit a4480b5

Please sign in to comment.