Skip to content

Commit

Permalink
Merge pull request #442 from AntonShevchuk/master
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
Anton committed Oct 12, 2017
2 parents cd93415 + 812be85 commit 3e9a7d5
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
16 changes: 8 additions & 8 deletions src/Db/Table.php
Expand Up @@ -195,10 +195,11 @@ public function getModel()
*
* @return array
*/
public function getColumns()
public static function getColumns()
{
if (empty($this->columns)) {
$cacheKey = "db.table.{$this->name}";
$self = static::getInstance();
if (empty($self->columns)) {
$cacheKey = "db.table.{$self->name}";
$columns = Cache::get($cacheKey);
if (!$columns) {
$schema = DbProxy::getOption('connect', 'name');
Expand All @@ -209,13 +210,13 @@ public function getColumns()
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = ?
AND TABLE_NAME = ?',
[$schema, $this->getName()]
[$schema, $self->getName()]
);
Cache::set($cacheKey, $columns, Cache::TTL_NO_EXPIRY, ['system', 'db']);
}
$this->columns = $columns;
$self->columns = $columns;
}
return $this->columns;
return $self->columns;
}

/**
Expand All @@ -227,8 +228,7 @@ public function getColumns()
*/
public static function filterColumns($data)
{
$self = static::getInstance();
return array_intersect_key($data, array_flip($self->getColumns()));
return array_intersect_key($data, array_flip(static::getColumns()));
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Grid/Data.php
Expand Up @@ -28,12 +28,11 @@ class Data extends \ArrayIterator
*
* @param integer $total
*
* @return self
* @return void
*/
public function setTotal(int $total)
{
$this->total = $total;
return $this;
}

/**
Expand Down
25 changes: 15 additions & 10 deletions src/Grid/Grid.php
Expand Up @@ -303,6 +303,7 @@ public function getController()
* - http://domain.com/pages/grid/#/page/2/order-created/desc/order-alias/asc/
*
* @return Grid
* @throws GridException
*/
public function processRequest()
{
Expand Down Expand Up @@ -378,6 +379,7 @@ public function processSource()
* Get data
*
* @return Data
* @throws \Bluz\Grid\GridException
*/
public function getData()
{
Expand Down Expand Up @@ -436,7 +438,7 @@ public function getParams(array $rewrite = [])
// change limit
$limit = $rewrite['limit'] ?? $this->getLimit();

if ($limit != $this->defaultLimit) {
if ($limit !== $this->defaultLimit) {
$params[$this->prefix . 'limit'] = $limit;
}

Expand All @@ -453,7 +455,7 @@ public function getParams(array $rewrite = [])

foreach ($filters as $column => $columnFilters) {
$column = $this->applyAlias($column);
if (count($columnFilters) == 1 && isset($columnFilters[self::FILTER_EQ])) {
if (count($columnFilters) === 1 && isset($columnFilters[self::FILTER_EQ])) {
$params[$this->prefix . 'filter-' . $column] = $columnFilters[self::FILTER_EQ];
continue;
}
Expand Down Expand Up @@ -545,7 +547,7 @@ protected function checkOrderColumn($column)
*/
protected function checkOrderName($order)
{
return ($order == Grid::ORDER_ASC || $order == Grid::ORDER_DESC);
return ($order === self::ORDER_ASC || $order === self::ORDER_DESC);
}

/**
Expand All @@ -557,7 +559,7 @@ protected function checkOrderName($order)
* @return void
* @throws GridException
*/
public function addOrder($column, $order = Grid::ORDER_ASC)
public function addOrder($column, $order = self::ORDER_ASC)
{
if (!$this->checkOrderColumn($column)) {
throw new GridException("Order for column `$column` is not allowed");
Expand All @@ -576,6 +578,7 @@ public function addOrder($column, $order = Grid::ORDER_ASC)
* @param array $orders
*
* @return void
* @throws GridException
*/
public function addOrders(array $orders)
{
Expand All @@ -591,6 +594,7 @@ public function addOrders(array $orders)
* @param string $order ASC or DESC
*
* @return void
* @throws GridException
*/
public function setOrder($column, $order = Grid::ORDER_ASC)
{
Expand All @@ -604,6 +608,7 @@ public function setOrder($column, $order = Grid::ORDER_ASC)
* @param array $orders
*
* @return void
* @throws GridException
*/
public function setOrders(array $orders)
{
Expand Down Expand Up @@ -678,8 +683,8 @@ public function getAllowFilters()
*/
protected function checkFilterColumn($column)
{
if (in_array($column, $this->getAllowFilters()) ||
array_key_exists($column, $this->getAllowFilters())
if (array_key_exists($column, $this->getAllowFilters()) ||
in_array($column, $this->getAllowFilters())
) {
return true;
}
Expand Down Expand Up @@ -799,7 +804,7 @@ public function setPage(int $page = 1)
if ($page < 1) {
throw new GridException('Wrong page number, should be greater than zero');
}
$this->page = (int)$page;
$this->page = $page;
}

/**
Expand All @@ -825,7 +830,7 @@ public function setLimit(int $limit)
if ($limit < 1) {
throw new GridException('Wrong limit value, should be greater than zero');
}
$this->limit = (int)$limit;
$this->limit = $limit;
}

/**
Expand Down Expand Up @@ -853,7 +858,7 @@ public function setDefaultLimit(int $limit)
}
$this->setLimit($limit);

$this->defaultLimit = (int)$limit;
$this->defaultLimit = $limit;
}

/**
Expand All @@ -875,7 +880,7 @@ public function getDefaultLimit(): int
* @return void
* @throws GridException
*/
public function setDefaultOrder($column, $order = Grid::ORDER_ASC)
public function setDefaultOrder($column, $order = self::ORDER_ASC)
{
$this->setOrder($column, $order);

Expand Down
2 changes: 1 addition & 1 deletion src/Grid/Helper/Reset.php
Expand Up @@ -20,5 +20,5 @@ function () {
/**
* @var Grid\Grid $this
*/
return $this->getUrl([]);
return $this->getUrl(['page' => 1, 'filters' => []]);
};
2 changes: 1 addition & 1 deletion src/Grid/Source/ArraySource.php
Expand Up @@ -31,7 +31,7 @@ class ArraySource extends AbstractSource
public function setSource($source)
{
if (!is_array($source) && !($source instanceof \ArrayAccess)) {
throw new Grid\GridException("Source of `ArraySource` should be array or implement ArrayAccess interface");
throw new Grid\GridException('Source of `ArraySource` should be array or implement ArrayAccess interface');
}

$this->source = $source;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Grid/Source/SqlSourceTest.php
Expand Up @@ -20,7 +20,7 @@
* @author Anton Shevchuk
* @created 07.08.14 14:37
*/
class GridTest extends FrameworkTestCase
class SqlSourceTest extends FrameworkTestCase
{
/**
* SQL Source
Expand Down

0 comments on commit 3e9a7d5

Please sign in to comment.