Use consts to select the CodeGen handler format
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
e6b23cf9ef
commit
e29f892d62
@ -32,12 +32,9 @@ class ExportCodegen extends ExportPlugin
|
||||
* @var array
|
||||
*/
|
||||
private $_cgFormats;
|
||||
/**
|
||||
* CodeGen Handlers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_cgHandlers;
|
||||
|
||||
private const HANDLER_NHIBERNATE_CS = 0;
|
||||
private const HANDLER_NHIBERNATE_XML = 1;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@ -54,19 +51,10 @@ class ExportCodegen extends ExportPlugin
|
||||
*/
|
||||
protected function initSpecificVariables()
|
||||
{
|
||||
$this->_setCgFormats(
|
||||
[
|
||||
'NHibernate C# DO',
|
||||
'NHibernate XML',
|
||||
]
|
||||
);
|
||||
|
||||
$this->_setCgHandlers(
|
||||
[
|
||||
'_handleNHibernateCSBody',
|
||||
'_handleNHibernateXMLBody',
|
||||
]
|
||||
);
|
||||
$this->_setCgFormats([
|
||||
self::HANDLER_NHIBERNATE_CS => 'NHibernate C# DO',
|
||||
self::HANDLER_NHIBERNATE_XML => 'NHibernate XML',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -187,16 +175,14 @@ class ExportCodegen extends ExportPlugin
|
||||
$sql_query,
|
||||
array $aliases = []
|
||||
) {
|
||||
$CG_FORMATS = $this->_getCgFormats();
|
||||
$CG_HANDLERS = $this->_getCgHandlers();
|
||||
$format = (int) $GLOBALS['codegen_format'];
|
||||
|
||||
$format = $GLOBALS['codegen_format'];
|
||||
if (isset($CG_FORMATS[$format])) {
|
||||
$method = $CG_HANDLERS[$format];
|
||||
if ($format === self::HANDLER_NHIBERNATE_CS) {
|
||||
return $this->export->outputHandler($this->handleNHibernateCSBody($db, $table, $crlf, $aliases));
|
||||
}
|
||||
|
||||
return $this->export->outputHandler(
|
||||
$this->$method($db, $table, $crlf, $aliases)
|
||||
);
|
||||
if ($format === self::HANDLER_NHIBERNATE_XML) {
|
||||
return $this->export->outputHandler($this->handleNHibernateXMLBody($db, $table, $crlf, $aliases));
|
||||
}
|
||||
|
||||
return $this->export->outputHandler(sprintf('%s is not supported.', $format));
|
||||
@ -235,7 +221,7 @@ class ExportCodegen extends ExportPlugin
|
||||
*
|
||||
* @return string containing C# code lines, separated by "\n"
|
||||
*/
|
||||
private function _handleNHibernateCSBody($db, $table, $crlf, array $aliases = [])
|
||||
private function handleNHibernateCSBody($db, $table, $crlf, array $aliases = [])
|
||||
{
|
||||
$db_alias = $db;
|
||||
$table_alias = $table;
|
||||
@ -338,7 +324,7 @@ class ExportCodegen extends ExportPlugin
|
||||
*
|
||||
* @return string containing XML code lines, separated by "\n"
|
||||
*/
|
||||
private function _handleNHibernateXMLBody(
|
||||
private function handleNHibernateXMLBody(
|
||||
$db,
|
||||
$table,
|
||||
$crlf,
|
||||
@ -397,8 +383,6 @@ class ExportCodegen extends ExportPlugin
|
||||
return implode($crlf, $lines);
|
||||
}
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
|
||||
|
||||
/**
|
||||
* Getter for CodeGen formats
|
||||
*
|
||||
@ -420,26 +404,4 @@ class ExportCodegen extends ExportPlugin
|
||||
{
|
||||
$this->_cgFormats = $CG_FORMATS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for CodeGen handlers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _getCgHandlers()
|
||||
{
|
||||
return $this->_cgHandlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for CodeGen handlers
|
||||
*
|
||||
* @param array $CG_HANDLERS contains CodeGen handler methods
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _setCgHandlers(array $CG_HANDLERS)
|
||||
{
|
||||
$this->_cgHandlers = $CG_HANDLERS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,8 +23,4 @@
|
||||
<exclude name="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
|
||||
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration"/>
|
||||
</rule>
|
||||
|
||||
<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedMethod">
|
||||
<exclude-pattern>libraries/classes/Plugins/Export/ExportCodegen.php</exclude-pattern>
|
||||
</rule>
|
||||
</ruleset>
|
||||
|
||||
@ -64,9 +64,6 @@ class ExportCodegenTest extends AbstractTestCase
|
||||
$attrCgFormats = new ReflectionProperty(ExportCodegen::class, '_cgFormats');
|
||||
$attrCgFormats->setAccessible(true);
|
||||
|
||||
$attrCgHandlers = new ReflectionProperty(ExportCodegen::class, '_cgHandlers');
|
||||
$attrCgHandlers->setAccessible(true);
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
'NHibernate C# DO',
|
||||
@ -74,14 +71,6 @@ class ExportCodegenTest extends AbstractTestCase
|
||||
],
|
||||
$attrCgFormats->getValue($this->object)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
'_handleNHibernateCSBody',
|
||||
'_handleNHibernateXMLBody',
|
||||
],
|
||||
$attrCgHandlers->getValue($this->object)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -325,7 +314,7 @@ class ExportCodegenTest extends AbstractTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PhpMyAdmin\Plugins\Export\ExportCodegen::_handleNHibernateCSBody
|
||||
* Test for PhpMyAdmin\Plugins\Export\ExportCodegen::handleNHibernateCSBody
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -351,7 +340,7 @@ class ExportCodegenTest extends AbstractTestCase
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$method = new ReflectionMethod(ExportCodegen::class, '_handleNHibernateCSBody');
|
||||
$method = new ReflectionMethod(ExportCodegen::class, 'handleNHibernateCSBody');
|
||||
$method->setAccessible(true);
|
||||
$result = $method->invoke($this->object, 'db', 'table', "\n");
|
||||
|
||||
@ -390,7 +379,7 @@ class ExportCodegenTest extends AbstractTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PhpMyAdmin\Plugins\Export\ExportCodegen::_handleNHibernateXMLBody
|
||||
* Test for PhpMyAdmin\Plugins\Export\ExportCodegen::handleNHibernateXMLBody
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@ -421,7 +410,7 @@ class ExportCodegenTest extends AbstractTestCase
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
$method = new ReflectionMethod(ExportCodegen::class, '_handleNHibernateXMLBody');
|
||||
$method = new ReflectionMethod(ExportCodegen::class, 'handleNHibernateXMLBody');
|
||||
$method->setAccessible(true);
|
||||
$result = $method->invoke($this->object, 'db', 'table', "\n");
|
||||
|
||||
@ -471,32 +460,4 @@ class ExportCodegenTest extends AbstractTestCase
|
||||
$getter->invoke($this->object)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for
|
||||
* - PhpMyAdmin\Plugins\Export\ExportCodegen::_getCgHandlers
|
||||
* - PhpMyAdmin\Plugins\Export\ExportCodegen::_setCgHandlers
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetGetCgHandlers()
|
||||
{
|
||||
$reflection = new ReflectionClass(ExportCodegen::class);
|
||||
|
||||
$getter = $reflection->getMethod('_getCgHandlers');
|
||||
$setter = $reflection->getMethod('_setCgHandlers');
|
||||
|
||||
$getter->setAccessible(true);
|
||||
$setter->setAccessible(true);
|
||||
|
||||
$setter->invoke($this->object, [1, 2]);
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
1,
|
||||
2,
|
||||
],
|
||||
$getter->invoke($this->object)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user