Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: arokettu/monsterid
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4.0.0
Choose a base ref
...
head repository: arokettu/monsterid
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 6 commits
  • 16 files changed
  • 2 contributors

Commits on Jan 3, 2024

  1. Date

    arokettu committed Jan 3, 2024
    Copy the full SHA
    6c0d6a4 View commit details

Commits on Jul 15, 2024

  1. Copy the full SHA
    877c9b6 View commit details
  2. Copy the full SHA
    34c95ed View commit details
  3. Copy the full SHA
    45e7469 View commit details

Commits on Jul 20, 2024

  1. Outdated doc

    arokettu committed Jul 20, 2024
    Copy the full SHA
    f470c30 View commit details

Commits on Oct 13, 2024

  1. Update from templates

    arokettu committed Oct 13, 2024
    Copy the full SHA
    de2873a View commit details
4 changes: 2 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version: 2

build:
os: 'ubuntu-22.04'
os: 'ubuntu-24.04'
tools:
python: '3.11'
python: '3.12'

sphinx:
configuration: 'docs/conf.py'
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@

### 4.0.0

*Jan 3, 2024*

* `$string` parameter is mandatory
* Added getResponse() method to build PSR-7 response object
* Removed all custom exceptions
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@
"httpsoft/http-message": "^1.1",
"phpunit/phpunit": ">= 7.0 < 10",
"psy/psysh": "*",
"sandfox.dev/code-standard": "^1.2023.12.09",
"sandfox.dev/code-standard": "^1.2024.07.05",
"squizlabs/php_codesniffer": "*",
"vimeo/psalm": "^5.4"
}
8 changes: 5 additions & 3 deletions docs/_templates/rtd-version.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{%- if current_version -%}
<div class="sidebar-brand">{{ current_version }}</div>
{%- endif -%}
<div class="navbar-brand">{{ current_version }}</div>

{#- hack scroll issue -#}

<style>#rtd-footer-container{display:none}</style>
58 changes: 49 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -6,23 +6,63 @@
from conf_project import *

author = 'Anton Smirnov'
copyright = '{} {}'.format(datetime.now().year, author)
copyright = '{}'.format(datetime.now().year)
language = 'en'

html_title = project
html_theme = 'furo'
html_theme = 'sphinx_book_theme'
templates_path = ["_templates"]
html_sidebars = {
"**": [
"sidebar/brand.html",
"navbar-logo.html",
"icon-links.html",
"rtd-version.html",
"sidebar/search.html",
"sidebar/scroll-start.html",
"sidebar/navigation.html",
"sidebar/ethical-ads.html",
"sidebar/scroll-end.html",
"sidebar/variant-selector.html",
"search-button-field.html",
"sbt-sidebar-nav.html",
]
}
html_theme_options = {
'use_edit_page_button': True,
'icon_links': [
{
"name": "GitLab",
"url": "https://gitlab.com/sandfox/" + repo,
"icon": "fa-brands fa-square-gitlab",
"type": "fontawesome",
},
{
"name": "GitHub",
"url": "https://github.com/arokettu/" + repo,
"icon": "fa-brands fa-square-github",
"type": "fontawesome",
},
{
"name": "BitBucket",
"url": "https://bitbucket.org/sandfox/" + repo,
"icon": "fa-brands fa-bitbucket",
"type": "fontawesome",
},
{
"name": "Gitea",
"url": "https://sandfox.org/sandfox/" + repo,
"icon": "fa-solid fa-mug-hot",
"type": "fontawesome",
},
]
}
if packagist:
html_theme_options['icon_links'].append({
"name": "Packagist",
"url": "https://packagist.org/packages/" + packagist,
"icon": "https://img.shields.io/packagist/dm/" + packagist + "?style=flat-square",
"type": "url",
})
html_context = {
'current_version': os.environ.get("READTHEDOCS_VERSION_NAME"),
'gitlab_user': "sandfox",
'gitlab_repo': repo,
'gitlab_version': "master",
'doc_path': "docs",
}

exclude_patterns = ['venv/*']
2 changes: 2 additions & 0 deletions docs/conf_project.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
project = 'MonsterID'
repo = 'monsterid'
packagist = 'arokettu/monsterid'
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
furo
sphinx-book-theme
2 changes: 1 addition & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
@@ -124,7 +124,7 @@ Setting a default factory globally
use Arokettu\MonsterID\Randomizer\DefaultV2Factory;
use Arokettu\MonsterID\Randomizer\DefaultV3Factory;

Config::setRandomizerFactory(); // reset to default (currently V2)
Config::setRandomizerFactory(); // reset to default (currently V3)
Config::setRandomizerFactory(new DefaultV0Factory()); // set V0
Config::setRandomizerFactory(new DefaultV1Factory()); // set V1
Config::setRandomizerFactory(new DefaultV2Factory()); // set V2
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -13,4 +13,7 @@
<directory>src</directory>
</include>
</coverage>
<php>
<ini name="error_reporting" value="E_ALL"/>
</php>
</phpunit>
4 changes: 2 additions & 2 deletions src/classes/Config.php
Original file line number Diff line number Diff line change
@@ -9,14 +9,14 @@

final class Config
{
private static ?FactoryInterface $randomizerFactory = null;
private static FactoryInterface|null $randomizerFactory = null;

private static function buildDefault(): FactoryInterface
{
return new DefaultV3Factory();
}

public static function setRandomizerFactory(FactoryInterface $factory = null): void
public static function setRandomizerFactory(FactoryInterface|null $factory = null): void
{
self::$randomizerFactory = $factory ?? self::buildDefault();
}
6 changes: 3 additions & 3 deletions src/classes/Monster.php
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ final class Monster
public function __construct(
private string $string,
private int $size = self::DEFAULT_SIZE,
?FactoryInterface $rngFactory = null
FactoryInterface|null $rngFactory = null
) {
if ($size < 1) {
throw new DomainException('$size must be 1 or more');
@@ -88,8 +88,8 @@ public function getImage(): string
}

public function getResponse(
?ResponseFactoryInterface $responseFactory = null,
?StreamFactoryInterface $streamFactory = null,
ResponseFactoryInterface|null $responseFactory = null,
StreamFactoryInterface|null $streamFactory = null,
): ResponseInterface {
$responseFactory ??= Psr17FactoryDiscovery::findResponseFactory();
$streamFactory ??= Psr17FactoryDiscovery::findStreamFactory();
2 changes: 1 addition & 1 deletion src/classes/Randomizer/DefaultV0Factory.php
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ public function getRandomizer(string $seed): Engine
// original code was:
// $intSeed = hexdec(substr(md5($seed),0,6));

['val' => $val] = unpack("Nval", md5($seed, true));
['val' => $val] = unpack("Nval", hash('md5', $seed, true));
$intSeed = ($val >> 8) & 0xffffff;

// As the original implementation generated on PHP 7.2+
2 changes: 1 addition & 1 deletion src/classes/Randomizer/DefaultV1Factory.php
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ final class DefaultV1Factory implements FactoryInterface
{
public function getRandomizer(string $seed): Engine
{
['val' => $intSeed] = unpack('lval', md5($seed, true)); // convert to 32bit signed integer
['val' => $intSeed] = unpack('lval', hash('md5', $seed, true)); // convert to 32bit signed integer

// As v1.3.0 generated on PHP 7.2+
return new Engine\Mt19937($intSeed, \MT_RAND_MT19937);
2 changes: 1 addition & 1 deletion src/classes/Randomizer/DefaultV2Factory.php
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ final class DefaultV2Factory implements FactoryInterface
{
public function getRandomizer(string $seed): Engine
{
$binSeed = md5($seed, true);
$binSeed = hash('md5', $seed, true);

// first index of unpack is 1
// convert to 32bit signed integer
3 changes: 2 additions & 1 deletion src/classes/Randomizer/Xorshift32.php
Original file line number Diff line number Diff line change
@@ -15,7 +15,8 @@ final class Xorshift32 implements Engine
{
public function __construct(
private int $seed,
) {}
) {
}

public function generate(): string
{
12 changes: 6 additions & 6 deletions src/functions.php
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
function build_monster(
string $string,
int $size = MONSTER_DEFAULT_SIZE,
?FactoryInterface $rngFactory = null,
FactoryInterface|null $rngFactory = null,
): string {
$monster = new Monster($string, $size, $rngFactory);
return $monster->getImage();
@@ -37,7 +37,7 @@ function stream_monster(
$stream,
string $string,
int $size = MONSTER_DEFAULT_SIZE,
?FactoryInterface $rngFactory = null,
FactoryInterface|null $rngFactory = null,
) {
$monster = new Monster($string, $size, $rngFactory);
return $monster->writeToStream($stream);
@@ -51,7 +51,7 @@ function stream_monster(
function build_monster_gd(
string $string,
int $size = MONSTER_DEFAULT_SIZE,
?FactoryInterface $rngFactory = null,
FactoryInterface|null $rngFactory = null,
): GdImage {
$monster = new Monster($string, $size, $rngFactory);
return $monster->getGdImage();
@@ -65,9 +65,9 @@ function build_monster_gd(
function build_monster_response(
string $string,
int $size = MONSTER_DEFAULT_SIZE,
?ResponseFactoryInterface $responseFactory = null,
?StreamFactoryInterface $streamFactory = null,
?FactoryInterface $rngFactory = null,
ResponseFactoryInterface|null $responseFactory = null,
StreamFactoryInterface|null $streamFactory = null,
FactoryInterface|null $rngFactory = null,
): ResponseInterface {
$monster = new Monster($string, $size, $rngFactory);
return $monster->getResponse($responseFactory, $streamFactory);