mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-09 05:38:39 +00:00
Fix types
This commit is contained in:
parent
d633d96462
commit
a0b51cef62
|
|
@ -38,7 +38,7 @@ final class Builder extends BuilderAbstract
|
||||||
/**
|
/**
|
||||||
* Columns.
|
* Columns.
|
||||||
*
|
*
|
||||||
* @var array<string, array<string, string>>
|
* @var array
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public $selects = [];
|
public $selects = [];
|
||||||
|
|
@ -46,7 +46,7 @@ final class Builder extends BuilderAbstract
|
||||||
/**
|
/**
|
||||||
* Columns.
|
* Columns.
|
||||||
*
|
*
|
||||||
* @var array<string, array<string, string>>
|
* @var array
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public $updates = [];
|
public $updates = [];
|
||||||
|
|
@ -260,7 +260,7 @@ final class Builder extends BuilderAbstract
|
||||||
$this->type = QueryType::SELECT;
|
$this->type = QueryType::SELECT;
|
||||||
|
|
||||||
foreach ($columns as $key => $column) {
|
foreach ($columns as $key => $column) {
|
||||||
if (is_string($column) || $column instanceof \Closure) {
|
if (\is_string($column) || $column instanceof \Closure) {
|
||||||
$this->selects[] = $column;
|
$this->selects[] = $column;
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException();
|
throw new \InvalidArgumentException();
|
||||||
|
|
@ -293,7 +293,7 @@ final class Builder extends BuilderAbstract
|
||||||
/**
|
/**
|
||||||
* Bind parameter.
|
* Bind parameter.
|
||||||
*
|
*
|
||||||
* @param string|array|\Closure $binds Binds
|
* @param mixed $binds Binds
|
||||||
*
|
*
|
||||||
* @return Builder
|
* @return Builder
|
||||||
*
|
*
|
||||||
|
|
@ -301,9 +301,9 @@ final class Builder extends BuilderAbstract
|
||||||
*/
|
*/
|
||||||
public function bind($binds) : Builder
|
public function bind($binds) : Builder
|
||||||
{
|
{
|
||||||
if (is_array($binds)) {
|
if (\is_array($binds)) {
|
||||||
$this->binds += $binds;
|
$this->binds += $binds;
|
||||||
} elseif (is_string($binds) || $binds instanceof \Closure) {
|
} elseif (\is_string($binds) || $binds instanceof \Closure) {
|
||||||
$this->binds[] = $binds;
|
$this->binds[] = $binds;
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException();
|
throw new \InvalidArgumentException();
|
||||||
|
|
@ -336,18 +336,6 @@ final class Builder extends BuilderAbstract
|
||||||
return $this->grammar->compileQuery($this);
|
return $this->grammar->compileQuery($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Parsing to prepared string.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function toPrepared() : string
|
|
||||||
{
|
|
||||||
return $this->grammar->compilePreparedQuery($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set raw query.
|
* Set raw query.
|
||||||
*
|
*
|
||||||
|
|
@ -387,14 +375,14 @@ final class Builder extends BuilderAbstract
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$test = strtolower($raw);
|
$test = \strtolower($raw);
|
||||||
|
|
||||||
if (strpos($test, 'insert') !== false
|
if (\strpos($test, 'insert') !== false
|
||||||
|| strpos($test, 'update') !== false
|
|| \strpos($test, 'update') !== false
|
||||||
|| strpos($test, 'drop') !== false
|
|| \strpos($test, 'drop') !== false
|
||||||
|| strpos($test, 'delete') !== false
|
|| \strpos($test, 'delete') !== false
|
||||||
|| strpos($test, 'create') !== false
|
|| \strpos($test, 'create') !== false
|
||||||
|| strpos($test, 'alter') !== false
|
|| \strpos($test, 'alter') !== false
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -435,7 +423,7 @@ final class Builder extends BuilderAbstract
|
||||||
/**
|
/**
|
||||||
* From.
|
* From.
|
||||||
*
|
*
|
||||||
* @param string|array ...$tables Tables
|
* @param array ...$tables Tables
|
||||||
*
|
*
|
||||||
* @return Builder
|
* @return Builder
|
||||||
*
|
*
|
||||||
|
|
@ -444,7 +432,7 @@ final class Builder extends BuilderAbstract
|
||||||
public function from(...$tables) : Builder
|
public function from(...$tables) : Builder
|
||||||
{
|
{
|
||||||
foreach ($tables as $key => $table) {
|
foreach ($tables as $key => $table) {
|
||||||
if (is_string($table) || $table instanceof \Closure) {
|
if (\is_string($table) || $table instanceof \Closure) {
|
||||||
$this->from[] = $table;
|
$this->from[] = $table;
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException();
|
throw new \InvalidArgumentException();
|
||||||
|
|
@ -486,11 +474,11 @@ final class Builder extends BuilderAbstract
|
||||||
*/
|
*/
|
||||||
public function where($columns, $operator = null, $values = null, $boolean = 'and') : Builder
|
public function where($columns, $operator = null, $values = null, $boolean = 'and') : Builder
|
||||||
{
|
{
|
||||||
if ($operator !== null && !is_array($operator) && !\in_array(strtolower($operator), self::OPERATORS)) {
|
if ($operator !== null && !\is_array($operator) && !\in_array(\strtolower($operator), self::OPERATORS)) {
|
||||||
throw new \InvalidArgumentException('Unknown operator.');
|
throw new \InvalidArgumentException('Unknown operator.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($columns)) {
|
if (!\is_array($columns)) {
|
||||||
$columns = [$columns];
|
$columns = [$columns];
|
||||||
$operator = [$operator];
|
$operator = [$operator];
|
||||||
$values = [$values];
|
$values = [$values];
|
||||||
|
|
@ -499,7 +487,7 @@ final class Builder extends BuilderAbstract
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($columns as $key => $column) {
|
foreach ($columns as $key => $column) {
|
||||||
if (isset($operator[$i]) && !\in_array(strtolower($operator[$i]), self::OPERATORS)) {
|
if (isset($operator[$i]) && !\in_array(\strtolower($operator[$i]), self::OPERATORS)) {
|
||||||
throw new \InvalidArgumentException('Unknown operator.');
|
throw new \InvalidArgumentException('Unknown operator.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -545,11 +533,11 @@ final class Builder extends BuilderAbstract
|
||||||
*/
|
*/
|
||||||
public function getTableOfSystem($expression, string $systemIdentifier) : ?string
|
public function getTableOfSystem($expression, string $systemIdentifier) : ?string
|
||||||
{
|
{
|
||||||
if (($pos = strpos($expression, $systemIdentifier . '.' . $systemIdentifier)) === false) {
|
if (($pos = \strpos($expression, $systemIdentifier . '.' . $systemIdentifier)) === false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return explode('.', $expression)[0];
|
return \explode('.', $expression)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -648,7 +636,7 @@ final class Builder extends BuilderAbstract
|
||||||
public function groupBy(...$columns) : Builder
|
public function groupBy(...$columns) : Builder
|
||||||
{
|
{
|
||||||
foreach ($columns as $key => $column) {
|
foreach ($columns as $key => $column) {
|
||||||
if (is_string($column) || $column instanceof \Closure) {
|
if (\is_string($column) || $column instanceof \Closure) {
|
||||||
$this->groups[] = $column;
|
$this->groups[] = $column;
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException();
|
throw new \InvalidArgumentException();
|
||||||
|
|
@ -702,8 +690,8 @@ final class Builder extends BuilderAbstract
|
||||||
*/
|
*/
|
||||||
public function orderBy($columns, $order = 'DESC') : Builder
|
public function orderBy($columns, $order = 'DESC') : Builder
|
||||||
{
|
{
|
||||||
if (is_string($columns) || $columns instanceof \Closure) {
|
if (\is_string($columns) || $columns instanceof \Closure) {
|
||||||
if (!is_string($order)) {
|
if (!\is_string($order)) {
|
||||||
throw new \InvalidArgumentException();
|
throw new \InvalidArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -712,9 +700,9 @@ final class Builder extends BuilderAbstract
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->orders[$order][] = $columns;
|
$this->orders[$order][] = $columns;
|
||||||
} elseif (is_array($columns)) {
|
} elseif (\is_array($columns)) {
|
||||||
foreach ($columns as $key => $column) {
|
foreach ($columns as $key => $column) {
|
||||||
$this->orders[is_string($order) ? $order : $order[$key]][] = $column;
|
$this->orders[\is_string($order) ? $order : $order[$key]][] = $column;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException();
|
throw new \InvalidArgumentException();
|
||||||
|
|
@ -766,7 +754,7 @@ final class Builder extends BuilderAbstract
|
||||||
*/
|
*/
|
||||||
public function union($query) : Builder
|
public function union($query) : Builder
|
||||||
{
|
{
|
||||||
if (!is_array($query)) {
|
if (!\is_array($query)) {
|
||||||
$this->unions[] = $query;
|
$this->unions[] = $query;
|
||||||
} else {
|
} else {
|
||||||
$this->unions += $query;
|
$this->unions += $query;
|
||||||
|
|
@ -1022,7 +1010,7 @@ final class Builder extends BuilderAbstract
|
||||||
$this->type = QueryType::UPDATE;
|
$this->type = QueryType::UPDATE;
|
||||||
|
|
||||||
foreach ($tables as $key => $table) {
|
foreach ($tables as $key => $table) {
|
||||||
if (is_string($table) || $table instanceof \Closure) {
|
if (\is_string($table) || $table instanceof \Closure) {
|
||||||
$this->updates[] = $table;
|
$this->updates[] = $table;
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException();
|
throw new \InvalidArgumentException();
|
||||||
|
|
@ -1214,9 +1202,9 @@ final class Builder extends BuilderAbstract
|
||||||
*/
|
*/
|
||||||
public static function getBindParamType($value)
|
public static function getBindParamType($value)
|
||||||
{
|
{
|
||||||
if (is_int($value)) {
|
if (\is_int($value)) {
|
||||||
return \PDO::PARAM_INT;
|
return \PDO::PARAM_INT;
|
||||||
} elseif (is_string($value) || is_float($value)) {
|
} elseif (\is_string($value) || \is_float($value)) {
|
||||||
return \PDO::PARAM_STR;
|
return \PDO::PARAM_STR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1236,10 +1224,10 @@ final class Builder extends BuilderAbstract
|
||||||
*/
|
*/
|
||||||
public static function getPublicColumnName($column) : string
|
public static function getPublicColumnName($column) : string
|
||||||
{
|
{
|
||||||
if (is_string($column)) {
|
if (\is_string($column)) {
|
||||||
return $column;
|
return $column;
|
||||||
} elseif ($column instanceof Column) {
|
} elseif ($column instanceof Column) {
|
||||||
return $column->getPublicName();
|
return $column->getColumn();
|
||||||
} elseif ($column instanceof \Closure) {
|
} elseif ($column instanceof \Closure) {
|
||||||
return $column();
|
return $column();
|
||||||
} elseif ($column instanceof \Serializable) {
|
} elseif ($column instanceof \Serializable) {
|
||||||
|
|
|
||||||
|
|
@ -117,14 +117,14 @@ class Text
|
||||||
/**
|
/**
|
||||||
* Get a random string.
|
* Get a random string.
|
||||||
*
|
*
|
||||||
* @param int $length Text length
|
* @param int $length Text length
|
||||||
* @param int $words Vocabulary
|
* @param array $words Vocabulary
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function generateText(int $length, $words = null) : string
|
public function generateText(int $length, array $words = null) : string
|
||||||
{
|
{
|
||||||
if ($length === 0) {
|
if ($length === 0) {
|
||||||
return '';
|
return '';
|
||||||
|
|
@ -135,8 +135,8 @@ class Text
|
||||||
}
|
}
|
||||||
|
|
||||||
$punctuation = $this->generatePunctuation($length);
|
$punctuation = $this->generatePunctuation($length);
|
||||||
$punctuationCount = array_count_values(
|
$punctuationCount = \array_count_values(
|
||||||
array_map(
|
\array_map(
|
||||||
function ($item) {
|
function ($item) {
|
||||||
return $item[1];
|
return $item[1];
|
||||||
},
|
},
|
||||||
|
|
@ -163,20 +163,20 @@ class Text
|
||||||
for ($i = 0; $i < $length + 1; ++$i) {
|
for ($i = 0; $i < $length + 1; ++$i) {
|
||||||
$newSentence = false;
|
$newSentence = false;
|
||||||
|
|
||||||
$lastChar = substr($text, -1);
|
$lastChar = \substr($text, -1);
|
||||||
|
|
||||||
if ($lastChar === '.' || $lastChar === '!' || $lastChar === '?' || !$lastChar) {
|
if ($lastChar === '.' || $lastChar === '!' || $lastChar === '?' || !$lastChar) {
|
||||||
$newSentence = true;
|
$newSentence = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$word = $words[rand(0, $wordCount - 1)];
|
$word = $words[rand(0, $wordCount - 1)] ?? '';
|
||||||
|
|
||||||
if ($newSentence) {
|
if ($newSentence) {
|
||||||
$word = ucfirst($word);
|
$word = \ucfirst($word);
|
||||||
$sentenceCount++;
|
$sentenceCount++;
|
||||||
|
|
||||||
/** @noinspection PhpUndefinedVariableInspection */
|
/** @noinspection PhpUndefinedVariableInspection */
|
||||||
if ($this->hasParagraphs && $sentenceCount === $paragraph[$paid]) {
|
if ($this->hasParagraphs) {
|
||||||
$paid++;
|
$paid++;
|
||||||
|
|
||||||
$text .= '</p><p>';
|
$text .= '</p><p>';
|
||||||
|
|
@ -184,7 +184,7 @@ class Text
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @noinspection PhpUndefinedVariableInspection */
|
/** @noinspection PhpUndefinedVariableInspection */
|
||||||
if ($this->hasFormatting && array_key_exists($i, $formatting)) {
|
if ($this->hasFormatting && isset($formatting[$i])) {
|
||||||
$word = '<' . $formatting[$i] . '>' . $word . '</' . $formatting[$i] . '>';
|
$word = '<' . $formatting[$i] . '>' . $word . '</' . $formatting[$i] . '>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -276,11 +276,11 @@ class Text
|
||||||
*
|
*
|
||||||
* @param int $length Amount of sentences
|
* @param int $length Amount of sentences
|
||||||
*
|
*
|
||||||
* @return string
|
* @return array
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private function generateParagraph(int $length) : string
|
private function generateParagraph(int $length) : array
|
||||||
{
|
{
|
||||||
$minSentence = 3;
|
$minSentence = 3;
|
||||||
$maxSentence = 10;
|
$maxSentence = 10;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user