Skip to content

Rename variable #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/JsonQueriable.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait JsonQueriable
* contain prepared data for process
* @var mixed
*/
protected $_map;
protected $_data;

/**
* contains column names
Expand Down Expand Up @@ -100,8 +100,8 @@ public function import($file = null)
{
if (!is_null($file)) {
if (is_string($file) && file_exists($file)) {
$this->_map = $this->getDataFromFile($file);
$this->_baseContents = $this->_map;
$this->_data = $this->getDataFromFile($file);
$this->_baseContents = $this->_data;
return true;
}
}
Expand All @@ -123,7 +123,7 @@ protected function prepare()

if (count($this->_conditions) > 0) {
$calculatedData = $this->processConditions();
$this->_map = $this->objectToArray($calculatedData);
$this->_data = $this->objectToArray($calculatedData);

$this->_conditions = [];
$this->_node = '';
Expand All @@ -132,7 +132,7 @@ protected function prepare()
}

$this->_isProcessed = true;
$this->_map = $this->objectToArray($this->getData());
$this->_data = $this->objectToArray($this->getData());
return $this;
}

Expand Down Expand Up @@ -356,7 +356,7 @@ protected function getFromNested($map, $node)
*/
protected function getData()
{
return $this->getFromNested($this->_map, $this->_node);
return $this->getFromNested($this->_data, $this->_node);
}

/**
Expand Down
78 changes: 39 additions & 39 deletions src/Jsonq.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function get($object = false)
{
$this->prepare();

return $this->prepareResult($this->_map, $object);
return $this->prepareResult($this->_data, $object);
}

/**
Expand All @@ -144,11 +144,11 @@ public function exists()
{
$this->prepare();

return (!empty($this->_map) && !is_null($this->_map));
return (!empty($this->_data) && !is_null($this->_data));
}

/**
* reset given data to the $_map
* reset given data to the $_data
*
* @param mixed $data
* @param bool $instance
Expand All @@ -167,7 +167,7 @@ public function reset($data = null, $instance = false)
return $self;
}

$this->_map = $this->_baseContents;
$this->_data = $this->_baseContents;
$this->reProcess();

return $this;
Expand All @@ -185,14 +185,14 @@ public function groupBy($column)
$this->prepare();

$data = [];
foreach ($this->_map as $map) {
foreach ($this->_data as $map) {
$value = $this->getFromNested($map, $column);
if ($value) {
$data[$value][] = $map;
}
}

$this->_map = $data;
$this->_data = $data;
return $this;
}

Expand All @@ -202,7 +202,7 @@ public function countGroupBy($column)
$this->prepare();

$data = [];
foreach ($this->_map as $map) {
foreach ($this->_data as $map) {
$value = $this->getFromNested($map, $column);
if (!$value) {
continue;
Expand All @@ -215,7 +215,7 @@ public function countGroupBy($column)
}
}

$this->_map = $data;
$this->_data = $data;
return $this;
}

Expand All @@ -229,7 +229,7 @@ public function count()
{
$this->prepare();

return count($this->_map);
return count($this->_data);
}

/**
Expand All @@ -255,9 +255,9 @@ public function sum($column = null)

$sum = 0;
if (is_null($column)) {
$sum = array_sum($this->_map);
$sum = array_sum($this->_data);
} else {
foreach ($this->_map as $key => $val) {
foreach ($this->_data as $key => $val) {
$value = $this->getFromNested($val, $column);
if (is_scalar($value)) {
$sum += $value;
Expand All @@ -281,9 +281,9 @@ public function max($column = null)
$this->prepare();

if (is_null($column)) {
$max = max($this->_map);
$max = max($this->_data);
} else {
$max = max(array_column($this->_map, $column));
$max = max(array_column($this->_data, $column));
}

return $max;
Expand All @@ -301,9 +301,9 @@ public function min($column = null)
$this->prepare();

if (is_null($column)) {
$min = min($this->_map);
$min = min($this->_data);
} else {
$min = min(array_column($this->_map, $column));
$min = min(array_column($this->_data, $column));
}

return $min;
Expand Down Expand Up @@ -337,7 +337,7 @@ public function first($object = false)
{
$this->prepare();

$data = $this->_map;
$data = $this->_data;
if (count($data) > 0) {
return $this->prepareResult(reset($data), $object);
}
Expand All @@ -356,7 +356,7 @@ public function last($object = false)
{
$this->prepare();

$data = $this->_map;
$data = $this->_data;
if (count($data) > 0) {
return $this->prepareResult(end($data), $object);
}
Expand All @@ -376,11 +376,11 @@ public function nth($index, $object = false)
{
$this->prepare();

$data = $this->_map;
$data = $this->_data;
$total_elm = count($data);
$idx = abs($index);

if (!is_integer($index) || $total_elm < $idx || $index == 0 || !is_array($this->_map)) {
if (!is_integer($index) || $total_elm < $idx || $index == 0 || !is_array($this->_data)) {
return null;
}

Expand All @@ -405,11 +405,11 @@ public function sortBy($column, $order = 'asc')
{
$this->prepare();

if (!is_array($this->_map)) {
if (!is_array($this->_data)) {
return $this;
}

usort($this->_map, function ($a, $b) use ($column, $order) {
usort($this->_data, function ($a, $b) use ($column, $order) {
$val1 = $this->getFromNested($a, $column);
$val2 = $this->getFromNested($b, $column);
if (is_string($val1)) {
Expand Down Expand Up @@ -447,11 +447,11 @@ public function sortByCallable(callable $sortFunc)
{
$this->prepare();

if (!is_array($this->_map)) {
if (!is_array($this->_data)) {
return $this;
}

usort($this->_map, $sortFunc);
usort($this->_data, $sortFunc);

return $this;
}
Expand All @@ -465,9 +465,9 @@ public function sortByCallable(callable $sortFunc)
public function sort($order = 'asc')
{
if ($order == 'desc') {
rsort($this->_map);
rsort($this->_data);
}else{
sort($this->_map);
sort($this->_data);
}

return $this;
Expand Down Expand Up @@ -497,7 +497,7 @@ public function each(callable $fn)
{
$this->prepare();

foreach ($this->_map as $key => $val) {
foreach ($this->_data as $key => $val) {
$fn($key, $val);
}
}
Expand All @@ -514,7 +514,7 @@ public function transform(callable $fn)
$this->prepare();

$new_data = [];
foreach ($this->_map as $key => $val) {
foreach ($this->_data as $key => $val) {
$new_data[$key] = $fn($val);
}

Expand All @@ -536,11 +536,11 @@ public function pipe(callable $fn, $class = null)
if (is_string($fn) && !is_null($class)) {
$instance = new $class;

$this->_map = call_user_func_array([$instance, $fn], [$this]);
$this->_data = call_user_func_array([$instance, $fn], [$this]);
return $this;
}

$this->_map = $fn($this);
$this->_data = $fn($this);
return $this;
}

Expand All @@ -557,7 +557,7 @@ public function filter(callable $fn, $key = false)
$this->prepare();

$data = [];
foreach ($this->_map as $k => $val) {
foreach ($this->_data as $k => $val) {
if ($fn($val)) {
if ($key) {
$data[$k] = $val;
Expand All @@ -580,7 +580,7 @@ public function filter(callable $fn, $key = false)
*/
public function then($node)
{
$this->_map = $this->prepare()->first(false);
$this->_data = $this->prepare()->first(false);

$this->from($node);

Expand Down Expand Up @@ -612,8 +612,8 @@ public function json($data)
*/
public function collect($data)
{
$this->_map = $this->objectToArray($data);
$this->_baseContents = &$this->_map;
$this->_data = $this->objectToArray($data);
$this->_baseContents = &$this->_data;

return $this;
}
Expand Down Expand Up @@ -655,7 +655,7 @@ public function implode($key, $delimiter = ',')
*/
protected function makeImplode($key, $delimiter)
{
$data = array_column($this->_map, $key);
$data = array_column($this->_data, $key);

if (is_array($data)) {
return implode($delimiter, $data);
Expand All @@ -675,7 +675,7 @@ public function column($column)
{
$this->prepare();

return array_column($this->_map, $column);
return array_column($this->_data, $column);
}

/**
Expand All @@ -688,7 +688,7 @@ public function toJson()
{
$this->prepare();

return json_encode($this->_map);
return json_encode($this->_data);
}

/**
Expand All @@ -701,7 +701,7 @@ public function keys()
{
$this->prepare();

return array_keys($this->_map);
return array_keys($this->_data);
}

/**
Expand All @@ -714,7 +714,7 @@ public function values()
{
$this->prepare();

return array_values($this->_map);
return array_values($this->_data);
}

/**
Expand All @@ -729,7 +729,7 @@ public function chunk($amount, callable $fn = null)
{
$this->prepare();

$chunk_value = array_chunk($this->_map, $amount);
$chunk_value = array_chunk($this->_data, $amount);
$chunks = [];

if (!is_null($fn) && is_callable($fn)) {
Expand Down