Skip to content

Commit 1bd7cbb

Browse files
authored
Merge pull request #10 from GitHubHubus/psr_style
Cleaning some code according to PSR and removing excess code for simplify perception
2 parents 896215e + ca5b43e commit 1bd7cbb

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
*
@@ -254,7 +254,6 @@ protected function getData()
254254
return false;
255255
}
256256

257-
258257
/**
259258
* process AND and OR conditions
260259
*
@@ -286,7 +285,6 @@ protected function processConditions()
286285
return $result;
287286
}
288287

289-
290288
/**
291289
* make WHERE clause
292290
*
@@ -328,7 +326,6 @@ public function orWhere($key = null, $condition = null, $value = null)
328326
return $this->makeWhere($key, $condition, $value);
329327
}
330328

331-
332329
/**
333330
* generator for AND and OR where
334331
*
@@ -357,7 +354,6 @@ protected function makeWhere($key, $condition = null, $value = null)
357354
return $this;
358355
}
359356

360-
361357
/**
362358
* make WHERE IN clause
363359
*
@@ -372,7 +368,6 @@ public function whereIn($key = null, $value = [])
372368
return $this;
373369
}
374370

375-
376371
/**
377372
* make WHERE NOT IN clause
378373
*
@@ -386,7 +381,6 @@ public function whereNotIn($key = null, $value = [])
386381
return $this;
387382
}
388383

389-
390384
/**
391385
* make WHERE NULL clause
392386
*
@@ -482,8 +476,6 @@ public function macro($key, callable $fn)
482476
return $this;
483477
}
484478

485-
486-
487479
// condition methods
488480

489481
/**
@@ -495,10 +487,7 @@ public function macro($key, callable $fn)
495487
*/
496488
protected function condEqual($key, $val)
497489
{
498-
if ($key == $val) {
499-
return true;
500-
}
501-
return false;
490+
return $key == $val;
502491
}
503492

504493
/**
@@ -510,10 +499,7 @@ protected function condEqual($key, $val)
510499
*/
511500
protected function condExactEqual($key, $val)
512501
{
513-
if ($key === $val) {
514-
return true;
515-
}
516-
return false;
502+
return $key === $val;
517503
}
518504

519505
/**
@@ -525,10 +511,7 @@ protected function condExactEqual($key, $val)
525511
*/
526512
protected function condNotEqual($key, $val)
527513
{
528-
if ($key != $val) {
529-
return true;
530-
}
531-
return false;
514+
return $key != $val;
532515
}
533516

534517
/**
@@ -540,10 +523,7 @@ protected function condNotEqual($key, $val)
540523
*/
541524
protected function condNotExactEqual($key, $val)
542525
{
543-
if ($key !== $val) {
544-
return true;
545-
}
546-
return false;
526+
return $key !== $val;
547527
}
548528

549529
/**
@@ -555,10 +535,7 @@ protected function condNotExactEqual($key, $val)
555535
*/
556536
protected function condGreater($key, $val)
557537
{
558-
if ($key > $val) {
559-
return true;
560-
}
561-
return false;
538+
return $key > $val;
562539
}
563540

564541
/**
@@ -570,10 +547,7 @@ protected function condGreater($key, $val)
570547
*/
571548
protected function condLess($key, $val)
572549
{
573-
if ($key < $val) {
574-
return true;
575-
}
576-
return false;
550+
return $key < $val;
577551
}
578552

579553
/**
@@ -585,10 +559,7 @@ protected function condLess($key, $val)
585559
*/
586560
protected function condGreaterEqual($key, $val)
587561
{
588-
if ($key >= $val) {
589-
return true;
590-
}
591-
return false;
562+
return $key >= $val;
592563
}
593564

594565
/**
@@ -600,10 +571,7 @@ protected function condGreaterEqual($key, $val)
600571
*/
601572
protected function condLessEqual($key, $val)
602573
{
603-
if ($key <= $val) {
604-
return true;
605-
}
606-
return false;
574+
return $key <= $val;
607575
}
608576

609577
/**
@@ -615,12 +583,7 @@ protected function condLessEqual($key, $val)
615583
*/
616584
protected function condIn($key, $val)
617585
{
618-
if (is_array($val)) {
619-
if (in_array($key, $val)) {
620-
return true;
621-
}
622-
}
623-
return false;
586+
return (is_array($val) && in_array($key, $val));
624587
}
625588

626589
/**
@@ -632,12 +595,7 @@ protected function condIn($key, $val)
632595
*/
633596
protected function condNotIn($key, $val)
634597
{
635-
if (is_array($val)) {
636-
if (!in_array($key, $val)) {
637-
return true;
638-
}
639-
}
640-
return false;
598+
return (is_array($val) && !in_array($key, $val));
641599
}
642600

643601
/**
@@ -649,10 +607,7 @@ protected function condNotIn($key, $val)
649607
*/
650608
protected function condNull($key, $val)
651609
{
652-
if (is_null($key) || $key == $val) {
653-
return true;
654-
}
655-
return false;
610+
return (is_null($key) || $key == $val);
656611
}
657612

658613
/**
@@ -664,10 +619,7 @@ protected function condNull($key, $val)
664619
*/
665620
protected function condNotNull($key, $val)
666621
{
667-
if (!is_null($key) && $key !== $val) {
668-
return true;
669-
}
670-
return false;
622+
return (!is_null($key) && $key !== $val);
671623
}
672624

673625
/**
@@ -679,8 +631,7 @@ protected function condNotNull($key, $val)
679631
*/
680632
protected function condStartsWith($key, $val)
681633
{
682-
$pattern = '/^'.$val.'/';
683-
if (preg_match($pattern, $key)) {
634+
if (preg_match("/^$val/", $key)) {
684635
return true;
685636
}
686637

@@ -716,11 +667,7 @@ protected function condMatch($key, $val)
716667
*/
717668
protected function condContains($key, $val)
718669
{
719-
if (strpos($key, $val) !== false) {
720-
return true;
721-
}
722-
723-
return false;
670+
return (strpos($key, $val) !== false);
724671
}
725672

726673
/**

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
*
@@ -106,7 +104,6 @@ public function get($object = true)
106104
return $this->prepareResult($this->_map, $object);
107105
}
108106

109-
110107
/**
111108
* alias of get method
112109
*
@@ -119,8 +116,6 @@ public function fetch($object = true)
119116
return $this->get($object);
120117
}
121118

122-
123-
124119
/**
125120
* check data exists in system
126121
*
@@ -131,15 +126,9 @@ public function exists()
131126
{
132127
$this->prepare();
133128

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

141-
142-
143132
/**
144133
* reset given data to the $_map
145134
*
@@ -157,7 +146,6 @@ public function reset($data = null)
157146
return $this;
158147
}
159148

160-
161149
/**
162150
* getting group data from specific column
163151
*
@@ -170,14 +158,14 @@ public function groupBy($column)
170158
{
171159
$this->prepare();
172160

173-
$new_data = [];
161+
$data = [];
174162
foreach ($this->_map as $map) {
175163
if (isset($map[$column])) {
176-
$new_data[$map[$column]][] = $map;
164+
$data[$map[$column]][] = $map;
177165
}
178166
}
179167

180-
$this->_map = $new_data;
168+
$this->_map = $data;
181169
return $this;
182170
}
183171

@@ -484,7 +472,6 @@ public function pipe(callable $fn, $class = null)
484472
return $this;
485473
}
486474

487-
488475
/**
489476
* filtered each element of prepared data
490477
*
@@ -497,18 +484,18 @@ public function filter(callable $fn, $key = false)
497484
{
498485
$this->prepare();
499486

500-
$new_data = [];
487+
$data = [];
501488
foreach ($this->_map as $k => $val) {
502489
if ($fn($val)) {
503490
if ($key) {
504-
$new_data[$k] = $val;
491+
$data[$k] = $val;
505492
} else {
506-
$new_data[] = $val;
493+
$data[] = $val;
507494
}
508495
}
509496
}
510497

511-
return $new_data;
498+
return $data;
512499
}
513500

514501
/**
@@ -559,7 +546,6 @@ public function collect($data)
559546
return $this;
560547
}
561548

562-
563549
/**
564550
* implode resulting data from desire key and delimeter
565551
*
@@ -681,7 +667,7 @@ public function chunk($amount, callable $fn = null)
681667
$chunks[] = $return;
682668
}
683669
}
684-
return count($chunks)>0?$chunks:null;
670+
return count($chunks) > 0 ? $chunks : null;
685671
}
686672

687673
return $chunk_value;

0 commit comments

Comments
 (0)