Skip to content

Commit

Permalink
Refactored #39: Apply Symphony2 coding standards
Browse files Browse the repository at this point in the history
 - Applied standards.
  • Loading branch information
andkirby committed Dec 2, 2015
1 parent 2c05c8f commit ee35820
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions LibHooks/lib/PreCommit/Validator/CommitMsg.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CommitMsg extends AbstractValidator
*
* @var string
*/
protected $_type;
protected $type;

/**
* Set type
Expand All @@ -60,11 +60,11 @@ public function __construct(array $options)
{
parent::__construct($options);
if (isset($options['type'])) {
$this->_type = $options['type'];
$this->type = $options['type'];
} else {
$this->_type = $this->_getConfig()->getNode('hooks/commit-msg/message/type');
$this->type = $this->getConfig()->getNode('hooks/commit-msg/message/type');
}
if (!$this->_type) {
if (!$this->type) {
throw new Exception('Type is not set.');
}
}
Expand All @@ -78,7 +78,7 @@ public function __construct(array $options)
*/
public function validate($message, $file)
{
if (!$this->_matchMessage($message)) {
if (!$this->matchMessage($message)) {
$this->_addError('Commit Message', self::CODE_BAD_COMMIT_MESSAGE, $message->head);
}

Expand All @@ -92,11 +92,11 @@ public function validate($message, $file)
* @return bool
* @throws \PreCommit\Exception
*/
protected function _matchMessage($message)
protected function matchMessage($message)
{
foreach ($this->_getExpressions() as $name => $expression) {
foreach ($this->getExpressions() as $name => $expression) {
if (is_array($expression)) {
if ($this->_getInterpreterResult($message, $expression)) {
if ($this->getInterpreterResult($message, $expression)) {
return true;
}
} elseif (preg_match($expression, $message->head)) {
Expand All @@ -116,11 +116,11 @@ protected function _matchMessage($message)
* @return bool
* @throws \PreCommit\Exception
*/
protected function _getInterpreterResult($message, array $config)
protected function getInterpreterResult($message, array $config)
{
$result = null;
if (!$message->verb) {
$result = $this->_getInterpreter($config)
$result = $this->getInterpreter($config)
->interpret(array('message' => $message));

/**
Expand Down Expand Up @@ -153,7 +153,7 @@ protected function _getInterpreterResult($message, array $config)
* At least issue key should be set after interpreting
*/
if ($result) {
foreach ($this->_getRequiredKeys() as $name => $enabled) {
foreach ($this->getRequiredKeys() as $name => $enabled) {
if (!$enabled) {
continue;
}
Expand All @@ -170,7 +170,7 @@ protected function _getInterpreterResult($message, array $config)
*/
if ($message->issue) {
//find verb key
$key = array_search($message->verb, $this->_getVerbs());
$key = array_search($message->verb, $this->getVerbs());
if (false === $key) {
$this->_addError('Commit Message', self::CODE_VERB_NOT_FOUND, $message->verb);

Expand All @@ -189,7 +189,7 @@ protected function _getInterpreterResult($message, array $config)
return false;
}
//it's cannot be processed if issue type is not valid
$allowed = $this->_getAllowedVerbs($message->issue->getType());
$allowed = $this->getAllowedVerbs($message->issue->getType());
if (!isset($allowed[$key]) || !$allowed[$key]) {
$this->_addError('Commit Message', self::CODE_VERB_INCORRECT, $message->verb);

Expand All @@ -208,17 +208,17 @@ protected function _getInterpreterResult($message, array $config)
* @return array
* @throws \PreCommit\Exception
*/
protected function _getAllowedVerbs($type)
protected function getAllowedVerbs($type)
{
if (!$type) {
throw new Exception('Empty issue type.');
}

return (array) $this->_getConfig()->getNodeArray(
return (array) $this->getConfig()->getNodeArray(
'validators/IssueType/issue/verb/allowed/'
.$this->_type.'/'.$type
.$this->type.'/'.$type
)
?: (array) $this->_getConfig()->getNodeArray(
?: (array) $this->getConfig()->getNodeArray(
'validators/IssueType/issue/verb/allowed/default/'
.$type
);
Expand All @@ -229,30 +229,30 @@ protected function _getAllowedVerbs($type)
*
* @return array
*/
protected function _getVerbs()
protected function getVerbs()
{
return (array) $this->_getConfig()->getNodeArray('hooks/commit-msg/message/verb/list/'.$this->_type)
?: (array) $this->_getConfig()->getNodeArray('hooks/commit-msg/message/verb/list/default');
return (array) $this->getConfig()->getNodeArray('hooks/commit-msg/message/verb/list/'.$this->type)
?: (array) $this->getConfig()->getNodeArray('hooks/commit-msg/message/verb/list/default');
}

/**
* Get regular expressions to match
*
* @return array|null
*/
protected function _getExpressions()
protected function getExpressions()
{
return $this->_getConfig()->getNodeArray('validators/CommitMessage/match');
return $this->getConfig()->getNodeArray('validators/CommitMessage/match');
}

/**
* Get required keys
*
* @return array|null
*/
protected function _getRequiredKeys()
protected function getRequiredKeys()
{
return $this->_getConfig()->getNodeArray('validators/CommitMessage/match/full/required');
return $this->getConfig()->getNodeArray('validators/CommitMessage/match/full/required');
}

/**
Expand All @@ -262,16 +262,17 @@ protected function _getRequiredKeys()
* @return \PreCommit\Interpreter\InterpreterInterface
* @throws Exception
*/
protected function _getInterpreter(array $config)
protected function getInterpreter(array $config)
{
if (empty($config['interpreter']['class'])) {
throw new Exception('Interpreter class is not set.');
}
$class = $config['interpreter']['class'];
/** @var InterpreterInterface $interpreter */
if (empty($config['interpreter']['options'])) {
return new $config['interpreter']['class'];
return new $class();
} else {
return new $config['interpreter']['class'](
return new $class(
$config['interpreter']['options']
);
}
Expand All @@ -282,7 +283,7 @@ protected function _getInterpreter(array $config)
*
* @return Config
*/
protected function _getConfig()
protected function getConfig()
{
return Config::getInstance();
}
Expand Down

0 comments on commit ee35820

Please sign in to comment.