Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jun 29, 2016
1 parent 9f50776 commit a0cd0ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
23 changes: 6 additions & 17 deletions src/Illuminate/Support/MessageBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,15 @@ protected function isUnique($key, $message)
}

/**
* Determine if messages exist for a given key.
* Determine if messages exist for a given key(s).
*
* @param string $key
* @param array|string $key
* @return bool
*/
public function has($key = null)
{
return $this->first($key) !== '';
}

/**
* Determine if messages exist for all given keys.
*
* @param array $keys
* @return bool
*/
public function hasAll($keys = [])
{
foreach ($keys as $key) {
if ($this->first($key) === '') {
foreach ((array) $key as $k) {
if ($this->first($k) === '') {
return false;
}
}
Expand All @@ -124,15 +113,15 @@ public function hasAll($keys = [])
}

/**
* Determine if messages exist for any given key.
* Determine if messages exist for any of the given keys.
*
* @param array $keys
* @return bool
*/
public function hasAny($keys = [])
{
foreach ($keys as $key) {
if ($this->first($key) !== '') {
if ($this->has($key)) {
return true;
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Support/SupportMessageBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ public function testHasAnyIndicatesExistence()
$this->assertFalse($container->hasAny(['baz']));
}

public function testHasAllIndicatesExistence()
public function testHasIndicatesExistenceOfAllKeys()
{
$container = new MessageBag;
$container->setFormat(':message');
$container->add('foo', 'bar');
$container->add('bar', 'foo');
$container->add('boom', 'baz');
$this->assertTrue($container->hasAll(['foo', 'bar', 'boom']));
$this->assertFalse($container->hasAll(['foo', 'bar', 'boom', 'baz']));
$this->assertFalse($container->hasAll(['foo', 'baz']));
$this->assertTrue($container->has(['foo', 'bar', 'boom']));
$this->assertFalse($container->has(['foo', 'bar', 'boom', 'baz']));
$this->assertFalse($container->has(['foo', 'baz']));
}

public function testAllReturnsAllMessages()
Expand Down

0 comments on commit a0cd0ae

Please sign in to comment.