sixty-nine/php-cloud-lib

View on GitHub
src/SixtyNine/Cloud/Filters/RemoveCharacters.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace SixtyNine\Cloud\Filters;

/**
 * Remove unwanted characters from words.
 */
class RemoveCharacters extends AbstractFilter implements FilterInterface
{
    protected $unwantedCharacters;

    /**
     * @param array $unwantedCharacters Array of characters to be removed.
     */
    public function __construct($unwantedCharacters = null)
    {
        if (!$unwantedCharacters) {
            $unwantedCharacters = array(
                ':', '?', '!', '\'', '"', '(', ')', '[', ']',
            );
        }
        $this->unwantedCharacters = $unwantedCharacters;
    }

    /** {@inheritdoc} */
    public function filterWord($word)
    {
        foreach($this->unwantedCharacters as $p) {
            $word = str_replace($p, '', $word);
        }

        return $word;
    }
}