Skip to content

Commit

Permalink
Merge pull request #11 from Nimlhug/master
Browse files Browse the repository at this point in the history
Add getStringProperty($name) to AbstractRule.php
  • Loading branch information
manuelpichler committed Sep 7, 2012
2 parents 4c543a6 + 4360229 commit b7d659f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/php/PHP/PMD/AbstractRule.php
Expand Up @@ -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 <b>$name</b> exists.
*
* @param string $name The property identifier.
*
* @return string
* @throws OutOfBoundsException When no property for <b>$name</b> 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 <b>$node</b> instance.
Expand Down
3 changes: 3 additions & 0 deletions src/test/php/PHP/PMD/AbstractTest.php
Expand Up @@ -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');
}

/**
Expand Down
25 changes: 25 additions & 0 deletions src/test/php/PHP/PMD/RuleTest.php
Expand Up @@ -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__));
}
}

0 comments on commit b7d659f

Please sign in to comment.