| Code Coverage
| Classes and Traits | Functions and Methods | Lines
Total | 0.00% covered (danger) | 0.00% | 0 / 1 | 33.33% covered (danger) | 33.33% | 1 / 3 | CRAP | 36.36% covered (danger) | 36.36% | 8 / 22
Controller | 0.00% covered (danger) | 0.00% | 0 / 1 | 33.33% covered (danger) | 33.33% | 1 / 3 | 8.12 | 36.36% covered (danger) | 36.36% | 8 / 22
log | 100.00% covered (success) | 100.00% | 1 / 1 | 1 | 100.00% covered (success) | 100.00% | 8 / 8
apiError | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 2
preparativeUser | 0.00% covered (danger) | 0.00% | 0 / 1 | 6.00 | 0.00% covered (danger) | 0.00% | 0 / 12

1 | <?php
2 |
3 | namespace App\Http\Controllers;
4 |
5 | use App\Log;
6 | use App\User;
7 | use Illuminate\Foundation\Bus\DispatchesJobs;
8 | use Illuminate\Routing\Controller as BaseController;
9 | use Illuminate\Foundation\Validation\ValidatesRequests;
10 | use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
11 | use Illuminate\Support\Facades\Auth;
12 | use Illuminate\Support\Facades\Request;
13 | use Illuminate\Support\Str;
14 | use Zttp\Zttp;
15 |
16 | class Controller extends BaseController
17 | {
18 | use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
19 | public function log($method,$type,$description,$id_user=null){
20 | (new Log([
21 | 'operation'=>$method,
22 | 'type'=>$type,
23 | 'description'=>$description,
24 | 'id_user'=>$id_user,
25 | 'ip'=>Request::ip()
26 | ]))->save();
27 | }
28 | public function apiError($method,$description){
29 | $this->log($method,'apiError',$description);
30 | return ['success'=>'false','fail_info'=>$description];
31 | }
32 |
33 | /**
34 | * @return User
35 | */
36 | public function preparativeUser(){
37 | $name='_preparativeUser_';
38 | $user=User::where('name',$name)->first();
39 | if(!$user){
40 | $user = new User([
41 | 'name' => $name,
42 | 'email' => $name.'@'.$name.'.com',
43 | 'email_verified_at' => now(),
44 | 'password' => '$2y$10$vvcID/Akq2KjOZwRUUgBJOpVyGi.nTDT8Yb7gxiy5Xj9/5GnpzBMi', // password
45 | 'api_token' => md5($name),
46 | 'remember_token' => Str::random(10),
47 | ]);
48 | $user->save();
49 | }
50 | return $user;
51 | }
52 | }