Skip to content

Commit

Permalink
Merge pull request #15 from LearningLocker/issue/14
Browse files Browse the repository at this point in the history
Make validateIdentifiers a truthy experience in both Agent and Group
  • Loading branch information
ht2 authored Aug 25, 2016
2 parents 3b6a473 + 43585f0 commit 61a6aa2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ protected function identifierError($used_identifiers) {
}

protected function validateIdentifiers($used_identifiers) {
return $used_identifiers !== 1;
return $used_identifiers === 1;
}

public function validate() {
$errors = $this->validateTypedElement();

// Gets the used identifiers.
$used_identifiers = $this->countIdentifiers();
$hasOneIdent = $this->validateIdentifiers($used_identifiers);

// Checks that only one identifier is used.
if ($this->validateIdentifiers($used_identifiers)) {
if (!$hasOneIdent) {
$errors[] = new Error($this->identifierError($used_identifiers));
}

Expand Down
8 changes: 4 additions & 4 deletions src/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ protected function identifierError($used_identifiers) {
}

protected function validateIdentifiers($used_identifiers) {
$members = $this->getPropValue('member') ?: null;
$validateIdentifiers = parent::validateIdentifiers($used_identifiers);
$validateMembers = $members === null || count($members) === 0;
return $validateIdentifiers && $validateMembers;
$members = $this->getPropValue('member');
$hasOneIdent = parent::validateIdentifiers($used_identifiers);
$hasMembers = !is_null($members) && count($members) > 0;
return $hasOneIdent || (!$hasOneIdent && $hasMembers);
}
}

0 comments on commit 61a6aa2

Please sign in to comment.