From c5fa857464234d90a84a665dd53e3132ef7989c3 Mon Sep 17 00:00:00 2001 From: lubiana Date: Fri, 27 Jun 2025 23:16:20 +0200 Subject: [PATCH] mache mal statistische analyse mit rein --- composer.json | 19 +++ composer.lock | 280 +++++++++++++++++++++++++++++++++++++- ecs.php | 28 ++++ phpstan.neon | 8 ++ public/index.php | 59 +------- rector.php | 22 +++ src/App.php | 64 +++++++++ src/PlaintextResponse.php | 21 +++ 8 files changed, 444 insertions(+), 57 deletions(-) create mode 100644 ecs.php create mode 100644 phpstan.neon create mode 100644 rector.php create mode 100644 src/App.php create mode 100644 src/PlaintextResponse.php diff --git a/composer.json b/composer.json index 6d00f4b..9220c99 100644 --- a/composer.json +++ b/composer.json @@ -12,5 +12,24 @@ "php": ">=8.4", "symfony/uid": "^7.0", "symfony/http-foundation": "^7.3" + }, + "require-dev": { + "symplify/easy-coding-standard": "^12.5", + "rector/rector": "^2.1", + "phpstan/phpstan": "^2.1", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan-strict-rules": "^2.0" + }, + "config": { + "allow-plugins": { + "phpstan/extension-installer": true + } + }, + "scripts": { + "fix": [ + "rector", + "ecs --fix || ecs --fix" + ], + "phpstan": "phpstan" } } diff --git a/composer.lock b/composer.lock index bd8d5b5..03b1b19 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "745f0c513993cf179f9e68b32a2483c7", + "content-hash": "b10d3777b145d0b70391ba08eb08720f", "packages": [ { "name": "symfony/deprecation-contracts", @@ -463,7 +463,283 @@ "time": "2025-05-24T14:28:13+00:00" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "phpstan/extension-installer", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/phpstan/extension-installer.git", + "reference": "85e90b3942d06b2326fba0403ec24fe912372936" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/85e90b3942d06b2326fba0403ec24fe912372936", + "reference": "85e90b3942d06b2326fba0403ec24fe912372936", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.9.0 || ^2.0" + }, + "require-dev": { + "composer/composer": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2.0", + "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPStan\\ExtensionInstaller\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPStan\\ExtensionInstaller\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Composer plugin for automatic installation of PHPStan extensions", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "issues": "https://github.com/phpstan/extension-installer/issues", + "source": "https://github.com/phpstan/extension-installer/tree/1.4.3" + }, + "time": "2024-09-04T20:21:43+00:00" + }, + { + "name": "phpstan/phpstan", + "version": "2.1.17", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "89b5ef665716fa2a52ecd2633f21007a6a349053" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/89b5ef665716fa2a52ecd2633f21007a6a349053", + "reference": "89b5ef665716fa2a52ecd2633f21007a6a349053", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2025-05-21T20:55:28+00:00" + }, + { + "name": "phpstan/phpstan-strict-rules", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-strict-rules.git", + "reference": "3e139cbe67fafa3588e1dbe27ca50f31fdb6236a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/3e139cbe67fafa3588e1dbe27ca50f31fdb6236a", + "reference": "3e139cbe67fafa3588e1dbe27ca50f31fdb6236a", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.0.4" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^9.6" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Extra strict and opinionated rules for PHPStan", + "support": { + "issues": "https://github.com/phpstan/phpstan-strict-rules/issues", + "source": "https://github.com/phpstan/phpstan-strict-rules/tree/2.0.4" + }, + "time": "2025-03-18T11:42:40+00:00" + }, + { + "name": "rector/rector", + "version": "2.1.0", + "source": { + "type": "git", + "url": "https://github.com/rectorphp/rector.git", + "reference": "d513dea45a94394b660e15c155d1fa27826f8e30" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/d513dea45a94394b660e15c155d1fa27826f8e30", + "reference": "d513dea45a94394b660e15c155d1fa27826f8e30", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0", + "phpstan/phpstan": "^2.1.17" + }, + "conflict": { + "rector/rector-doctrine": "*", + "rector/rector-downgrade-php": "*", + "rector/rector-phpunit": "*", + "rector/rector-symfony": "*" + }, + "suggest": { + "ext-dom": "To manipulate phpunit.xml via the custom-rule command" + }, + "bin": [ + "bin/rector" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Instant Upgrade and Automated Refactoring of any PHP code", + "homepage": "https://getrector.com/", + "keywords": [ + "automation", + "dev", + "migration", + "refactoring" + ], + "support": { + "issues": "https://github.com/rectorphp/rector/issues", + "source": "https://github.com/rectorphp/rector/tree/2.1.0" + }, + "funding": [ + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2025-06-24T20:26:57+00:00" + }, + { + "name": "symplify/easy-coding-standard", + "version": "12.5.20", + "source": { + "type": "git", + "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", + "reference": "bb44b0fc70dd2148d8a6362bc66a35e23dc31bc4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/bb44b0fc70dd2148d8a6362bc66a35e23dc31bc4", + "reference": "bb44b0fc70dd2148d8a6362bc66a35e23dc31bc4", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "conflict": { + "friendsofphp/php-cs-fixer": "<3.46", + "phpcsstandards/php_codesniffer": "<3.8", + "symplify/coding-standard": "<12.1" + }, + "suggest": { + "ext-dom": "Needed to support checkstyle output format in class CheckstyleOutputFormatter" + }, + "bin": [ + "bin/ecs" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Use Coding Standard with 0-knowledge of PHP-CS-Fixer and PHP_CodeSniffer", + "keywords": [ + "Code style", + "automation", + "fixer", + "static analysis" + ], + "support": { + "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.5.20" + }, + "funding": [ + { + "url": "https://www.paypal.me/rectorphp", + "type": "custom" + }, + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2025-05-30T11:42:07+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": {}, diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..b1de5ab --- /dev/null +++ b/ecs.php @@ -0,0 +1,28 @@ +withPaths([ + __DIR__ . '/public', + __DIR__ . '/src', + ]) + ->withRootFiles() + ->withRules([ + NoUnusedImportsFixer::class, + ]) + ->withPhpCsFixerSets( + per: true, + php84Migration: true, + ) + ->withPreparedSets( + arrays: true, + comments: true, + controlStructures: true, + strict: true, + cleanCode: true, + ) +; diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..b68261c --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,8 @@ +includes: + - phar://phpstan.phar/conf/bleedingEdge.neon + +parameters: + level: max + paths: + - public + - src \ No newline at end of file diff --git a/public/index.php b/public/index.php index 98fed13..985381b 100644 --- a/public/index.php +++ b/public/index.php @@ -1,60 +1,9 @@ getPathInfo(); -$scheme = 'https'; -$host = $request->getHost(); -$base = "{$scheme}://{$host}/"; - -function response(string $text): Response { - return new Response($text, 200, [ - 'Content-Type' => 'text/plain', - ]); -} - -$response = match ($path) { - '/uuid/v1' => \response(Uuid::v1()->toString()), - '/uuid/v4' => \response(Uuid::v4()->toString()), - '/uuid/v6' => \response(Uuid::v6()->toString()), - '/uuid/v7' => \response(Uuid::v7()->toString()), - '/ulid' => \response(Ulid::generate()), - '/' => \response(<< new RedirectResponse("/", 301), -}; - -$response->send(); \ No newline at end of file +new App('https://uuid.php.fail/')->run(); diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..6b1003b --- /dev/null +++ b/rector.php @@ -0,0 +1,22 @@ +withPaths([ + __DIR__ . '/public', + __DIR__ . '/src', + ]) + ->withRootFiles() + ->withImportNames(removeUnusedImports: true) + ->withPhpSets() + ->withPreparedSets( + codeQuality: true, + typeDeclarations: true, + earlyReturn: true, + strictBooleans: true, + ) + ->withImportNames(removeUnusedImports: true) +; diff --git a/src/App.php b/src/App.php new file mode 100644 index 0000000..ae16140 --- /dev/null +++ b/src/App.php @@ -0,0 +1,64 @@ +getPathInfo()) { + '/v1' => new PlaintextResponse(Uuid::v1()->toString()), + '/v4' => new PlaintextResponse(Uuid::v4()->toString()), + '/v6' => new PlaintextResponse(Uuid::v6()->toString()), + '/v7' => new PlaintextResponse(Uuid::v7()->toString()), + '/ulid' => new PlaintextResponse(Ulid::generate()), + '/' => new PlaintextResponse( + <<base}v1 + + /v3 - Generate a UUID v3 (name-based, MD5 hash) + curl {$this->base}v3 + + /v4 - Generate a UUID v4 (random) + curl {$this->base}v4 + + /v5 - Generate a UUID v5 (name-based, SHA-1 hash) + curl {$this->base}v5 + + /v6 - Generate a UUID v6 (reordered time-based) + curl {$this->base}v6 + + /v7 - Generate a UUID v7 (Unix timestamp-based) + curl {$this->base}v7 + + /ulid - Generate a ULID + curl {$this->base}ulid + + source: https://git.hannover.ccc.de/lubiana/uuid + TXT + ), + default => new RedirectResponse('/', 301), + }; + } + public function run(?Request $request = null): void + { + $request ??= Request::createFromGlobals(); + $response = $this->handle($request); + $response->send(); + } +} diff --git a/src/PlaintextResponse.php b/src/PlaintextResponse.php new file mode 100644 index 0000000..6277ccf --- /dev/null +++ b/src/PlaintextResponse.php @@ -0,0 +1,21 @@ + $headers */ + public function __construct(?string $content, int $status = 200, array $headers = []) + { + $headers['Content-Type'] ??= 'text/plain'; + parent::__construct( + content: $content, + status: $status, + headers: $headers, + ); + } +}