This repository has been archived on 2019-03-01. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
paper-pi/app/Decorators/RandomNumberDecorator.php
2019-03-01 07:58:22 +01:00

33 lines
804 B
PHP

<?php
/**
* Created by PhpStorm.
* User: k
* Date: 28.02.2019
* Time: 21:28
*/
namespace App\Decorators;
class RandomNumberDecorator extends TextConverterDecorator
{
/**
* przeszukiwanie tekstu pod katem zawartości [ liczba, liczba2 ] i zamienianiu tego na randomową liczbę z przedziału
* liczba - liczba2
* obojętnie czy ujemną czy nie
*/
public function getText(): string
{
$text = $this->text->getText();
$re = '/\[\s*(-?\d+)\s*\,\s*(-?\d+)\s*\]/';
preg_match_all($re, $text, $matches, PREG_SET_ORDER, 0);
foreach ($matches as $match) {
$pos = strpos($text, $match[0]);
$text = substr_replace($text, mt_rand($match[1], $match[2]), $pos, strlen($match[0]));
}
return $text;
}
}