Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 15
CharacterSalad
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 15
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 4
 next
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 11
<?php
namespace RemexHtml\FuzzTest;
/**
 * A generator for a random strings, biased towards characters that have
 * special meaning in HTML.
 */
class CharacterSalad {
    private $minLength;
    private $maxLength;
    private $bigDictionary;
    private static $smallDictionary = [
        '<',
        '>',
        '&',
        ';',
        '/',
        '=',
        '"',
        '\'',
        '=',
        'a',
        'b',
        'c',
    ];
    public function __construct( $minLength, $maxLength ) {
        $this->minLength = $minLength;
        $this->maxLength = $maxLength;
        $this->bigDictionary = Utils::getBigDictionary();
    }
    public function next() {
        $length = mt_rand( $this->minLength, $this->maxLength );
        $s = '';
        for ( $i = 0; $i < $length; $i++ ) {
            if ( Utils::coinToss( 0.5 ) ) {
                $s .= Utils::pickRandom( $this->bigDictionary );
            } else {
                $s .= Utils::pickRandom( self::$smallDictionary );
            }
        }
        return $s;
    }
}