fix: Определения типов

This commit is contained in:
origami11@yandex.ru 2025-10-01 12:37:39 +03:00
parent 9f6fd74b17
commit dd74a97894
28 changed files with 334 additions and 249 deletions

View file

@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information please see
* <http://creole.phpdb.org>.
*/
/**
* Static class for extracting SQL statements from a string or file.
*
@ -30,12 +30,12 @@ namespace ctiso\Tools;
use Exception;
class SQLStatementExtractor {
protected static $delimiter = ';';
/**
* Get SQL statements from file.
*
*
* @param string $filename Path to file to read.
* @return array SQL statements
*/
@ -46,17 +46,17 @@ class SQLStatementExtractor {
}
throw new Exception("Unable to read file: " . $filename);
}
/**
* Extract statements from string.
*
*
* @param string $buffer
* @return array
*/
public static function extract($buffer) {
return self::extractStatements(self::getLines($buffer));
}
/**
* Extract SQL statements from array of lines.
*
@ -64,20 +64,20 @@ class SQLStatementExtractor {
* @return array
*/
protected static function extractStatements($lines) {
$statements = [];
$sql = "";
foreach($lines as $line) {
$line = trim($line);
if (self::startsWith("//", $line) ||
if (self::startsWith("//", $line) ||
self::startsWith("--", $line) ||
self::startsWith("#", $line)) {
continue;
}
if (strlen($line) > 4 && strtoupper(substr($line,0, 4)) == "REM ") {
continue;
}
@ -91,19 +91,19 @@ class SQLStatementExtractor {
if (strpos($line, "--") !== false) {
$sql .= "\n";
}
if (self::endsWith(self::$delimiter, $sql)) {
$statements[] = self::substring($sql, 0, strlen($sql)-1 - strlen(self::$delimiter));
$sql = "";
}
}
return $statements;
return $statements;
}
//
// Some string helper methods
//
//
/**
* Tests if a string starts with a given string.
* @param string $check The substring to check.
@ -117,24 +117,24 @@ class SQLStatementExtractor {
return (strpos($string, $check) === 0);
}
}
/**
* Tests if a string ends with a given string.
* @param string $check The substring to check.
* @param string $string The string to check in (haystack).
* @return boolean True if $string ends with $check, or they are equal, or $check is empty.
*/
protected static function endsWith($check/*: string*/, $string) {
protected static function endsWith(string $check, $string) {
if ($check === "" || $check === $string) {
return true;
} else {
return (strpos(strrev($string), strrev($check)) === 0);
}
}
}
/**
* a natural way of getting a subtring, php's circular string buffer and strange
* return values suck if you want to program strict as of C or friends
* return values suck if you want to program strict as of C or friends
*/
protected static function substring($string, $startpos, $endpos = -1) {
$len = strlen($string);
@ -152,16 +152,16 @@ class SQLStatementExtractor {
}
return substr($string, $startpos, $len+1);
}
/**
* Convert string buffer into array of lines.
*
*
* @param string $buffer
* @return array string[] lines of file.
*/
protected static function getLines($buffer) {
protected static function getLines($buffer) {
$lines = preg_split("/\r?\n|\r/", $buffer);
return $lines;
}
}