Compare commits
No commits in common. "master" and "2.0.0" have entirely different histories.
3 changed files with 49 additions and 70 deletions
|
@ -1,34 +1,34 @@
|
|||
{
|
||||
"name": "joshtronic/php-loremipsum",
|
||||
"description": "Lorem ipsum generator in PHP without dependencies",
|
||||
"version": "2.1.0",
|
||||
"type": "library",
|
||||
"keywords": [
|
||||
"lorem",
|
||||
"ipsum",
|
||||
"generator"
|
||||
],
|
||||
"homepage": "https://github.com/joshtronic/php-loremipsum",
|
||||
"license": "MIT",
|
||||
"authors": [{
|
||||
"name": "Josh Sherman",
|
||||
"email": "hello@joshtronic.com",
|
||||
"homepage": "https://joshtronic.com"
|
||||
}],
|
||||
"require": {
|
||||
"php": ">=5.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8.36 || ^9.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"joshtronic\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"joshtronic\\Tests\\": "tests/"
|
||||
}
|
||||
"name": "joshtronic/php-loremipsum",
|
||||
"description": "Lorem ipsum generator in PHP without dependencies",
|
||||
"version": "2.0.0",
|
||||
"type": "library",
|
||||
"keywords": [
|
||||
"lorem",
|
||||
"ipsum",
|
||||
"generator"
|
||||
],
|
||||
"homepage": "https://github.com/joshtronic/php-loremipsum",
|
||||
"license": "MIT",
|
||||
"authors": [{
|
||||
"name": "Josh Sherman",
|
||||
"email": "hello@joshtronic.com",
|
||||
"homepage": "https://joshtronic.com"
|
||||
}],
|
||||
"require": {
|
||||
"php": ">=5.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8.36 || ^9.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"joshtronic\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"joshtronic\\Tests\\": "tests/"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
14
phpstan.neon
14
phpstan.neon
|
@ -1,14 +0,0 @@
|
|||
parameters:
|
||||
|
||||
paths:
|
||||
- src
|
||||
|
||||
# The level 8 is the highest level
|
||||
level: max
|
||||
|
||||
excludePaths:
|
||||
- ./*/*/FileToBeExcluded.php
|
||||
|
||||
checkMissingIterableValueType: true
|
||||
|
||||
#editorUrl: 'vscode://file/%%file%%:%%line%%'
|
|
@ -24,7 +24,7 @@ class LoremIpsum
|
|||
* Whether or not we should be starting the string with "Lorem ipsum..."
|
||||
*
|
||||
* @access private
|
||||
* @var mixed
|
||||
* @var boolean
|
||||
*/
|
||||
private $first = true;
|
||||
|
||||
|
@ -35,7 +35,7 @@ class LoremIpsum
|
|||
* a complete list exists and if so, where to get it.
|
||||
*
|
||||
* @access private
|
||||
* @var array<string>
|
||||
* @var array
|
||||
*/
|
||||
private $words = array(
|
||||
// Lorem ipsum...
|
||||
|
@ -83,7 +83,7 @@ class LoremIpsum
|
|||
*/
|
||||
public function word($tags = false)
|
||||
{
|
||||
return strval($this->words(1, $tags));
|
||||
return $this->words(1, $tags);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,7 +94,7 @@ class LoremIpsum
|
|||
* @access public
|
||||
* @param integer $count how many words to generate
|
||||
* @param mixed $tags string or array of HTML tags to wrap output with
|
||||
* @return mixed generated lorem ipsum words
|
||||
* @return array generated lorem ipsum words
|
||||
*/
|
||||
public function wordsArray($count = 1, $tags = false)
|
||||
{
|
||||
|
@ -114,7 +114,6 @@ class LoremIpsum
|
|||
*/
|
||||
public function words($count = 1, $tags = false, $array = false)
|
||||
{
|
||||
$count = (int) $count;
|
||||
$words = array();
|
||||
$word_count = 0;
|
||||
|
||||
|
@ -152,7 +151,7 @@ class LoremIpsum
|
|||
*/
|
||||
public function sentence($tags = false)
|
||||
{
|
||||
return strval($this->sentences(1, $tags));
|
||||
return $this->sentences(1, $tags);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -163,7 +162,7 @@ class LoremIpsum
|
|||
* @access public
|
||||
* @param integer $count how many sentences to generate
|
||||
* @param mixed $tags string or array of HTML tags to wrap output with
|
||||
* @return mixed generated lorem ipsum sentences
|
||||
* @return array generated lorem ipsum sentences
|
||||
*/
|
||||
public function sentencesArray($count = 1, $tags = false)
|
||||
{
|
||||
|
@ -205,7 +204,7 @@ class LoremIpsum
|
|||
*/
|
||||
public function paragraph($tags = false)
|
||||
{
|
||||
return strval($this->paragraphs(1, $tags));
|
||||
return $this->paragraphs(1, $tags);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,18 +215,15 @@ class LoremIpsum
|
|||
* @access public
|
||||
* @param integer $count how many paragraphs to generate
|
||||
* @param mixed $tags string or array of HTML tags to wrap output with
|
||||
* @return array<string> generated lorem ipsum paragraphs
|
||||
* @return array generated lorem ipsum paragraphs
|
||||
*/
|
||||
public function paragraphsArray($count = 1, $tags = false)
|
||||
{
|
||||
// The $array parameter set to true means an array is returned.
|
||||
// Return type is mixed, we should probably cast to array.
|
||||
// @phpstan-ignore-next-line
|
||||
return $this->paragraphs($count, $tags, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paragraphs
|
||||
* Paragraphss
|
||||
*
|
||||
* Generates paragraphs of lorem ipsum.
|
||||
*
|
||||
|
@ -242,13 +238,10 @@ class LoremIpsum
|
|||
$paragraphs = array();
|
||||
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$paragraphs[] = strval($this->sentences($this->gauss(5.8, 1.93)));
|
||||
$paragraphs[] = $this->sentences($this->gauss(5.8, 1.93));
|
||||
}
|
||||
|
||||
if ($array) {
|
||||
return $this->output($paragraphs, $tags, $array, "\n\n");
|
||||
}
|
||||
return strval($this->output($paragraphs, $tags, false, "\n\n"));
|
||||
return $this->output($paragraphs, $tags, $array, "\n\n");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -262,7 +255,7 @@ class LoremIpsum
|
|||
* @access private
|
||||
* @param double $mean average value
|
||||
* @param double $std_dev stadnard deviation
|
||||
* @return int calculated distribution
|
||||
* @return double calculated distribution
|
||||
*/
|
||||
private function gauss($mean, $std_dev)
|
||||
{
|
||||
|
@ -270,7 +263,7 @@ class LoremIpsum
|
|||
$y = mt_rand() / mt_getrandmax();
|
||||
$z = sqrt(-2 * log($x)) * cos(2 * pi() * $y);
|
||||
|
||||
return intval($z * $std_dev + $mean);
|
||||
return $z * $std_dev + $mean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -280,7 +273,6 @@ class LoremIpsum
|
|||
* the first time we are generating the text.
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
private function shuffle()
|
||||
{
|
||||
|
@ -306,18 +298,18 @@ class LoremIpsum
|
|||
* first word of the sentence.
|
||||
*
|
||||
* @access private
|
||||
* @param array<string> $sentences the sentences we would like to punctuate
|
||||
* @return void
|
||||
* @param array $sentences the sentences we would like to punctuate
|
||||
*/
|
||||
private function punctuate(&$sentences)
|
||||
{
|
||||
foreach ($sentences as $key => $sentence) {
|
||||
$words = count($sentence);
|
||||
|
||||
// Only worry about commas on sentences longer than 4 words
|
||||
if ($words > 4) {
|
||||
$mean = log($words, 6);
|
||||
$std_dev = $mean / 6;
|
||||
$commas = $this->gauss($mean, $std_dev);
|
||||
$commas = round($this->gauss($mean, $std_dev));
|
||||
|
||||
for ($i = 1; $i <= $commas; $i++) {
|
||||
$word = round($i * $words / ($commas + 1));
|
||||
|
@ -341,7 +333,7 @@ class LoremIpsum
|
|||
* into a string or not.
|
||||
*
|
||||
* @access private
|
||||
* @param array<string> $strings an array of generated strings
|
||||
* @param array $strings an array of generated strings
|
||||
* @param mixed $tags string or array of HTML tags to wrap output with
|
||||
* @param boolean $array whether an array or a string should be returned
|
||||
* @param string $delimiter the string to use when calling implode()
|
||||
|
@ -380,3 +372,4 @@ class LoremIpsum
|
|||
return $strings;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue