Source of file MinWordsRule.php
Size: 1,750 Bytes - Last Modified: 2021-12-23T10:37:30+00:00
/var/www/docs.ssmods.com/process/src/src/Rules/MinWordsRule.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 | <?php /** * This file is part of SilverWare. * * PHP version >=5.6.0 * * For full copyright and license information, please view the * LICENSE.md file that was distributed with this source code. * * @package SilverWare\Validator\Rules * @author Colin Tucker <colin@praxis.net.au> * @copyright 2017 Praxis Interactive * @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause * @link https://github.com/praxisnetau/silverware-validator */ namespace SilverWare\Validator\Rules; /** * An extension of the min rule class for a minwords rule. * * @package SilverWare\Validator\Rules * @author Colin Tucker <colin@praxis.net.au> * @copyright 2017 Praxis Interactive * @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause * @link https://github.com/praxisnetau/silverware-validator */ class MinWordsRule extends MinRule { /** * Defines the default type for the rule. * * @var string * @config */ private static $default_type = 'minwords'; /** * Answers the test result of the validator rule on the given value. * * @param mixed $value * * @return boolean */ public function test($value) { if (!$this->isValid() || !$value) { return true; } $count = str_word_count($value); return ($count >= $this->min); } /** * Answers the default message for the rule. * * @return string */ public function getDefaultMessage() { return sprintf( _t( __CLASS__ . '.DEFAULTMESSAGE', 'This value should contain a minimum of %d words.' ), $this->min ); } } |