From 8f0c487844f781dfd76c006ae9fcc0b582c3f113 Mon Sep 17 00:00:00 2001 From: Nim Date: Fri, 30 Mar 2012 15:29:03 +0200 Subject: [PATCH 1/3] Add getStringProperty($name) to abstract rule in order to get at all property values, not just ints and bools. --- src/main/php/PHP/PMD/AbstractRule.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/php/PHP/PMD/AbstractRule.php b/src/main/php/PHP/PMD/AbstractRule.php index 7d8c0b31f..d1e114dff 100644 --- a/src/main/php/PHP/PMD/AbstractRule.php +++ b/src/main/php/PHP/PMD/AbstractRule.php @@ -391,6 +391,25 @@ public function getIntProperty($name) throw new OutOfBoundsException('Property $' . $name . ' does not exist.'); } + + /** + * Returns the raw string value of a configured property or throws an + * exception when no property with $name exists. + * + * @param string $name The property identifier. + * + * @return string + * @throws OutOfBoundsException When no property for $name exists. + */ + public function getStringProperty($name) + { + if (isset($this->_properties[$name])) { + return $this->_properties[$name]; + } + throw new OutOfBoundsException('Property $' . $name . ' does not exist.'); + + } + /** * This method adds a violation to all reports for this violation type and * for the given $node instance. From f12c3f52c30285a9ee071c004d2381213e5c13af Mon Sep 17 00:00:00 2001 From: Nim Date: Sat, 31 Mar 2012 10:38:26 +0200 Subject: [PATCH 2/3] Testcase for AbstractRule->getStringProperty() --- src/test/php/PHP/PMD/RuleTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/test/php/PHP/PMD/RuleTest.php b/src/test/php/PHP/PMD/RuleTest.php index 58f2de905..fe8f657d0 100644 --- a/src/test/php/PHP/PMD/RuleTest.php +++ b/src/test/php/PHP/PMD/RuleTest.php @@ -156,4 +156,29 @@ public function testGetBooleanPropertyThrowsExceptionWhenNoPropertyForNameExists $rule = $this->getMockForAbstractClass('PHP_PMD_AbstractRule'); $rule->getBooleanProperty(__FUNCTION__); } + + /** + * testStringPropertyThrowsExceptionWhenNoPropertyForNameExists + * + * @return void + * @expectedException OutOfBoundsException + */ + public function testGetStringPropertyThrowsExceptionWhenNoPropertyForNameExists() + { + $rule = $this->getMockForAbstractClass('PHP_PMD_AbstractRule'); + $rule->getStringProperty(__FUNCTION__); + } + + /** + * testGetStringPropertyReturnsStringValue + * + * @return void + */ + public function testGetStringPropertyReturnsString() + { + $rule = $this->getMockForAbstractClass('PHP_PMD_AbstractRule'); + $rule->addProperty(__FUNCTION__, 'Fourty Two'); + + $this->assertSame('Fourty Two', $rule->getStringProperty(__FUNCTION__)); + } } From 4360229b8e292c7afec13c598d1f441fade4a6d2 Mon Sep 17 00:00:00 2001 From: Nim Date: Sat, 31 Mar 2012 10:39:01 +0200 Subject: [PATCH 3/3] Prevent timezone warnings in tests on PHP setups without a default timezone set (PHP 5.1+) --- src/test/php/PHP/PMD/AbstractTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/php/PHP/PMD/AbstractTest.php b/src/test/php/PHP/PMD/AbstractTest.php index a46b720a7..825d03502 100644 --- a/src/test/php/PHP/PMD/AbstractTest.php +++ b/src/test/php/PHP/PMD/AbstractTest.php @@ -558,6 +558,9 @@ public static function init() $autoload = new PHP_Depend_Autoload(); $autoload->register(); + + // Prevent timezone warnings if no default TZ is set (PHP > 5.1.0) + date_default_timezone_set('UTC'); } /**