Conditions | 10 |
Paths | 13 |
Total Lines | 49 |
Code Lines | 34 |
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 |
||
47 | public function checkNewUpdate() |
||
48 | { |
||
49 | $notify = new BarNotification(); |
||
50 | if (!\Schema::hasTable('bar_notifications')) { |
||
51 | $url = url('database-upgrade'); |
||
52 | //$string = "Your Database is outdated please upgrade <a href=$url>Now !</a>"; |
||
53 | echo view('themes.default1.update.database', compact('url')); |
||
54 | exit; |
||
55 | } |
||
56 | $not = $notify->get(); |
||
57 | if ($not->count() > 0) { |
||
58 | $now = \Carbon\Carbon::now(); |
||
59 | $yesterday = \Carbon\Carbon::yesterday(); |
||
60 | $notifications = $notify->whereBetween('created_at', [$yesterday, $now])->lists('value', 'key'); |
||
61 | $todelete = $notify->where('created_at', '<', $yesterday)->get(); |
||
62 | if ($todelete->count() > 0) { |
||
63 | foreach ($todelete as $delete) { |
||
64 | $delete->delete(); |
||
65 | } |
||
66 | } |
||
67 | if (count($notifications) > 0) { |
||
68 | if (!array_key_exists('new-version', $notifications)) { |
||
69 | $check_version = $this->checkNewVersion(); |
||
70 | if ($check_version == true) { |
||
71 | $notify->create(['key' => 'new-version', 'value' => 'new version found please click <a href='.url('file-update').'><b>here to download</b></a>']); |
||
72 | } |
||
73 | } else { |
||
74 | $n = $notify->where('key', 'new-version')->first(); |
||
75 | $last = $n->created_at; |
||
76 | $now = \Carbon\Carbon::now(); |
||
77 | $difference = $now->diffInHours($last); |
||
78 | if ($difference >= 24) { |
||
79 | $n->delete(); |
||
80 | $this->checkNewUpdate(); |
||
81 | } |
||
82 | } |
||
83 | } |
||
84 | } else { |
||
85 | $check_version = $this->checkNewVersion(); |
||
86 | |||
87 | if ($check_version == true) { |
||
88 | //dd('if'); |
||
89 | $notify->create(['key' => 'new-version', 'value' => 'new version found please click <a href='.url('file-update').'><b>here to download</b></a>', 'created_at' => \Carbon\Carbon::now()]); |
||
90 | } else { |
||
91 | //dd('else'); |
||
92 | $notify->create(['key' => 'new-version', 'value' => '', 'created_at' => \Carbon\Carbon::now()]); |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | |||
127 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.