Skip to content

Commit ca5b43e

Browse files
committed
cleaning some code according PSR
1 parent 8f91b06 commit ca5b43e

File tree

2 files changed

+28
-95
lines changed

2 files changed

+28
-95
lines changed

src/JsonQueriable.php

Lines changed: 18 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ trait JsonQueriable
1212
* @var string
1313
*/
1414
protected $_node = '';
15+
1516
/**
1617
* contain prepared data for process
1718
* @var mixed
1819
*/
1920
protected $_map;
2021

21-
2222
/**
2323
* Stores base contents.
2424
*
@@ -33,7 +33,9 @@ trait JsonQueriable
3333
*/
3434
protected $_conditions = [];
3535

36-
36+
/**
37+
* @var bool
38+
*/
3739
protected $_isProcessed = false;
3840

3941
/**
@@ -139,8 +141,6 @@ protected function objectToArray($obj)
139141
return array_map([$this, 'objectToArray'], $obj);
140142
}
141143

142-
143-
144144
/**
145145
* check given value is multidimensional array
146146
*
@@ -252,7 +252,6 @@ protected function getData()
252252
return false;
253253
}
254254

255-
256255
/**
257256
* process AND and OR conditions
258257
*
@@ -284,7 +283,6 @@ protected function processConditions()
284283
return $result;
285284
}
286285

287-
288286
/**
289287
* make WHERE clause
290288
*
@@ -326,7 +324,6 @@ public function orWhere($key = null, $condition = null, $value = null)
326324
return $this->makeWhere($key, $condition, $value);
327325
}
328326

329-
330327
/**
331328
* generator for AND and OR where
332329
*
@@ -355,7 +352,6 @@ protected function makeWhere($key, $condition = null, $value = null)
355352
return $this;
356353
}
357354

358-
359355
/**
360356
* make WHERE IN clause
361357
*
@@ -370,7 +366,6 @@ public function whereIn($key = null, $value = [])
370366
return $this;
371367
}
372368

373-
374369
/**
375370
* make WHERE NOT IN clause
376371
*
@@ -384,7 +379,6 @@ public function whereNotIn($key = null, $value = [])
384379
return $this;
385380
}
386381

387-
388382
/**
389383
* make WHERE NULL clause
390384
*
@@ -480,8 +474,6 @@ public function macro($key, callable $fn)
480474
return $this;
481475
}
482476

483-
484-
485477
// condition methods
486478

487479
/**
@@ -493,10 +485,7 @@ public function macro($key, callable $fn)
493485
*/
494486
protected function condEqual($key, $val)
495487
{
496-
if ($key == $val) {
497-
return true;
498-
}
499-
return false;
488+
return $key == $val;
500489
}
501490

502491
/**
@@ -508,10 +497,7 @@ protected function condEqual($key, $val)
508497
*/
509498
protected function condExactEqual($key, $val)
510499
{
511-
if ($key === $val) {
512-
return true;
513-
}
514-
return false;
500+
return $key === $val;
515501
}
516502

517503
/**
@@ -523,10 +509,7 @@ protected function condExactEqual($key, $val)
523509
*/
524510
protected function condNotEqual($key, $val)
525511
{
526-
if ($key != $val) {
527-
return true;
528-
}
529-
return false;
512+
return $key != $val;
530513
}
531514

532515
/**
@@ -538,10 +521,7 @@ protected function condNotEqual($key, $val)
538521
*/
539522
protected function condNotExactEqual($key, $val)
540523
{
541-
if ($key !== $val) {
542-
return true;
543-
}
544-
return false;
524+
return $key !== $val;
545525
}
546526

547527
/**
@@ -553,10 +533,7 @@ protected function condNotExactEqual($key, $val)
553533
*/
554534
protected function condGreater($key, $val)
555535
{
556-
if ($key > $val) {
557-
return true;
558-
}
559-
return false;
536+
return $key > $val;
560537
}
561538

562539
/**
@@ -568,10 +545,7 @@ protected function condGreater($key, $val)
568545
*/
569546
protected function condLess($key, $val)
570547
{
571-
if ($key < $val) {
572-
return true;
573-
}
574-
return false;
548+
return $key < $val;
575549
}
576550

577551
/**
@@ -583,10 +557,7 @@ protected function condLess($key, $val)
583557
*/
584558
protected function condGreaterEqual($key, $val)
585559
{
586-
if ($key >= $val) {
587-
return true;
588-
}
589-
return false;
560+
return $key >= $val;
590561
}
591562

592563
/**
@@ -598,10 +569,7 @@ protected function condGreaterEqual($key, $val)
598569
*/
599570
protected function condLessEqual($key, $val)
600571
{
601-
if ($key <= $val) {
602-
return true;
603-
}
604-
return false;
572+
return $key <= $val;
605573
}
606574

607575
/**
@@ -613,12 +581,7 @@ protected function condLessEqual($key, $val)
613581
*/
614582
protected function condIn($key, $val)
615583
{
616-
if (is_array($val)) {
617-
if (in_array($key, $val)) {
618-
return true;
619-
}
620-
}
621-
return false;
584+
return (is_array($val) && in_array($key, $val));
622585
}
623586

624587
/**
@@ -630,12 +593,7 @@ protected function condIn($key, $val)
630593
*/
631594
protected function condNotIn($key, $val)
632595
{
633-
if (is_array($val)) {
634-
if (!in_array($key, $val)) {
635-
return true;
636-
}
637-
}
638-
return false;
596+
return (is_array($val) && !in_array($key, $val));
639597
}
640598

641599
/**
@@ -647,10 +605,7 @@ protected function condNotIn($key, $val)
647605
*/
648606
protected function condNull($key, $val)
649607
{
650-
if (is_null($key) || $key == $val) {
651-
return true;
652-
}
653-
return false;
608+
return (is_null($key) || $key == $val);
654609
}
655610

656611
/**
@@ -662,10 +617,7 @@ protected function condNull($key, $val)
662617
*/
663618
protected function condNotNull($key, $val)
664619
{
665-
if (!is_null($key) && $key !== $val) {
666-
return true;
667-
}
668-
return false;
620+
return (!is_null($key) && $key !== $val);
669621
}
670622

671623
/**
@@ -677,8 +629,7 @@ protected function condNotNull($key, $val)
677629
*/
678630
protected function condStartsWith($key, $val)
679631
{
680-
$pattern = '/^'.$val.'/';
681-
if (preg_match($pattern, $key)) {
632+
if (preg_match("/^$val/", $key)) {
682633
return true;
683634
}
684635

@@ -714,11 +665,7 @@ protected function condMatch($key, $val)
714665
*/
715666
protected function condContains($key, $val)
716667
{
717-
if (strpos($key, $val) !== false) {
718-
return true;
719-
}
720-
721-
return false;
668+
return (strpos($key, $val) !== false);
722669
}
723670

724671
/**

src/Jsonq.php

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ class Jsonq
1111
{
1212
use JsonQueriable;
1313

14-
15-
1614
/**
17-
* Jthis constructor set main json file path
15+
* this constructor set main json file path
1816
* otherwise create it and read file contents
1917
* and decode as an array and store it in $this->_data
2018
*
@@ -107,7 +105,6 @@ public function get($object = true)
107105
return $this->prepareResult($this->_map, $object);
108106
}
109107

110-
111108
/**
112109
* alias of get method
113110
*
@@ -120,8 +117,6 @@ public function fetch($object = true)
120117
return $this->get($object);
121118
}
122119

123-
124-
125120
/**
126121
* check data exists in system
127122
*
@@ -132,15 +127,9 @@ public function exists()
132127
{
133128
$this->prepare();
134129

135-
if (!empty($this->_map) && !is_null($this->_map)) {
136-
return true;
137-
}
138-
139-
return false;
130+
return (!empty($this->_map) && !is_null($this->_map));
140131
}
141132

142-
143-
144133
/**
145134
* reset given data to the $_map
146135
*
@@ -158,7 +147,6 @@ public function reset($data = null)
158147
return $this;
159148
}
160149

161-
162150
/**
163151
* getting group data from specific column
164152
*
@@ -171,14 +159,14 @@ public function groupBy($column)
171159
{
172160
$this->prepare();
173161

174-
$new_data = [];
162+
$data = [];
175163
foreach ($this->_map as $map) {
176164
if (isset($map[$column])) {
177-
$new_data[$map[$column]][] = $map;
165+
$data[$map[$column]][] = $map;
178166
}
179167
}
180168

181-
$this->_map = $new_data;
169+
$this->_map = $data;
182170
return $this;
183171
}
184172

@@ -485,7 +473,6 @@ public function pipe(callable $fn, $class = null)
485473
return $this;
486474
}
487475

488-
489476
/**
490477
* filtered each element of prepared data
491478
*
@@ -498,18 +485,18 @@ public function filter(callable $fn, $key = false)
498485
{
499486
$this->prepare();
500487

501-
$new_data = [];
488+
$data = [];
502489
foreach ($this->_map as $k => $val) {
503490
if ($fn($val)) {
504491
if ($key) {
505-
$new_data[$k] = $val;
492+
$data[$k] = $val;
506493
} else {
507-
$new_data[] = $val;
494+
$data[] = $val;
508495
}
509496
}
510497
}
511498

512-
return $new_data;
499+
return $data;
513500
}
514501

515502
/**
@@ -560,7 +547,6 @@ public function collect($data)
560547
return $this;
561548
}
562549

563-
564550
/**
565551
* implode resulting data from desire key and delimeter
566552
*
@@ -682,7 +668,7 @@ public function chunk($amount, callable $fn = null)
682668
$chunks[] = $return;
683669
}
684670
}
685-
return count($chunks)>0?$chunks:null;
671+
return count($chunks) > 0 ? $chunks : null;
686672
}
687673

688674
return $chunk_value;

0 commit comments

Comments
 (0)