Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
StyleCIBot committed Jun 24, 2024
1 parent f74f60e commit 6b45b86
Show file tree
Hide file tree
Showing 51 changed files with 547 additions and 547 deletions.
22 changes: 11 additions & 11 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function __construct(array $data = [])

if (empty($this->name)) {
// 当前模型名
$name = str_replace('\\', '/', static::class);
$name = str_replace('\\', '/', static::class);
$this->name = basename($name);
}

Expand Down Expand Up @@ -472,9 +472,9 @@ public function replace(bool $replace = true)
public function refresh(bool $relation = false)
{
if ($this->exists) {
$this->data = $this->db()->find($this->getKey())->getData();
$this->data = $this->db()->find($this->getKey())->getData();
$this->origin = $this->data;
$this->get = [];
$this->get = [];

if ($relation) {
$this->relation = [];
Expand Down Expand Up @@ -561,8 +561,8 @@ public function save(array $data = [], string $sequence = null): bool
$this->trigger('AfterWrite');

// 重新记录原始数据
$this->origin = $this->data;
$this->get = [];
$this->origin = $this->data;
$this->get = [];
$this->lazySave = false;

return true;
Expand Down Expand Up @@ -631,7 +631,7 @@ protected function updateData(): bool

if ($this->autoWriteTimestamp && $this->updateTime) {
// 自动写入更新时间
$data[$this->updateTime] = $this->autoWriteTimestamp();
$data[$this->updateTime] = $this->autoWriteTimestamp();
$this->data[$this->updateTime] = $data[$this->updateTime];
}

Expand All @@ -655,7 +655,7 @@ protected function updateData(): bool

$db->transaction(function () use ($data, $allowFields, $db) {
$this->key = null;
$where = $this->getWhere();
$where = $this->getWhere();

$result = $db->where($where)
->strict(false)
Expand Down Expand Up @@ -696,12 +696,12 @@ protected function insertData(string $sequence = null): bool
// 时间戳自动写入
if ($this->autoWriteTimestamp) {
if ($this->createTime && !isset($data[$this->createTime])) {
$data[$this->createTime] = $this->autoWriteTimestamp();
$data[$this->createTime] = $this->autoWriteTimestamp();
$this->data[$this->createTime] = $data[$this->createTime];
}

if ($this->updateTime && !isset($data[$this->updateTime])) {
$data[$this->updateTime] = $this->autoWriteTimestamp();
$data[$this->updateTime] = $this->autoWriteTimestamp();
$this->data[$this->updateTime] = $data[$this->updateTime];
}
}
Expand Down Expand Up @@ -754,7 +754,7 @@ public function getWhere()
$pk = $this->getPk();

if (is_string($pk) && isset($this->origin[$pk])) {
$where = [[$pk, '=', $this->origin[$pk]]];
$where = [[$pk, '=', $this->origin[$pk]]];
$this->key = $this->origin[$pk];
} elseif (is_array($pk)) {
foreach ($pk as $field) {
Expand Down Expand Up @@ -841,7 +841,7 @@ public function delete(): bool

$this->trigger('AfterDelete');

$this->exists = false;
$this->exists = false;
$this->lazySave = false;

return true;
Expand Down
28 changes: 14 additions & 14 deletions src/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
*/
protected $options = [
'var_page' => 'page',
'path' => '/',
'query' => [],
'path' => '/',
'query' => [],
'fragment' => '',
];

Expand All @@ -104,7 +104,7 @@ public function __construct($items, int $listRows, int $currentPage = 1, int $to

$this->options['path'] = '/' != $this->options['path'] ? rtrim($this->options['path'], '/') : $this->options['path'];

$this->simple = $simple;
$this->simple = $simple;
$this->listRows = $listRows;

if (!$items instanceof Collection) {
Expand All @@ -113,13 +113,13 @@ public function __construct($items, int $listRows, int $currentPage = 1, int $to

if ($simple) {
$this->currentPage = $this->setCurrentPage($currentPage);
$this->hasMore = count($items) > ($this->listRows);
$items = $items->slice(0, $this->listRows);
$this->hasMore = count($items) > ($this->listRows);
$items = $items->slice(0, $this->listRows);
} else {
$this->total = $total;
$this->lastPage = (int) ceil($total / $listRows);
$this->total = $total;
$this->lastPage = (int) ceil($total / $listRows);
$this->currentPage = $this->setCurrentPage($currentPage);
$this->hasMore = $this->currentPage < $this->lastPage;
$this->hasMore = $this->currentPage < $this->lastPage;
}
$this->items = $items;
}
Expand Down Expand Up @@ -172,10 +172,10 @@ protected function url(int $page): string

if (strpos($this->options['path'], '[PAGE]') === false) {
$parameters = [$this->options['var_page'] => $page];
$path = $this->options['path'];
$path = $this->options['path'];
} else {
$parameters = [];
$path = str_replace('[PAGE]', (string) $page, $this->options['path']);
$path = str_replace('[PAGE]', (string) $page, $this->options['path']);
}

if (count($this->options['query']) > 0) {
Expand Down Expand Up @@ -505,11 +505,11 @@ public function toArray(): array
}

return [
'total' => $total,
'per_page' => $this->listRows(),
'total' => $total,
'per_page' => $this->listRows(),
'current_page' => $this->currentPage(),
'last_page' => $this->lastPage,
'data' => $this->items->toArray(),
'last_page' => $this->lastPage,
'data' => $this->items->toArray(),
];
}

Expand Down
62 changes: 31 additions & 31 deletions src/db/BaseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public function field($field)
if (true === $field) {
// 获取全部字段
$fields = $this->getTableFields();
$field = $fields ?: ['*'];
$field = $fields ?: ['*'];
}

if (isset($this->options['field'])) {
Expand Down Expand Up @@ -373,7 +373,7 @@ public function withoutField($field)

// 字段排除
$fields = $this->getTableFields();
$field = $fields ? array_diff($fields, $field) : $field;
$field = $fields ? array_diff($fields, $field) : $field;

if (isset($this->options['field'])) {
$field = array_merge((array) $this->options['field'], $field);
Expand Down Expand Up @@ -406,7 +406,7 @@ public function tableField($field, string $tableName, string $prefix = '', strin
if (true === $field) {
// 获取全部字段
$fields = $this->getTableFields($tableName);
$field = $fields ?: ['*'];
$field = $fields ?: ['*'];
}

// 添加统一的前缀
Expand Down Expand Up @@ -452,7 +452,7 @@ public function removeOption(string $option = '')
{
if ('' === $option) {
$this->options = [];
$this->bind = [];
$this->bind = [];
} elseif (isset($this->options[$option])) {
unset($this->options[$option]);
}
Expand Down Expand Up @@ -502,13 +502,13 @@ public function table($table)
} elseif (false === strpos($table, ',')) {
if (strpos($table, ' ')) {
[$item, $alias] = explode(' ', $table);
$table = [];
$table = [];
$this->alias([$item => $alias]);
$table[$item] = $alias;
}
} else {
$tables = explode(',', $table);
$table = [];
$table = [];

foreach ($tables as $item) {
$item = trim($item);
Expand All @@ -523,7 +523,7 @@ public function table($table)
}
} elseif (is_array($table)) {
$tables = $table;
$table = [];
$table = [];

foreach ($tables as $key => $val) {
if (is_numeric($key)) {
Expand Down Expand Up @@ -600,22 +600,22 @@ public function order($field, string $order = '')
public function paginate($listRows = null, $simple = false): Paginator
{
if (is_int($simple)) {
$total = $simple;
$total = $simple;
$simple = false;
}

$defaultConfig = [
'query' => [], //url额外参数
'fragment' => '', //url锚点
'var_page' => 'page', //分页变量
'query' => [], //url额外参数
'fragment' => '', //url锚点
'var_page' => 'page', //分页变量
'list_rows' => 15, //每页数量
];

if (is_array($listRows)) {
$config = array_merge($defaultConfig, $listRows);
$config = array_merge($defaultConfig, $listRows);
$listRows = intval($config['list_rows']);
} else {
$config = $defaultConfig;
$config = $defaultConfig;
$listRows = intval($listRows ?: $config['list_rows']);
}

Expand All @@ -630,7 +630,7 @@ public function paginate($listRows = null, $simple = false): Paginator

unset($this->options['order'], $this->options['cache'], $this->options['limit'], $this->options['page'], $this->options['field']);

$bind = $this->bind;
$bind = $this->bind;
$total = $this->count();
if ($total > 0) {
$results = $this->options($options)->bind($bind)->page($page, $listRows)->select();
Expand All @@ -643,7 +643,7 @@ public function paginate($listRows = null, $simple = false): Paginator
}
} elseif ($simple) {
$results = $this->limit(($page - 1) * $listRows, $listRows + 1)->select();
$total = null;
$total = null;
} else {
$results = $this->page($page, $listRows)->select();
}
Expand All @@ -666,20 +666,20 @@ public function paginate($listRows = null, $simple = false): Paginator
public function paginateX($listRows = null, string $key = null, string $sort = null): Paginator
{
$defaultConfig = [
'query' => [], //url额外参数
'fragment' => '', //url锚点
'var_page' => 'page', //分页变量
'query' => [], //url额外参数
'fragment' => '', //url锚点
'var_page' => 'page', //分页变量
'list_rows' => 15, //每页数量
];

$config = is_array($listRows) ? array_merge($defaultConfig, $listRows) : $defaultConfig;
$config = is_array($listRows) ? array_merge($defaultConfig, $listRows) : $defaultConfig;
$listRows = is_int($listRows) ? $listRows : (int) $config['list_rows'];
$page = isset($config['page']) ? (int) $config['page'] : Paginator::getCurrentPage($config['var_page']);
$page = $page < 1 ? 1 : $page;
$page = isset($config['page']) ? (int) $config['page'] : Paginator::getCurrentPage($config['var_page']);
$page = $page < 1 ? 1 : $page;

$config['path'] = $config['path'] ?? Paginator::getCurrentPath();

$key = $key ?: $this->getPk();
$key = $key ?: $this->getPk();
$options = $this->getOptions();

if (is_null($sort)) {
Expand Down Expand Up @@ -759,7 +759,7 @@ public function more(int $limit, $lastId = null, string $key = null, string $sor
$result->first();

return [
'data' => $result,
'data' => $result,
'lastId' => $last ? $last[$key] : null,
];
}
Expand All @@ -780,10 +780,10 @@ public function cache($key = true, $expire = null, $tag = null)

if ($key instanceof \DateTimeInterface || $key instanceof \DateInterval || (is_int($key) && is_null($expire))) {
$expire = $key;
$key = true;
$key = true;
}

$this->options['cache'] = [$key, $expire, $tag ?: $this->getTable()];
$this->options['cache'] = [$key, $expire, $tag ?: $this->getTable()];

return $this;
}
Expand Down Expand Up @@ -898,7 +898,7 @@ public function sequence(string $sequence = null)
*/
public function json(array $json = [], bool $assoc = false)
{
$this->options['json'] = $json;
$this->options['json'] = $json;
$this->options['json_assoc'] = $assoc;

return $this;
Expand Down Expand Up @@ -1254,10 +1254,10 @@ public function parseOptions(): array
if (isset($options['page'])) {
// 根据页数计算limit
[$page, $listRows] = $options['page'];
$page = $page > 0 ? $page : 1;
$listRows = $listRows ?: (is_numeric($options['limit']) ? $options['limit'] : 20);
$offset = $listRows * ($page - 1);
$options['limit'] = $offset . ',' . $listRows;
$page = $page > 0 ? $page : 1;
$listRows = $listRows ?: (is_numeric($options['limit']) ? $options['limit'] : 20);
$offset = $listRows * ($page - 1);
$options['limit'] = $offset . ',' . $listRows;
}

$this->options = $options;
Expand All @@ -1274,7 +1274,7 @@ public function parseOptions(): array
*/
public function parseUpdateData(&$data): bool
{
$pk = $this->getPk();
$pk = $this->getPk();
$isUpdate = false;
// 如果存在主键数据 则自动作为更新条件
if (is_string($pk) && isset($data[$pk])) {
Expand Down
Loading

0 comments on commit 6b45b86

Please sign in to comment.