HomePhabricator

Use SMW\TableFormatter for the table query printer (SMWTableResultPrinter)

Authored by mwjames.

Description

Use SMW\TableFormatter for the table query printer (SMWTableResultPrinter)

SMWTableResultPrinter has a CRAP of 478 which puts this printer into
a category of a potential hazardous printer that can be broken easily.

Doing data gathering and doing formatting are fundamentally two
different things and should not be mixed as it increases complexity.
Having attributes being dependent on data they present is necessary
but HTML related formatting has nothing to do with the data itself
therefore it is the wrong place and a formatting class should be used
instead.

It doesn't solve the inherent problem of the SMWTableResultPrinter class
but it allows for seperate unit testing and coverage.

SMW\TableFormatter
Code overage: 100%
CRAP: 25

SMWTableResultPrinter
Code coverage: 33.33%
CRAP: before 478 after 352

@code
$tableFormatter = new SMW\TableFormatter();

// Setup the header
$tableFormatter->addTableHeader( 'Foo' )
$tableFormatter->addTableHeader( 'Bar' )

// Add row
$tableFormatter->addTableCell( 'Lula' )
$tableFormatter->addTableCell( 'Lala' )
$tableFormatter->addTableRow()
...

Get table
$tableFormatter->getTable()
Standard table
$tableFormatter->transpose()->getTable() Transposed table
$tableFormatter->transpose( false )->getTable()
Standard table
@endcode

Note

SMW\TableFormatter is used for the Factbox as well.

[1] http://www.semantic-mediawiki.org/wiki/CRAP

Change-Id: I11c0057669e0a18c7b573ef64b21414fcb202b01

Details