Conditions | 12 |
Paths | 126 |
Total Lines | 63 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
21 | public static function activity($description = null) |
||
22 | { |
||
23 | $userType = trans('LaravelLogger::laravel-logger.userTypes.guest'); |
||
|
|||
24 | $userId = null; |
||
25 | |||
26 | if (Auth::check()) { |
||
27 | $userType = trans('LaravelLogger::laravel-logger.userTypes.registered'); |
||
28 | $userIdField = config('LaravelLogger.defaultUserIDField'); |
||
29 | $userId = Request::user()->{$userIdField}; |
||
30 | } |
||
31 | |||
32 | if (Crawler::isCrawler()) { |
||
33 | $userType = trans('LaravelLogger::laravel-logger.userTypes.crawler'); |
||
34 | if (is_null($description)) { |
||
35 | $description = $userType.' '.trans('LaravelLogger::laravel-logger.verbTypes.crawled').' '.Request::fullUrl(); |
||
36 | } |
||
37 | } |
||
38 | |||
39 | if (!$description) { |
||
40 | switch (strtolower(Request::method())) { |
||
41 | case 'post': |
||
42 | $verb = trans('LaravelLogger::laravel-logger.verbTypes.created'); |
||
43 | break; |
||
44 | |||
45 | case 'patch': |
||
46 | case 'put': |
||
47 | $verb = trans('LaravelLogger::laravel-logger.verbTypes.edited'); |
||
48 | break; |
||
49 | |||
50 | case 'delete': |
||
51 | $verb = trans('LaravelLogger::laravel-logger.verbTypes.deleted'); |
||
52 | break; |
||
53 | |||
54 | case 'get': |
||
55 | default: |
||
56 | $verb = trans('LaravelLogger::laravel-logger.verbTypes.viewed'); |
||
57 | break; |
||
58 | } |
||
59 | |||
60 | $description = $verb.' '.Request::path(); |
||
61 | } |
||
62 | |||
63 | $data = [ |
||
64 | 'description' => $description, |
||
65 | 'userType' => $userType, |
||
66 | 'userId' => $userId, |
||
67 | 'route' => Request::fullUrl(), |
||
68 | 'ipAddress' => Request::ip(), |
||
69 | 'userAgent' => Request::header('user-agent'), |
||
70 | 'locale' => Request::header('accept-language'), |
||
71 | 'referer' => Request::header('referer'), |
||
72 | 'methodType' => Request::method(), |
||
73 | ]; |
||
74 | |||
75 | // Validation Instance |
||
76 | $validator = Validator::make($data, Activity::rules()); |
||
77 | if ($validator->fails()) { |
||
78 | $errors = self::prepareErrorMessage($validator->errors(), $data); |
||
79 | if (config('LaravelLogger.logDBActivityLogFailuresToFile')) { |
||
80 | Log::error('Failed to record activity event. Failed Validation: '.$errors); |
||
81 | } |
||
82 | } else { |
||
83 | self::storeActivity($data); |
||
84 | } |
||
127 |