Skip to content

Commit

Permalink
ADD: Some extra documentation
Browse files Browse the repository at this point in the history
FIX: Please the MESS detector
  • Loading branch information
rvelhote committed Jun 19, 2016
1 parent a2defef commit cd2d0d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Rule/RuleCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function getRule(string $winner, string $loser)
* @return array An array of strings with all the weapons in the collection.
*/
public function getWeapons() : array {
return array_unique(array_values(array_map(function(Rule $r) { return $r->getWinner(); }, $this->rules)));
return array_unique(array_values(array_map(function(Rule $rule) { return $rule->getWinner(); }, $this->rules)));
}

/**
Expand Down
23 changes: 14 additions & 9 deletions src/Validation/ValidationResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,47 +30,52 @@
class ValidationResult
{
/**
* The list of messages that will be available after the validation if ran.
* @var array
*/
private $messages = [];

/**
* @param ValidationMessage $message
* Adds a new validation message to the list
* @param ValidationMessage $message A validation message to add to the list
*/
public function addMessage(ValidationMessage $message) {
$this->messages[] = $message;
}

/**
* @param array $messages
* Adds multiples messages to the list of messages
* @param array $messages The set of messages to add to the list
* @see ValidationMessage
*/
public function addMessages(array $messages)
{
$this->messages = array_merge($this->messages, $messages);
}

/**
* @return array
* Obtain the list of messages currently in this object
* @return array A list of messages
*/
public function getMessages() : array
{
return $this->messages;
}

/**
*
* @return bool
* Checks if there are not FAIL messages in this list of messages.
* @return bool true|false depending if there are/aren't messages with ValidationMessage::FAIL status.
* @todo Why am I using array_reduce? Looks cool maybe...
*/
public function isValid() : bool
{
$fn = function(int $carry, ValidationMessage $m) {
if($m->getType() === ValidationMessage::FAIL) {
$function = function(int $carry, ValidationMessage $message) {
if($message->getType() === ValidationMessage::FAIL) {
return $carry + 1;
}

return $carry;
};

return array_reduce($this->messages, $fn, 0) === 0;
return array_reduce($this->messages, $function, 0) === 0;
}
}

0 comments on commit cd2d0d3

Please sign in to comment.