PHP code example of johnykvsky / quidam

1. Go to this page and download the library: Download johnykvsky/quidam library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

johnykvsky / quidam example snippets


use Quidam\Quidam;

$generator = Quidam::create();                 // or create(seed: 2026) for repeatable data

$generator->person()->name();     // 'Brenda Patterson'
$generator->internet()->email();  // '[email protected]'

$person = $generator->person();    // or keep the extension
$person->firstName();

$email = $generator->unique('users.email', fn (Quidam $g) => $g->internet()->email());
$generator->fork('users.42')->person()->name();   // stable record

$generator = Quidam::create(seed: 42);   // its own Xoshiro256** - nothing else can move it

foreach ($ids as $id) {
    $user = $generator->fork('users.' . $id);   // user 42 is always the same user
    $users[] = ['name' => $user->person()->name(), 'email' => $user->internet()->email()];
}

$generator = Quidam::create(seed: 1, clock: $frozenClock);   // the same birth dates every run

$generator->ext(TemplateInterface::class)->parse('{{ person.name }} <{{ internet.email }}>');   // formats stored as data
$generator->ext(FillerInterface::class)->make(UserDto::class);      // DTO filled by property names and types
$generator->ext(TextInterface::class)->realText(100, 200);          // realistic text from a book (Markov chain)
$generator->ext(RichTextInterface::class)->html();                  // randomHtml() - also markdown()
$generator->ext(EdgeCasesInterface::class)->string('unicode');      // strings that break code

// one strategy
$generator->unique('users.email', fn (Quidam $g) => $g->internet()->email());
$generator->optional(fn (Quidam $g) => $g->lorem()->sentence(), 30);

// mixed - first added is the outermost one
$generator->strategy()->chance(70)->unique('contacts.phone')->add(new MyStrategy())
    ->generate(fn (Quidam $g) => $g->phoneNumber()->e164PhoneNumber());

// generator-wide, DummyGenerator style - $name is the key
$generator->withStrategy(UniqueStrategy::class)->generate('users.email', fn (Quidam $g) => ...);

use Quidam\LanguagePack\pl_PL\PlPlGenerator;

$pl = PlPlGenerator::create(seed: 2026);

$pl->person()->name();                     // 'Kazimiera Wójtowicz' - surnames follow gender
$pl->address()->address();                 // 'os. Toruńska 22, 71-220 Bezrzecze' - real place, postcode, county
$pl->phoneNumber()->e164PhoneNumber();     // '+48788228453'
$pl->payment()->iban(formatted: true);     // 'PL43 2728 8223 8453 1540 8939 7198' - real bank code
$pl->nationalId()->pesel();                // '51071882277'
$pl->profile()->citizen();                 // one person: PESEL matches birth date and gender, address of one place
shell
make check              # fix-style, check-style, phpstan (max level, src + test), phpunit
composer seed-snapshot  # after an intended change of seeded output
php bench/run.php       # benchmark against DummyGenerator and FakerPHP (sibling directories)
php bench/data-quality.php  # share of wrong / unsafe values, FakerPHP vs Quidam (docs/data-quality.md)