phpstan fixes

This commit is contained in:
Dennis Eichhorn 2021-10-10 16:07:06 +02:00
parent 0d26d19e51
commit 2cd76f6460
6 changed files with 61 additions and 48 deletions

View File

@ -74,14 +74,6 @@ use phpOMS\Utils\IO\Zip\Zip;
*/ */
final class Importer extends ImporterAbstract final class Importer extends ImporterAbstract
{ {
/**
* Database connection.
*
* @var ConnectionAbstract
* @since 1.0.0
*/
private ConnectionAbstract $remote;
/** /**
* Account * Account
* *
@ -465,7 +457,7 @@ final class Importer extends ImporterAbstract
$media[$number] = new Media(); $media[$number] = new Media();
$media[$number]->name = (string) $number; $media[$number]->name = (string) $number;
$media[$number]->type = 'backend_image'; $media[$number]->type = null;
$media[$number]->setPath('/Modules/Media/Files/Modules/ItemManagement/Articles/Images/' . $image); $media[$number]->setPath('/Modules/Media/Files/Modules/ItemManagement/Articles/Images/' . $image);
$media[$number]->setVirtualPath('/Modules/ItemManagement/Articles/Images'); $media[$number]->setVirtualPath('/Modules/ItemManagement/Articles/Images');
$media[$number]->extension = \explode('.', $image)[1]; $media[$number]->extension = \explode('.', $image)[1];

View File

@ -32,7 +32,7 @@ final class Importer extends ImporterAbstract
* *
* @param RequestAbstract $request Request * @param RequestAbstract $request Request
* *
* @return bool * @return array
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -17,6 +17,7 @@ namespace Modules\Exchange\Interfaces\OMS;
use Modules\Exchange\Models\ExchangeLog; use Modules\Exchange\Models\ExchangeLog;
use Modules\Exchange\Models\ExchangeType; use Modules\Exchange\Models\ExchangeType;
use Modules\Exchange\Models\ExporterAbstract; use Modules\Exchange\Models\ExporterAbstract;
use phpOMS\Localization\L11nManager;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\Message\RequestAbstract; use phpOMS\Message\RequestAbstract;
use phpOMS\Utils\StringUtils; use phpOMS\Utils\StringUtils;
@ -31,14 +32,6 @@ use phpOMS\Utils\StringUtils;
*/ */
final class Exporter extends ExporterAbstract final class Exporter extends ExporterAbstract
{ {
/**
* Database connection.
*
* @var ConnectionAbstract
* @since 1.0.0
*/
private ConnectionAbstract $remote;
/** /**
* Account * Account
* *
@ -48,16 +41,12 @@ final class Exporter extends ExporterAbstract
private int $account = 1; private int $account = 1;
/** /**
* Constructor * {@inheritdoc}
*
* @param ConnectionAbstract $local Database connection
*
* @since 1.0.0
*/ */
public function __construct(ConnectionAbstract $local) public function __construct(ConnectionAbstract $local, L11nManager $l11n)
{ {
$this->local = $local; parent::__construct($local, $l11n);
$this->app->l11nManager->loadLanguageFile('Exchange', __DIR__ . '/Lang/lang.php'); $this->l11n->loadLanguageFile('Exchange', __DIR__ . '/Lang/lang.php');
} }
/** /**
@ -72,7 +61,7 @@ final class Exporter extends ExporterAbstract
*/ */
public function export(\DateTime $start, \DateTime $end) : void public function export(\DateTime $start, \DateTime $end) : void
{ {
$this->exportLanguage($start, $end); $this->exportLanguage();
} }
/** /**
@ -91,13 +80,15 @@ final class Exporter extends ExporterAbstract
$this->account = $request->header->account; $this->account = $request->header->account;
$result = [];
if ($request->getData('type') === 'language') { if ($request->getData('type') === 'language') {
$result = $this->exportLanguage(); $result = $this->exportLanguage();
$log = new ExchangeLog(); $log = new ExchangeLog();
$log->createdBy = $this->account; $log->createdBy = $this->account;
$log->setType(ExchangeType::EXPORT); $log->setType(ExchangeType::EXPORT);
$log->message = $this->app->l11nManager->getText($request->header->l11n->getLanguage(), 'Exchange', '', 'LangFileExported'); $log->message = $this->l11n->getText($request->header->l11n->getLanguage(), 'Exchange', '', 'LangFileExported');
$log->subtype = 'language'; $log->subtype = 'language';
$log->exchange = (int) $request->getData('id'); $log->exchange = (int) $request->getData('id');
@ -214,6 +205,11 @@ final class Exporter extends ExporterAbstract
$template = \file_get_contents($item->getPathname()); $template = \file_get_contents($item->getPathname());
$keys = []; $keys = [];
if ($template === false) {
continue; // @codeCoverageIgnore
}
\preg_match_all('/(\$this\->getHtml\(\')([0-9a-zA-Z:]+)(\'\))/', $template, $keys, \PREG_PATTERN_ORDER); \preg_match_all('/(\$this\->getHtml\(\')([0-9a-zA-Z:]+)(\'\))/', $template, $keys, \PREG_PATTERN_ORDER);
foreach ($keys[2] ?? [] as $key) { foreach ($keys[2] ?? [] as $key) {

View File

@ -16,6 +16,7 @@ namespace Modules\Exchange\Interfaces\OMS;
use Modules\Exchange\Models\ExchangeLog; use Modules\Exchange\Models\ExchangeLog;
use Modules\Exchange\Models\ExchangeType; use Modules\Exchange\Models\ExchangeType;
use phpOMS\Localization\L11nManager;
use Modules\Exchange\Models\ImporterAbstract; use Modules\Exchange\Models\ImporterAbstract;
use Modules\Media\Controller\ApiController; use Modules\Media\Controller\ApiController;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
@ -34,14 +35,6 @@ use phpOMS\Message\RequestAbstract;
*/ */
final class Importer extends ImporterAbstract final class Importer extends ImporterAbstract
{ {
/**
* Database connection.
*
* @var ConnectionAbstract
* @since 1.0.0
*/
private ConnectionAbstract $remote;
/** /**
* Account * Account
* *
@ -51,16 +44,12 @@ final class Importer extends ImporterAbstract
private int $account = 1; private int $account = 1;
/** /**
* Constructor * {@inheritdoc}
*
* @param ConnectionAbstract $local Database connection
*
* @since 1.0.0
*/ */
public function __construct(ConnectionAbstract $local) public function __construct(ConnectionAbstract $local, ConnectionAbstract $remote, L11nManager $l11n)
{ {
$this->local = $local; parent::__construct($local, $remote, $l11n);
$this->app->l11nManager->loadLanguageFile('Exchange', __DIR__ . '/Lang/lang.php'); $this->l11n->loadLanguageFile('Exchange', __DIR__ . '/Lang/lang.php');
} }
/** /**
@ -119,7 +108,7 @@ final class Importer extends ImporterAbstract
$log = new ExchangeLog(); $log = new ExchangeLog();
$log->createdBy = $this->account; $log->createdBy = $this->account;
$log->setType(ExchangeType::IMPORT); $log->setType(ExchangeType::IMPORT);
$log->message = $this->app->l11nManager->getText($request->header->l11n->getLanguage(), 'Exchange', '', 'LangFileImported'); $log->message = $this->l11n->getText($request->header->l11n->getLanguage(), 'Exchange', '', 'LangFileImported');
$log->subtype = 'language'; $log->subtype = 'language';
$log->exchange = (int) $request->getData('id'); $log->exchange = (int) $request->getData('id');
@ -147,6 +136,10 @@ final class Importer extends ImporterAbstract
$header = \fgetcsv($fp, 0, ';', '"'); $header = \fgetcsv($fp, 0, ';', '"');
if ($header === false) {
return; // @codeCoverageIgnore
}
$languageArray = []; $languageArray = [];
$supportedLanguages = \array_slice($header, 4); $supportedLanguages = \array_slice($header, 4);
$keyLengths = []; $keyLengths = [];

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace Modules\Exchange\Models; namespace Modules\Exchange\Models;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\Localization\L11nManager;
use phpOMS\Message\RequestAbstract; use phpOMS\Message\RequestAbstract;
/** /**
@ -35,16 +36,26 @@ abstract class ExporterAbstract
*/ */
protected ConnectionAbstract $local; protected ConnectionAbstract $local;
/**
* L11n manager.
*
* @var L11nManager
* @since 1.0.0
*/
protected L11nManager $l11n;
/** /**
* Constructor * Constructor
* *
* @param ConnectionAbstract $local Database connection * @param ConnectionAbstract $local Database connection
* @param L11nManager $l11n Localization manager
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function __construct(ConnectionAbstract $local) public function __construct(ConnectionAbstract $local, L11nManager $l11n)
{ {
$this->local = $local; $this->local = $local;
$this->l11n = $l11n;
} }
/** /**

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace Modules\Exchange\Models; namespace Modules\Exchange\Models;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\Localization\L11nManager;
use phpOMS\Message\RequestAbstract; use phpOMS\Message\RequestAbstract;
/** /**
@ -27,6 +28,14 @@ use phpOMS\Message\RequestAbstract;
*/ */
abstract class ImporterAbstract abstract class ImporterAbstract
{ {
/**
* Database connection.
*
* @var ConnectionAbstract
* @since 1.0.0
*/
protected ConnectionAbstract $remote;
/** /**
* Database connection. * Database connection.
* *
@ -35,16 +44,28 @@ abstract class ImporterAbstract
*/ */
protected ConnectionAbstract $local; protected ConnectionAbstract $local;
/**
* L11n manager.
*
* @var L11nManager
* @since 1.0.0
*/
protected L11nManager $l11n;
/** /**
* Constructor * Constructor
* *
* @param ConnectionAbstract $local Database connection * @param ConnectionAbstract $local Database connection
* @param ConnectionAbstract $remote Database connection
* @param L11nManager $l11n Localization manager
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function __construct(ConnectionAbstract $local) public function __construct(ConnectionAbstract $local, ConnectionAbstract $remote, L11nManager $l11n)
{ {
$this->local = $local; $this->local = $local;
$this->remote = $remote;
$this->l11n = $l11n;
} }
/** /**