for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of the theroadbunch/bouncer package.
*
* (c) Dan McAdams <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace RoadBunch\String;
* Class StringCollection
* @author Dan McAdams
* @package RoadBunch\String
class StringCollection implements StringCollectionInterface
{
protected $elements = [];
* StringCollection constructor.
* @param string[] $elements
public function __construct(array $elements = [])
foreach ($elements as $element) {
if (!is_string($element)) {
throw new \InvalidArgumentException('All elements must be strings');
}
$this->add($element);
* Add an element, duplicates will be ignored
* @param string $element
public function add(string $element): void
if (!in_array($element, $this->elements)) {
$this->elements[] = $element;
* Check to see if an element exists in the lists
* @return bool
public function has(string $element): bool
return in_array($element, $this->elements);
* Remove an element from the list
public function remove(string $element): void
$index = array_search($element, $this->elements);
if ($index !== false) {
unset($this->elements[$index]);