chore: Аннотации к типам

This commit is contained in:
origami11@yandex.ru 2025-10-28 16:32:00 +03:00
parent 386a927254
commit 245b5c6c19
18 changed files with 191 additions and 104 deletions

View file

@ -18,7 +18,7 @@ class Drawing
* @param int $top
* @param int $width
* @param int $height
* @param array $rgb
* @param list<int> $rgb
*/
static function drawRectangle(GdImage &$image, int $left, int $top, int $width, int $height, array $rgb): void
{

View file

@ -26,10 +26,13 @@
* @version $Revision: 1.5 $
* @package creole.util.sql
*/
namespace ctiso\Tools;
use Exception;
class SQLStatementExtractor {
class SQLStatementExtractor
{
protected static $delimiter = ';';
@ -39,10 +42,11 @@ class SQLStatementExtractor {
* @param string $filename Path to file to read.
* @return array SQL statements
*/
public static function extractFile($filename) {
public static function extractFile($filename)
{
$buffer = file_get_contents($filename);
if ($buffer !== false) {
return self::extractStatements(self::getLines($buffer));
return self::extractStatements(self::getLines($buffer));
}
throw new Exception("Unable to read file: " . $filename);
}
@ -53,50 +57,53 @@ class SQLStatementExtractor {
* @param string $buffer
* @return array
*/
public static function extract($buffer) {
public static function extract($buffer)
{
return self::extractStatements(self::getLines($buffer));
}
/**
* Extract SQL statements from array of lines.
*
* @param array $lines Lines of the read-in file.
* @return array
* @param list<string> $lines Lines of the read-in file.
* @return list<string>
*/
protected static function extractStatements($lines) {
protected static function extractStatements($lines)
{
$statements = [];
$sql = "";
foreach($lines as $line) {
foreach ($lines as $line) {
$line = trim($line);
$line = trim($line);
if (self::startsWith("//", $line) ||
self::startsWith("--", $line) ||
self::startsWith("#", $line)) {
continue;
}
if (strlen($line) > 4 && strtoupper(substr($line,0, 4)) == "REM ") {
continue;
}
$sql .= " " . $line;
$sql = trim($sql);
// SQL defines "--" as a comment to EOL
// and in Oracle it may contain a hint
// so we cannot just remove it, instead we must end it
if (strpos($line, "--") !== false) {
$sql .= "\n";
}
if (self::endsWith(self::$delimiter, $sql)) {
$statements[] = self::substring($sql, 0, strlen($sql)-1 - strlen(self::$delimiter));
$sql = "";
}
if (
self::startsWith("//", $line) ||
self::startsWith("--", $line) ||
self::startsWith("#", $line)
) {
continue;
}
if (strlen($line) > 4 && strtoupper(substr($line, 0, 4)) == "REM ") {
continue;
}
$sql .= " " . $line;
$sql = trim($sql);
// SQL defines "--" as a comment to EOL
// and in Oracle it may contain a hint
// so we cannot just remove it, instead we must end it
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;
}
@ -110,7 +117,8 @@ class SQLStatementExtractor {
* @param string $string The string to check in (haystack).
* @return boolean True if $string starts with $check, or they are equal, or $check is empty.
*/
protected static function startsWith($check, $string) {
protected static function startsWith($check, $string)
{
if ($check === "" || $check === $string) {
return true;
} else {
@ -124,7 +132,8 @@ class SQLStatementExtractor {
* @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(string $check, string $string) {
protected static function endsWith(string $check, string $string)
{
if ($check === "" || $check === $string) {
return true;
} else {
@ -136,21 +145,22 @@ class SQLStatementExtractor {
* 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
*/
protected static function substring(string $string, int $startpos, int $endpos = -1) {
protected static function substring(string $string, int $startpos, int $endpos = -1)
{
$len = strlen($string);
$endpos = (int) (($endpos === -1) ? $len-1 : $endpos);
if ($startpos > $len-1 || $startpos < 0) {
$endpos = (int) (($endpos === -1) ? $len - 1 : $endpos);
if ($startpos > $len - 1 || $startpos < 0) {
trigger_error("substring(), Startindex out of bounds must be 0<n<$len", E_USER_ERROR);
}
if ($endpos > $len-1 || $endpos < $startpos) {
trigger_error("substring(), Endindex out of bounds must be $startpos<n<".($len-1), E_USER_ERROR);
if ($endpos > $len - 1 || $endpos < $startpos) {
trigger_error("substring(), Endindex out of bounds must be $startpos<n<" . ($len - 1), E_USER_ERROR);
}
if ($startpos === $endpos) {
return (string) $string[$startpos];
} else {
$len = $endpos-$startpos;
$len = $endpos - $startpos;
}
return substr($string, $startpos, $len+1);
return substr($string, $startpos, $len + 1);
}
/**
@ -159,9 +169,9 @@ class SQLStatementExtractor {
* @param string $buffer
* @return string[] lines of file.
*/
protected static function getLines(string $buffer): array {
$lines = preg_split("/\r?\n|\r/", $buffer);
return $lines;
protected static function getLines(string $buffer): array
{
$lines = preg_split("/\r?\n|\r/", $buffer);
return $lines;
}
}
}