Jeroen De Dauw has uploaded a new change for review. https://gerrit.wikimedia.org/r/85527
Change subject: Update DataType definition to match what we currently want it to be [DNM] ...................................................................... Update DataType definition to match what we currently want it to be [DNM] Includes some minor cleanup and deprecation of bad code Change-Id: Ifad7cafdf2151e1948e51ed5555eecd45197d095 --- M src/DataTypes/DataType.php M src/DataTypes/DataTypeFactory.php M tests/Modules/DataTypesModuleTest.php M tests/Phpunit/DataTypeFactoryTest.php M tests/Phpunit/DataTypeTest.php 5 files changed, 10 insertions(+), 81 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataTypes refs/changes/27/85527/1 diff --git a/src/DataTypes/DataType.php b/src/DataTypes/DataType.php index e61d646..777c831 100644 --- a/src/DataTypes/DataType.php +++ b/src/DataTypes/DataType.php @@ -3,17 +3,10 @@ namespace DataTypes; use InvalidArgumentException; -use ValueFormatters\ValueFormatter; -use ValueParsers\ValueParser; use ValueValidators\ValueValidator; /** - * Interface for data types. - * * @since 0.1 - * - * @file - * @ingroup DataTypes * * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > @@ -39,15 +32,6 @@ protected $dataValueType; /** - * The ValueFormatter used by this data type. - * - * @since 0.1 - * - * @var ValueFormatter[] - */ - protected $formatters; - - /** * The ValueValidator objects used by this data type. * * @since 0.1 @@ -57,20 +41,15 @@ protected $validators; /** - * Constructor. - * Typically you should not construct such objects yourself but use the TypeFactory. - * * @since 0.1 * * @param string $typeId * @param string $dataValueType - * @param ValueParser[] $parsers // TODO: remove - * @param ValueFormatter[] $formatters * @param ValueValidator[] $validators * * @throws InvalidArgumentException */ - public function __construct( $typeId, $dataValueType, array $parsers, array $formatters, array $validators ) { + public function __construct( $typeId, $dataValueType, array $validators ) { if ( !is_string( $typeId ) ) { throw new InvalidArgumentException( '$typeId must be a string' ); } @@ -81,7 +60,6 @@ $this->typeId = $typeId; $this->dataValueType = $dataValueType; - $this->formatters = $formatters; $this->validators = $validators; } @@ -105,19 +83,6 @@ */ public function getDataValueType() { return $this->dataValueType; - } - - /** - * Returns the ValueFormatter used by this data type. - * - * TODO: finish design and decide on the exact role of this and if we do not need multiple - * - * @since 0.1 - * - * @return ValueFormatter[] - */ - public function getFormatters() { - return $this->formatters; } /** diff --git a/src/DataTypes/DataTypeFactory.php b/src/DataTypes/DataTypeFactory.php index ed3c204..ea1a46d 100644 --- a/src/DataTypes/DataTypeFactory.php +++ b/src/DataTypes/DataTypeFactory.php @@ -7,12 +7,11 @@ use RuntimeException; /** - * Factory for creating data types. + * @deprecated since 0.1 * - * @since 0.1 - * - * @file - * @ingroup DataTypes + * This class acts both as a DataType registry and a DataType deserializer, + * and it is doing a bad job at both tasks. Thus create a proper registry or + * deserializer when one is needed. * * @licence GNU GPL v2+ * @author Jeroen De Dauw < [email protected] > @@ -81,7 +80,7 @@ * @param string $typeId * @param callable $builder A builder that takes $typeId and returns a DataType object * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function registerBuilder( $typeId, $builder ) { if ( !is_callable( $builder ) ) { @@ -104,7 +103,7 @@ * - if $builderSpec as an associative array, newType( $typeId, $builderSpec ) * is called for backwards compatibility * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @return DataType */ protected function buildType( $typeId, $builderSpec ) { @@ -120,7 +119,6 @@ $type = call_user_func( $builderSpec, $typeId ); } elseif ( is_array( $builderSpec ) ) { //B/C mode - //TODO: start failing on this using wfWarn or wfDeprecated $type = $this->newType( $typeId, $builderSpec ); } else { throw new InvalidArgumentException( "Bad builder spec, expected a callable." ); @@ -152,29 +150,6 @@ throw new InvalidArgumentException( 'Invalid datavalue type provided to DataTypeFactory' ); } - // TODO: use string ids for components once they have their own factories - - // TODO: Get rid of this whole method, use callable builders instead. - // Make a utility class that generates a builder based on an a spec array. - - $parser = array_key_exists( 'parser', $typeData ) ? $typeData['parser'] : 'ValueParsers\NullParser'; - - if ( is_string( $parser ) ) { - $parser = new $parser(); - } - - $formatters = array(); - - if ( array_key_exists( 'formatter', $typeData ) ) { - $formatter = $typeData['formatter']; - - if ( is_string( $formatter ) ) { - $formatter = new $formatter(); - } - - $formatters[] = $formatter; - } - if ( array_key_exists( 'validators', $typeData ) ) { $validators = is_array( $typeData['validators'] ) ? $typeData['validators'] : array( $typeData['validators'] ); } @@ -191,8 +166,6 @@ return new DataType( $typeId, $typeData['datavalue'], - array( $parser ), // TODO - $formatters, $validators ); } diff --git a/tests/Modules/DataTypesModuleTest.php b/tests/Modules/DataTypesModuleTest.php index 4f64d0c..2be0a40 100644 --- a/tests/Modules/DataTypesModuleTest.php +++ b/tests/Modules/DataTypesModuleTest.php @@ -3,10 +3,10 @@ namespace DataTypes\Tests\Modules; use DataTypes\DataTypeFactory; -use DataTypes\DataTypesModule; +use DataTypes\Modules\DataTypesModule; /** - * @covers DataTypes\DataTypesModule + * @covers DataTypes\Modules\DataTypesModule * * @file * @since 0.1 diff --git a/tests/Phpunit/DataTypeFactoryTest.php b/tests/Phpunit/DataTypeFactoryTest.php index 822b4c8..8b3026f 100644 --- a/tests/Phpunit/DataTypeFactoryTest.php +++ b/tests/Phpunit/DataTypeFactoryTest.php @@ -116,7 +116,7 @@ ), array( // #1 'new-school', - new DataType( 'new-school', 'newschool', array(), array(), array() ), + new DataType( 'new-school', 'newschool', array() ), 'newschool', 'DataValue object' ), diff --git a/tests/Phpunit/DataTypeTest.php b/tests/Phpunit/DataTypeTest.php index d947e9d..eb30aa0 100644 --- a/tests/Phpunit/DataTypeTest.php +++ b/tests/Phpunit/DataTypeTest.php @@ -59,15 +59,6 @@ * @dataProvider instanceProvider * @param DataType $type */ - public function testGetFormatter( DataType $type ) { - $this->assertInternalType( 'array', $type->getFormatters() ); - $this->assertContainsOnlyInstancesOf( 'ValueFormatters\ValueFormatter', $type->getFormatters() ); - } - - /** - * @dataProvider instanceProvider - * @param DataType $type - */ public function testGetValidators( DataType $type ) { $this->assertInternalType( 'array', $type->getValidators() ); $this->assertContainsOnlyInstancesOf( 'ValueValidators\ValueValidator', $type->getValidators() ); -- To view, visit https://gerrit.wikimedia.org/r/85527 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ifad7cafdf2151e1948e51ed5555eecd45197d095 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DataTypes Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
