Thiemo Mättig (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/391190 )
Change subject: [WIP] Rework CachedResult into an interface ...................................................................... [WIP] Rework CachedResult into an interface Change-Id: I0dda8d4ab83c7c2b1c55214782cbfaa99b1d2bb9 --- R includes/ConstraintCheck/Result/CachedScalar.php A includes/ConstraintCheck/Result/Caching.php M includes/ConstraintCheck/Result/CheckResult.php R tests/phpunit/Result/CachedScalarTest.php 4 files changed, 40 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints refs/changes/90/391190/1 diff --git a/includes/ConstraintCheck/Result/CachedResult.php b/includes/ConstraintCheck/Result/CachedScalar.php similarity index 83% rename from includes/ConstraintCheck/Result/CachedResult.php rename to includes/ConstraintCheck/Result/CachedScalar.php index ce045a7..0c6138e 100644 --- a/includes/ConstraintCheck/Result/CachedResult.php +++ b/includes/ConstraintCheck/Result/CachedScalar.php @@ -2,6 +2,8 @@ namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Result; +use InvalidArgumentException; + /** * A generic container for any kind of value which may be cached, * holding the value as well as information about whether and how it was cached. @@ -9,7 +11,7 @@ * @author Lucas Werkmeister * @license GNU GPL v2+ */ -class CachedResult { +class CachedScalar implements Caching { /** * @var mixed The wrapped value. @@ -25,6 +27,10 @@ * @param mixed $value The wrapped value. */ public function __construct( $value ) { + if ( $value !== null && !is_scalar( $value ) ) { + throw new InvalidArgumentException( '$value must be scalar' ); + } + $this->value = $value; } @@ -49,11 +55,12 @@ * The other result may also just be a bool * indicating whether the value is cached or not. * - * @param CachedResult|bool $other + * @param self|bool $other + * * @return self */ public function mergeCachedStatus( $other ) { - if ( $other instanceof CachedResult ) { + if ( $other instanceof self ) { $otherIsCached = $other->isCached; } else { $otherIsCached = $other; diff --git a/includes/ConstraintCheck/Result/Caching.php b/includes/ConstraintCheck/Result/Caching.php new file mode 100644 index 0000000..276c1b1 --- /dev/null +++ b/includes/ConstraintCheck/Result/Caching.php @@ -0,0 +1,12 @@ +<?php + +namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Result; + +interface Caching { + + /** + * @return bool + */ + public function isCached(); + +} diff --git a/includes/ConstraintCheck/Result/CheckResult.php b/includes/ConstraintCheck/Result/CheckResult.php index bf4ef31..2bf6bc5 100644 --- a/includes/ConstraintCheck/Result/CheckResult.php +++ b/includes/ConstraintCheck/Result/CheckResult.php @@ -15,7 +15,7 @@ * @author BP2014N1 * @license GNU GPL v2+ */ -class CheckResult extends CachedResult { +class CheckResult implements Caching { // Constants for statuses /** @@ -90,6 +90,11 @@ private $message; /** + * @var bool + */ + private $isCached; + + /** * @param Context $context * @param Constraint $constraint * @param array[] $parameters (string => string[]) parsed constraint parameters @@ -104,7 +109,6 @@ $status = self::STATUS_TODO, $message = '' ) { - parent::__construct( $this ); $this->context = $context; $this->constraint = $constraint; $this->parameters = $parameters; @@ -197,4 +201,11 @@ return $this->message; } + /** + * @return bool + */ + public function isCached() { + return $this->isCached; + } + } diff --git a/tests/phpunit/Result/CachedResultTest.php b/tests/phpunit/Result/CachedScalarTest.php similarity index 82% rename from tests/phpunit/Result/CachedResultTest.php rename to tests/phpunit/Result/CachedScalarTest.php index fef5d26..7050de4 100644 --- a/tests/phpunit/Result/CachedResultTest.php +++ b/tests/phpunit/Result/CachedScalarTest.php @@ -3,19 +3,19 @@ namespace WikibaseQuality\ConstraintReport\Test\Result; use PHPUnit_Framework_TestCase; -use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CachedResult; +use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CachedScalar; /** - * @covers \WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CachedResult + * @covers \WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CachedScalar * * @group WikibaseQualityConstraints * @author Lucas Werkmeister * @license GNU GPL v2+ */ -class CachedResultTest extends PHPUnit_Framework_TestCase { +class CachedScalarTest extends PHPUnit_Framework_TestCase { public function testMergeCachedStatus() { - $result = new CachedResult( null ); + $result = new CachedScalar( null ); $this->assertFalse( $result->isCached(), "should start out fresh" ); $result->mergeCachedStatus( true ); @@ -24,7 +24,7 @@ $result->mergeCachedStatus( false ); $this->assertTrue( $result->isCached(), "should still be cached" ); - $result2 = new CachedResult( null ); + $result2 = new CachedScalar( null ); $result2->mergeCachedStatus( $result ); $this->assertTrue( $result2->isCached(), "cached status should propagate" ); } -- To view, visit https://gerrit.wikimedia.org/r/391190 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0dda8d4ab83c7c2b1c55214782cbfaa99b1d2bb9 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.kr...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits