improve code

This commit is contained in:
Daniel Seifert 2021-12-20 13:41:24 +01:00
parent 67c462ccda
commit e604b84849
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
23 changed files with 77 additions and 75 deletions

View File

@ -19,14 +19,11 @@ use D3\DataWizard\Application\Model\Configuration;
use D3\DataWizard\Application\Model\Exceptions\DataWizardException;
use D3\DataWizard\Application\Model\Exceptions\DebugException;
use D3\ModCfg\Application\Model\d3database;
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
use Doctrine\DBAL\DBALException;
use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry;
class d3ActionWizard extends AdminDetailsController
@ -43,7 +40,7 @@ class d3ActionWizard extends AdminDetailsController
$this->configuration = oxNew(Configuration::class);
}
public function getGroups()
public function getGroups(): array
{
return $this->configuration->getActionGroups();
}
@ -55,9 +52,6 @@ class d3ActionWizard extends AdminDetailsController
/**
* @throws DatabaseConnectionException
* @throws StandardException
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
*/
public function runTask()
{
@ -93,7 +87,7 @@ class d3ActionWizard extends AdminDetailsController
/**
* @return Config
*/
public function d3GetConfig()
public function d3GetConfig(): Config
{
return Registry::getConfig();
}

View File

@ -45,7 +45,7 @@ class d3ExportWizard extends AdminDetailsController
$this->configuration = oxNew(Configuration::class);
}
public function getGroups()
public function getGroups(): array
{
return $this->configuration->getExportGroups();
}
@ -101,7 +101,7 @@ class d3ExportWizard extends AdminDetailsController
/**
* @return Config
*/
public function d3GetConfig()
public function d3GetConfig(): Config
{
return Registry::getConfig();
}

View File

@ -95,7 +95,7 @@ abstract class ActionBase implements QueryBase
* @return DatabaseInterface|null
* @throws DatabaseConnectionException
*/
public function d3GetDb()
public function d3GetDb(): ?DatabaseInterface
{
return DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC );
}

View File

@ -15,11 +15,7 @@ declare(strict_types=1);
namespace D3\DataWizard\Application\Model;
use D3\DataWizard\Application\Model\Actions\FixArtextendsItems;
use D3\DataWizard\Application\Model\Exceptions\DataWizardException;
use D3\DataWizard\Application\Model\Exports\InactiveCategories;
use D3\DataWizard\Application\Model\Exports\KeyFigures;
use OxidEsales\Eshop\Core\Registry;
class Configuration
{

View File

@ -25,6 +25,7 @@ use Doctrine\DBAL\DBALException;
use FormManager\Inputs\Checkbox;
use FormManager\Inputs\Input;
use FormManager\Inputs\Radio;
use OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface;
use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
@ -94,7 +95,7 @@ abstract class ExportBase implements QueryBase
/**
* @return RendererBridge
*/
public function getRendererBridge()
public function getRendererBridge(): RendererBridge
{
return oxNew(RendererBridge::class);
}
@ -244,10 +245,10 @@ abstract class ExportBase implements QueryBase
}
/**
* @return \OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface|null
* @return DatabaseInterface|null
* @throws DatabaseConnectionException
*/
protected function d3GetDb(): ?\OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface
protected function d3GetDb(): ?DatabaseInterface
{
return DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC);
}

View File

@ -37,7 +37,7 @@ class Csv implements RendererInterface
$csv = $this->getCsv();
$csv->insertOne( $fieldNames );
$csv->insertAll( $rows );
return method_exists($csv, 'getContent') ? $csv->getContent() : (string) $csv;
return (string) $csv;
} catch (Exception $e) {
/** @var RenderException $newException */
$newException = oxNew(RenderException::class, $e->getMessage(), $e->getCode(), $e );
@ -86,7 +86,7 @@ class Csv implements RendererInterface
/**
* @return Config
*/
public function d3GetConfig()
public function d3GetConfig(): Config
{
return Registry::getConfig();
}

View File

@ -35,7 +35,7 @@ class Pretty implements RendererInterface
* @param $rows
* @return ArrayToTextTable
*/
public function getArrayToTextTableInstance($rows)
public function getArrayToTextTableInstance($rows): ArrayToTextTable
{
return oxNew(ArrayToTextTable::class, $rows);
}

View File

@ -35,7 +35,7 @@ class RendererBridge
];
}
public function getTranslatedRendererIdList()
public function getTranslatedRendererIdList(): array
{
$rendererList = $this->getRendererList();
array_walk($rendererList, [$this, 'translateRendererId']);

View File

@ -11,5 +11,5 @@
* @link https://www.oxidmodule.com
*/
define('D3DATAWIZARD_REQUIRE_MODCFG', true);
const D3DATAWIZARD_REQUIRE_MODCFG = true;

View File

@ -13,6 +13,6 @@ class d3TestExport extends ExportBase
public function getQuery(): array
{
return "SELECT 1";
return ["SELECT 1"];
}
}

View File

@ -94,7 +94,7 @@ class ActionBaseTest extends d3ModCfgUnitTestCase
);
}
public function canGetHasFormElementsDataProvider()
public function canGetHasFormElementsDataProvider(): array
{
return [
'hasFormElements' => [['abc', 'def'], true],

View File

@ -21,6 +21,7 @@ use D3\DataWizard\tests\tools\d3TestAction;
use D3\DataWizard\tests\tools\d3TestExport;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class ConfigurationTest extends d3ModCfgUnitTestCase
{
@ -44,7 +45,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Configuration::__construct
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canConstruct()
{
@ -65,7 +66,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Configuration::configure()
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canConfigure()
{
@ -80,7 +81,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Configuration::registerAction
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canRegisterAction()
{
@ -113,7 +114,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Configuration::registerExport
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canRegisterExport()
{
@ -166,7 +167,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getGroupedActions()
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetGroupedActions()
{
@ -190,7 +191,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getGroupedExports()
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetGroupedExports()
{
@ -214,7 +215,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getActionGroups()
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetActionGroups()
{
@ -238,7 +239,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getExportGroups()
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetExportGroups()
{
@ -262,7 +263,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getActionsByGroup()
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetActionsByGroup()
{
@ -287,7 +288,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getExportsByGroup()
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetExportsByGroup()
{
@ -312,7 +313,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getAllActions()
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetAllActions()
{
@ -343,7 +344,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getAllExports()
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetAllExports()
{
@ -374,7 +375,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getActionById()
* @test
* @throws \ReflectionException
* @throws ReflectionException
* @dataProvider canGetActionByIdDataProvider
*/
public function canGetActionById($id, $throwException)
@ -409,7 +410,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Configuration::getExportById()
* @test
* @throws \ReflectionException
* @throws ReflectionException
* @dataProvider canGetActionByIdDataProvider
*/
public function canGetExportById($id, $throwException)

View File

@ -17,7 +17,9 @@ namespace D3\DataWizard\tests\unit\Application\Model\Exceptions;
use D3\DataWizard\Application\Model\Exceptions\DebugException;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class DebugExceptionTest extends d3ModCfgUnitTestCase
{
@ -27,13 +29,13 @@ class DebugExceptionTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Exceptions\DebugException::__construct
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canConstruct()
{
$code = '500';
$exception = oxNew(\Exception::class);
$exception = oxNew( Exception::class);
/** @var DebugException|MockObject $modelMock */
$modelMock = $this->getMockBuilder(DebugException::class)

View File

@ -17,7 +17,9 @@ namespace D3\DataWizard\tests\unit\Application\Model\Exceptions;
use D3\DataWizard\Application\Model\Exceptions\ExportFileException;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class ExportFileExceptionTest extends d3ModCfgUnitTestCase
{
@ -27,13 +29,13 @@ class ExportFileExceptionTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Exceptions\ExportFileException::__construct
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canConstruct()
{
$code = '500';
$exception = oxNew(\Exception::class);
$exception = oxNew( Exception::class);
/** @var ExportFileException|MockObject $modelMock */
$modelMock = $this->getMockBuilder(ExportFileException::class)

View File

@ -19,8 +19,10 @@ use D3\DataWizard\Application\Model\Exceptions\InputUnvalidException;
use D3\DataWizard\Application\Model\ExportBase;
use D3\DataWizard\tests\tools\d3TestExport;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use FormManager\Inputs\Number;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class InputUnvalidExceptionTest extends d3ModCfgUnitTestCase
{
@ -30,15 +32,14 @@ class InputUnvalidExceptionTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Exceptions\InputUnvalidException::__construct
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canConstruct()
{
$code = '500';
$exception = oxNew(\Exception::class);
$exception = oxNew( Exception::class);
/** @var Number $invalidField */
$invalidField = new Number(null, [
'required' => true,
'min' => 1,

View File

@ -17,7 +17,9 @@ namespace D3\DataWizard\tests\unit\Application\Model\Exceptions;
use D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class NoSuitableRendererExceptionTest extends d3ModCfgUnitTestCase
{
@ -27,13 +29,13 @@ class NoSuitableRendererExceptionTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException::__construct
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canConstruct()
{
$code = '500';
$exception = oxNew(\Exception::class);
$exception = oxNew( Exception::class);
/** @var NoSuitableRendererException|MockObject $modelMock */
$modelMock = $this->getMockBuilder(NoSuitableRendererException::class)

View File

@ -19,7 +19,9 @@ use D3\DataWizard\Application\Model\Exceptions\TaskException;
use D3\DataWizard\Application\Model\ExportBase;
use D3\DataWizard\tests\tools\d3TestExport;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class TaskExceptionTest extends d3ModCfgUnitTestCase
{
@ -29,13 +31,13 @@ class TaskExceptionTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\Exceptions\TaskException::__construct
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canConstruct()
{
$code = '500';
$exception = oxNew(\Exception::class);
$exception = oxNew( Exception::class);
/** @var ExportBase|MockObject $taskMock */
$taskMock = $this->getMockBuilder(d3TestExport::class)

View File

@ -99,7 +99,7 @@ class ExportBaseTest extends d3ModCfgUnitTestCase
);
}
public function canGetHasFormElementsDataProvider()
public function canGetHasFormElementsDataProvider(): array
{
return [
'hasFormElements' => [['abc', 'def'], true],

View File

@ -22,6 +22,7 @@ use League\Csv\Writer;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Registry;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class CsvTest extends ExportRendererTest
{
@ -38,7 +39,7 @@ class CsvTest extends ExportRendererTest
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getContent
* @test
* @throws \ReflectionException
* @throws ReflectionException
* @dataProvider canGetContentDataProvider
*/
public function canGetContent($blThrowException)
@ -48,25 +49,21 @@ class CsvTest extends ExportRendererTest
$valueList = ['value1', 'value2'];
/** @var Writer|MockObject $csvMock */
$csvMockBuilder = $this->getMockBuilder(Writer::class);
$csvMockBuilder = $this->getMockBuilder( Writer::class);
$csvMockBuilder->disableOriginalConstructor();
$onlyMethods = ['insertOne', 'insertAll'];
if (method_exists($csvMockBuilder->getMock(), 'getContent')) {
$onlyMethods[] = 'getContent';
} else {
$csvMockBuilder->addMethods(['getContent']);
}
$onlyMethods = ['__toString', 'insertOne', 'insertAll'];
$csvMockBuilder->onlyMethods($onlyMethods);
$csvMock = $csvMockBuilder->getMock();
$csvMock->method('insertOne')->willReturn(1);
$csvMock->method('insertAll')->willReturn(1);
if ($blThrowException) {
$csvMock->expects($this->atLeastOnce())->method('getContent')->willThrowException(oxNew(Exception::class));
$csvMock->expects($this->atLeastOnce())->method('__toString')->willThrowException(oxNew(Exception::class));
$this->expectException(RenderException::class);
} else {
$csvMock->expects($this->atLeastOnce())->method('getContent')->willReturn($expected);
$csvMock->expects($this->atLeastOnce())->method('__toString')->willReturn($expected);
}
$csvMock->expects($this->atLeastOnce())->method('insertOne')->with($fieldList)->willReturn(1);
$csvMock->expects($this->atLeastOnce())->method('insertAll')->with($valueList)->willReturn(1);
/** @var Csv|MockObject $modelMock */
$modelMock = $this->getMockBuilder(Csv::class)
@ -99,7 +96,7 @@ class CsvTest extends ExportRendererTest
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getCsv
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetCsv()
{
@ -115,7 +112,7 @@ class CsvTest extends ExportRendererTest
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getCsv
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetCsvNoSettings()
{
@ -165,7 +162,7 @@ class CsvTest extends ExportRendererTest
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::d3GetConfig
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetConfig()
{

View File

@ -15,6 +15,7 @@ namespace D3\DataWizard\tests\unit\Application\Model\ExportRenderer;
use D3\DataWizard\Application\Model\ExportRenderer\RendererInterface;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use ReflectionException;
abstract class ExportRendererTest extends d3ModCfgUnitTestCase
{
@ -33,7 +34,7 @@ abstract class ExportRendererTest extends d3ModCfgUnitTestCase
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Json::getFileExtension
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getFileExtension
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetFileExtension()
{
@ -51,7 +52,7 @@ abstract class ExportRendererTest extends d3ModCfgUnitTestCase
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Json::getTitleTranslationId
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getTitleTranslationId
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetTitleTranslationId()
{

View File

@ -17,6 +17,7 @@ namespace D3\DataWizard\tests\unit\Application\Model\ExportRenderer;
use D3\DataWizard\Application\Model\Exceptions\RenderException;
use D3\DataWizard\Application\Model\ExportRenderer\Json;
use ReflectionException;
class JsonTest extends ExportRendererTest
{
@ -33,7 +34,7 @@ class JsonTest extends ExportRendererTest
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Json::getContent
* @test
* @throws \ReflectionException
* @throws ReflectionException
* @dataProvider canGetContentDataProvider
*/
public function canGetContent($valueList, $expectException)

View File

@ -18,6 +18,7 @@ namespace D3\DataWizard\tests\unit\Application\Model\ExportRenderer;
use D3\DataWizard\Application\Model\ExportRenderer\Pretty;
use MathieuViossat\Util\ArrayToTextTable;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class PrettyTest extends ExportRendererTest
{
@ -34,7 +35,7 @@ class PrettyTest extends ExportRendererTest
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getContent
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetContent()
{
@ -69,7 +70,7 @@ class PrettyTest extends ExportRendererTest
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getArrayToTextTableInstance
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetArrayToTextTableInstance()
{

View File

@ -23,6 +23,7 @@ use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
use D3\DataWizard\Application\Model\ExportRenderer\RendererInterface;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class RendererBridgeTest extends d3ModCfgUnitTestCase
{
@ -46,7 +47,7 @@ class RendererBridgeTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::getRendererList
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetRendererList()
{
@ -62,7 +63,7 @@ class RendererBridgeTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::getTranslatedRendererIdList
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canGetTranslatedRendererIdList()
{
@ -84,7 +85,7 @@ class RendererBridgeTest extends d3ModCfgUnitTestCase
/**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::translateRendererId
* @test
* @throws \ReflectionException
* @throws ReflectionException
*/
public function canTranslateRendererId()
{
@ -108,7 +109,7 @@ class RendererBridgeTest extends d3ModCfgUnitTestCase
* @test
* @param $format
* @param $blThrowException
* @throws \ReflectionException
* @throws ReflectionException
* @dataProvider canGetRendererDataProvider
*/
public function canGetRenderer($format, $blThrowException)