Blame tests/resources/userdiff/files/file.php

Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
namespace Faker;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Proxy for other generators, to return only unique values. Works with
Packit Service 20376f
 * Faker\Generator\Base->unique()
Packit Service 20376f
 */
Packit Service 20376f
class UniqueGenerator
Packit Service 20376f
{
Packit Service 20376f
    protected $generator;
Packit Service 20376f
    protected $maxRetries;
Packit Service 20376f
	protected $moreStuff;
Packit Service 20376f
    protected $uniques = array();
Packit Service 20376f
Packit Service 20376f
    public function __construct(Generator $generator, $maxRetries)
Packit Service 20376f
    {
Packit Service 20376f
        $this->generator = $generator;
Packit Service 20376f
        $this->maxRetries = $maxRetries + 1;
Packit Service 20376f
    }
Packit Service 20376f
Packit Service 20376f
    /**
Packit Service 20376f
     * Catch and proxy all generator calls but return only unique values
Packit Service 20376f
     */
Packit Service 20376f
    public function __get($attribute)
Packit Service 20376f
    {
Packit Service 20376f
        return $this->__call($attribute, array());
Packit Service 20376f
    }
Packit Service 20376f
Packit Service 20376f
    /**
Packit Service 20376f
     * Catch and proxy all generator calls with arguments but return only unique values
Packit Service 20376f
     */
Packit Service 20376f
    public function __call($name, $arguments)
Packit Service 20376f
    {
Packit Service 20376f
        $i = 0;
Packit Service 20376f
        if (!isset($this->uniques[$name])) {
Packit Service 20376f
            $this->uniques[$name] = array();
Packit Service 20376f
        }
Packit Service 20376f
        do {
Packit Service 20376f
            $res = call_user_func_array(array($this->generator, $name), $arguments);
Packit Service 20376f
            $i++;
Packit Service 20376f
            if ($i >= $this->maxRetries) {
Packit Service 20376f
                throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries));
Packit Service 20376f
            }
Packit Service 20376f
        } while (in_array($res, $this->uniques[$name]));
Packit Service 20376f
        $this->uniques[$name][]= $res;
Packit Service 20376f
Packit Service 20376f
        return $res;
Packit Service 20376f
    }
Packit Service 20376f
}