GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DataViewer   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 45
dl 0
loc 73
c 0
b 0
f 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A checkTenant() 0 2 1
A scopeTenantFilter() 0 7 1
A orderableColumns() 0 2 1
A scopeAdvancedFilter() 0 7 1
A allowedOperators() 0 18 1
A whiteListColumns() 0 2 1
A process() 0 21 2
1
<?php
2
3
namespace Raystech\StarterKit\Traits;
4
5
use Illuminate\Validation\ValidationException;
6
7
use Raystech\StarterKit\Supports\CustomQueryBuilder;
8
9
trait DataViewer
10
{
11
  public function scopeTenantFilter($query) {
12
    $tenant_id = session()->get('_tenant', 1);
13
14
    return $query->whereHas('tenant', function($sub_query) use ($tenant_id) {
15
      $this->checkTenant($tenant_id, $sub_query);
16
      // $sub_query->where('tenant_id', 1);
17
    })->get();
18
  }
19
20
  public function checkTenant($tenant_id, $query) {
21
    return $query->where('tenant_id', $tenant_id);
22
  }
23
24
  public function scopeAdvancedFilter($query) {
25
    return $this->process($query, request()->all())
26
      ->orderBy(
27
        request('order_column', 'created_at'),
28
        request('order_direction', 'desc')
29
      )
30
      ->paginate(request('limit', 16));
31
  }
32
33
  public function process($query, $data) {
34
35
    $v = validator()->make($data, [
36
      'order_column'    => 'sometimes|required|in:'.$this->orderableColumns(),
37
      'order_direction' => 'sometimes|required|in:asc,desc',
38
      'limit'           => 'sometimes|required|integer|min:1',
39
40
      'filter_match'    => 'sometimes|required|in:and,or',
41
      'f'               => 'sometimes|required|array',
42
      'f.*.column'      => 'required|in:'.$this->whiteListColumns(),
43
      'f.*.operator'    => 'required_with:f.*.column|in:'.$this->allowedOperators(),
44
      'f.*.query_1'     => 'required',
45
      'f.*.query_2'     => 'required_if:f.*.operator,between,not_between'
46
    ]);
47
48
    if($v->fails()) {
49
      return dd($v->messages()->all());
0 ignored issues
show
Bug introduced by
Are you sure the usage of dd($v->messages()->all()) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
50
      throw new ValidationException;      
0 ignored issues
show
Unused Code introduced by
ThrowNode is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
51
    }
52
    $data['allowedFilters'] = $this->allowedFilters;
53
    return (new CustomQueryBuilder)->apply($query, $data);
54
  }
55
56
  protected function whiteListColumns() {
57
    return implode(',', $this->allowedFilters);
58
  }
59
60
  protected function orderableColumns() {
61
    return implode(',', $this->orderable);
62
  }
63
64
  protected function allowedOperators() {
65
    return implode(',', [
66
      'equal_to',
67
      'not_equal_to',
68
      'less_than',
69
      'greater_than',
70
      'between',
71
      'not_between',
72
      'contains',
73
      'starts_with',
74
      'ends_with',
75
      'in_the_past',
76
      'in_the_next',
77
      'in_the_period',
78
      'less_than_count',
79
      'greater_than_count',
80
      'equal_to_count',
81
      'not_equal_to_count'
82
    ]);
83
  }
84
}