From cd031464e61bf6f0027ee267651579c71a41b6c6 Mon Sep 17 00:00:00 2001
From: Troy Grunt
Date: Sun, 15 Feb 2026 14:45:02 +0100
Subject: [PATCH] strikt types
---
NEXT_STEPS.md | 9 ---------
_func.php | 3 ++-
debug.php | 8 +++++---
ips/crawler.php | 6 ++++--
link-meta.php | 7 ++-----
mail.php | 10 ++++++----
markdown.php | 7 ++++---
numbers.php | 8 +++++---
og.php | 6 ++++--
secret.php.example | 32 +++++++++++++++++---------------
sql.php | 14 ++++++++------
string.php | 30 ++++++++++++++++--------------
troy-api.php | 6 ++++--
13 files changed, 77 insertions(+), 69 deletions(-)
diff --git a/NEXT_STEPS.md b/NEXT_STEPS.md
index 4eed752..4d459d4 100644
--- a/NEXT_STEPS.md
+++ b/NEXT_STEPS.md
@@ -2,15 +2,6 @@
## Issue Drafts (Ready for Gitea/GitHub)
-- #TODO Enable strict types + typed signatures
-- Aufwand: `M`
-- Labels: `quality`, `refactor`
-- Ziel: Konsistente Typen und weniger implizite Typfehler.
-- Akzeptanzkriterien:
-- Alle PHP-Dateien starten mit `declare(strict_types=1);` (wo kompatibel).
-- Oeffentliche Funktionen erhalten Rueckgabe-/Parameter-Typen.
-- Inkompatible Stellen sind dokumentiert oder angepasst.
-
- #TODO Define unified error strategy
- Aufwand: `M`
- Labels: `quality`, `api`
diff --git a/_func.php b/_func.php
index d11c170..923b46b 100644
--- a/_func.php
+++ b/_func.php
@@ -1,4 +1,5 @@
\ No newline at end of file
+?>
diff --git a/debug.php b/debug.php
index ac60ed5..978f063 100644
--- a/debug.php
+++ b/debug.php
@@ -1,14 +1,16 @@
\ No newline at end of file
+?>
diff --git a/ips/crawler.php b/ips/crawler.php
index 6de1b40..f75696e 100644
--- a/ips/crawler.php
+++ b/ips/crawler.php
@@ -1,4 +1,6 @@
\ No newline at end of file
+?>
diff --git a/link-meta.php b/link-meta.php
index a92db62..6c1b249 100644
--- a/link-meta.php
+++ b/link-meta.php
@@ -1,4 +1,5 @@
\ No newline at end of file
+?>
diff --git a/markdown.php b/markdown.php
index 0d90701..3a77050 100644
--- a/markdown.php
+++ b/markdown.php
@@ -1,6 +1,7 @@
';
$lv = 0;
@@ -75,10 +76,10 @@ function md($str) {
$text .= '
';
return $text;
}
-function _md_link_replacer($in) {
+function _md_link_replacer(array $in): string {
// var_dump ( $in );
$in = explode ( '|', $in [1], 2 );
return '' . (isset ( $in [1] ) ? $in [1] : $in [0]) . '';
}
-?>
\ No newline at end of file
+?>
diff --git a/numbers.php b/numbers.php
index 7f97f26..25c99b4 100644
--- a/numbers.php
+++ b/numbers.php
@@ -1,5 +1,7 @@
\ No newline at end of file
+?>
diff --git a/og.php b/og.php
index fb644d4..24a2add 100644
--- a/og.php
+++ b/og.php
@@ -1,5 +1,7 @@
\ No newline at end of file
+?>
diff --git a/secret.php.example b/secret.php.example
index 1077fb5..0052050 100644
--- a/secret.php.example
+++ b/secret.php.example
@@ -1,15 +1,17 @@
-
\ No newline at end of file
+
diff --git a/sql.php b/sql.php
index e0ae57e..2f3c4d3 100644
--- a/sql.php
+++ b/sql.php
@@ -1,4 +1,6 @@
cnt_get ++;
if (SQL_LOG)
@@ -89,14 +91,14 @@ class SQL {
}
return $ret;
}
- public function single($que, $t = '', $p = array ()) {
+ public function single(string $que, string $t = '', mixed $p = array ()): array|false {
$data = $this->get ( $que, $t, $p );
if ($data) {
return $data [0];
}
return false;
}
- public function list($que, $t = '', $p = array ()) {
+ public function list(string $que, string $t = '', mixed $p = array ()): array|false {
$data = $this->get ( $que, $t, $p );
if ($data) {
$ret = array ();
@@ -109,7 +111,7 @@ class SQL {
}
return false;
}
- public function keyval($que, $k, $v, $t = '', $p = array ()) {
+ public function keyval(string $que, string|int $k, string|int $v, string $t = '', mixed $p = array ()): array|false {
$data = $this->get ( $que, $t, $p );
if ($data) {
$ret = array ();
@@ -120,7 +122,7 @@ class SQL {
}
return false;
}
- public function set($que, $t = '', $p = array (), $id = false) {
+ public function set(string $que, string $t = '', mixed $p = array (), bool $id = false): int|false {
// echo $que;
$this->cnt_set ++;
$statement = $this->h->prepare ( $que );
@@ -189,7 +191,7 @@ class SQL {
return $statement->affected_rows;
}
}
- function __destruct() {
+ function __destruct(): void {
if (SQL_LOG)
$this->h->close ();
// echo 'DESTROY';
diff --git a/string.php b/string.php
index f0b6137..8af8939 100644
--- a/string.php
+++ b/string.php
@@ -1,5 +1,7 @@
'
@@ -32,7 +34,7 @@ function noScript($str) {
'>'
), $str );
}
-function random($name_laenge) {
+function random(int $name_laenge): string {
$zeichen = "abcedfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRTSUVWXYZ0123456789";
$name_neu = "";
@@ -43,32 +45,32 @@ function random($name_laenge) {
}
return $name_neu;
}
-function startsWith($haystack, $needle) {
+function startsWith(string $haystack, string $needle): bool {
$length = strlen ( $needle );
return (substr ( $haystack, 0, $length ) === $needle);
}
-function endsWith($haystack, $needle) {
+function endsWith(string $haystack, string $needle): bool {
$length = strlen ( $needle );
return $length === 0 || (substr ( $haystack, - $length ) === $needle);
}
-function onlyAlpha($str, $zus = '') {
+function onlyAlpha(string $str, string $zus = ''): string {
return preg_replace ( "/[^a-zA-Z0-9 \-\{$zus}_]+/", "", $str );
}
-function shortener($str, $len = 50, $fill = '...') {
+function shortener(string $str, int $len = 50, string $fill = '...'): string {
if (strlen ( $str ) > $len) {
$str = substr ( $str, 0, $len - strlen ( $fill ) ) . $fill;
}
return $str;
}
-function isEmail($str) {
+function isEmail(string $str): string|false {
$match = preg_match ( "/[a-zA-Z0-9\-\_\.]*\@[a-zA-Z0-9\-\_\.]*.[a-z]{2,10}/", $str );
if ($match) {
return $str;
}
return false;
}
-function markUp($text) {
+function markUp(string $text): string {
$r = '';
$lv = 0;
foreach ( explode ( "\n", $text ) as $t ) {
@@ -127,7 +129,7 @@ function markUp($text) {
}
return $r;
}
-function onlySimpleHTML($s) {
+function onlySimpleHTML(string $s): string {
$s = str_replace ( array (
'<',
'>'
@@ -259,14 +261,14 @@ function onlySimpleHTML($s) {
return $s;
}
-function linkify($input) {
+function linkify(string $input): string {
$pattern = '@(http(s)?://[a-zA-Z0-9/\.\#\-\_]*)@';
return $output = preg_replace ( $pattern, '$1', $input );
}
-function inStr($needle, $haystack) {
+function inStr(string $needle, string $haystack): bool {
if (strpos ( $haystack, $needle ) !== false) {
return true;
}
return false;
}
-?>
\ No newline at end of file
+?>
diff --git a/troy-api.php b/troy-api.php
index 8540d40..64e6e42 100644
--- a/troy-api.php
+++ b/troy-api.php
@@ -1,5 +1,7 @@
array (
@@ -14,7 +16,7 @@ function sendToTroy($data) {
return file_get_contents ( $url, false, $context );
}
-function sendToGitea($title, $message) {
+function sendToGitea(string $title, string $message): array|null {
// secret.php liegt in lib/
require 'secret.php';