Conditions | 12 |
Paths | 20 |
Total Lines | 80 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
63 | public function availableState($content_type,$content_id) |
||
64 | { |
||
65 | |||
66 | $workflow = WorkflowType::where('content_type', $content_type)->first(); |
||
67 | |||
68 | if(!$workflow){ |
||
69 | return response()->json([ |
||
70 | 'status' => false |
||
71 | ]); |
||
72 | } |
||
73 | |||
74 | $history = $this->historyModel->where('workflow_id',$workflow->workflow_id)->where('content_id',$content_id)->orderBy('created_at','desc')->first(); |
||
75 | |||
76 | |||
77 | if(!$history){ |
||
78 | return response()->json([ |
||
79 | 'status' => false |
||
80 | ]); |
||
81 | } |
||
82 | |||
83 | |||
84 | |||
85 | |||
86 | $check_history = $this->historyModel->where('workflow_id',$workflow->workflow_id)->where('content_id',$content_id)->count(); |
||
87 | |||
88 | |||
89 | $transition_state = TransitionState::where('history_id',$history->id)->orderBy('created_at','desc')->first(); |
||
90 | |||
91 | $transitions = Transition::where('from',$transition_state->current_state)->get(); |
||
92 | |||
93 | $states = State::where('workflow_id',$history->workflow_id)->get(); |
||
94 | |||
95 | $current_state = State::find($transition_state->current_state); |
||
96 | |||
97 | $state_response = []; |
||
98 | |||
99 | foreach($transitions as $transition) |
||
100 | { |
||
101 | |||
102 | foreach($states as $state) |
||
103 | { |
||
104 | if($state->id == $transition->to && $state->id != $transition_state->current_state){ |
||
105 | if(!empty($transition->vueGuard->permission_id)){ |
||
106 | $permission = \App\Permission::find($transition->vueGuard->permission_id); |
||
107 | if( (\Auth::user()->hasPermission($permission->name)) ){ |
||
108 | |||
109 | array_push($state_response,$state); |
||
110 | } |
||
111 | array_set($state,'permission',$transition->vueGuard->permission_id); |
||
112 | |||
113 | }else{ |
||
114 | array_set($state,'permission',0); |
||
115 | } |
||
116 | } |
||
117 | } |
||
118 | } |
||
119 | if($check_history == 1){ |
||
120 | return response()->json([ |
||
121 | 'status' => true, |
||
122 | 'state' => $state_response, |
||
123 | 'transition_state' => $transition_state, |
||
124 | 'current_state' => $current_state, |
||
125 | 'current_history' => $history, |
||
126 | 'user' => '-' |
||
127 | ]); |
||
128 | }elseif($check_history > 1){ |
||
129 | return response()->json([ |
||
130 | 'status' => true, |
||
131 | 'state' => $state_response, |
||
132 | 'transition_state' => $transition_state, |
||
133 | 'current_state' => $current_state, |
||
134 | 'current_history' => $history, |
||
135 | 'user' => (empty($history->user)) ? '-' : $history->user->name |
||
136 | ]); |
||
137 | } |
||
138 | return response()->json([ |
||
139 | 'status' => false, |
||
140 | ]); |
||
141 | |||
142 | } |
||
143 | |||
251 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.