Skip to content

jaysn/spongemock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spongemock

License php 7.1+

A PHP implementation of nkrim/spongemock to mOCk SoMe TexT lIKe SpONGebOb wOuLd in PHP

Installation

Installation using Composer

composer require jaysn/spongemock

Usage

Basic Usage

Using instances of the Mocker is recommended for processing multiple strings with the same settings

use Jaysn\Spongemock\Mocker;

$mocker = new Mocker();

// $mockedText would be sth like 'MoCK sOMe tExt LIkE sPoNgEbOb WOuLd'
$mockedText = $mocker->process('mock some text like spongebob would');

Setting the diversity bias or custom seed for RNG

The Constructor of Mocker accepts Parameters $diversityBias and $randomSeed.

diversityBias is used for the distribution of case-swaps. Using a higher bias causes more swaps between upper and lowercase, using a lower value reduces them accordingly.

randomSeed is a custom seed for the Mersenne Twister Random Number Generator used for randomly swapping cases based on diversityBias. Settings this value allows deterministic creation of strings, as mt_srand() is used to pre-seed the RNG with this value for each call of Mocker::process(), thus returning the same string if given the same seed.

// less random swaps
$mocker = new Mocker(0.2);
$mocked = $mocker->process('mock some text like spongebob would');

// More random swaps (balanced distribution)
$mocker = new Mocker(0.8);
$mocked = $mocker->process('mock some text like spongebob would');

// default swapping but custom seed (for reproducable results)
$mocker = new Mocker(0.5, 42);
$mocked = $mocker->process('mock some text like spongebob would');

Static Usage

⚠ This is not recommended if processing multiple strings as every call creates another instance of the Mocker Class

use Jaysn\Spongemock\Mocker;

// $mockedText would be sth like 'MoCK sOMe tExt LIkE sPoNgEbOb WOuLd'
$mockedText = Mocker::mock('mock some text like spongebob would');

Setting the diversity bias or custom seed for RNG

// less random swaps
$mocked = Mocker::mock('mock some text like spongebob would', 0.2);


// More random swaps (balanced distribution)
$mocked = Mocker::mock('mock some text like spongebob would', 0.8);

// default swapping but custom seed (for reproducable results)
$mocked = Mocker::mock('mock some text like spongebob would', 0.5, 42);

Now go ahead and mOCk SoMe TexT lIKe SpONGebOb wOuLd

About

PHP Helper to mock text like spongebob would

Topics

Resources

License

Stars

Watchers

Forks

Languages