| Conditions | 12 |
| Paths | 96 |
| Total Lines | 106 |
| Code Lines | 69 |
| Lines | 86 |
| Ratio | 81.13 % |
| Changes | 7 | ||
| Bugs | 3 | Features | 4 |
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 |
||
| 40 | public function handle() |
||
| 41 | { |
||
| 42 | $infos = \Thujohn\Twitter\Facades\Twitter::getUsersLookup(['screen_name' => 'Symfomany', 'format' => 'php']); |
||
| 43 | $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017'); |
||
| 44 | $collection = new \MongoDB\Collection($manager, 'laravel.tweets'); |
||
|
|
|||
| 45 | |||
| 46 | View Code Duplication | if (!empty($infos)) { |
|
| 47 | $collection->deleteMany(['origin' => 'Twitter', 'type' => 'infos']); |
||
| 48 | |||
| 49 | $stat = [ |
||
| 50 | 'origin' => 'Twitter', |
||
| 51 | 'type' => 'infos', |
||
| 52 | 'data' => $infos, |
||
| 53 | 'created' => new \MongoDB\BSON\UTCDatetime(time()), |
||
| 54 | ]; |
||
| 55 | $collection->insertOne($stat); |
||
| 56 | } |
||
| 57 | |||
| 58 | $tweets = \Thujohn\Twitter\Facades\Twitter::getDmsOut(['format' => 'php']); |
||
| 59 | View Code Duplication | if (!empty($tweets)) { |
|
| 60 | $collection->deleteMany(['origin' => 'Twitter', 'type' => 'dmsout']); |
||
| 61 | |||
| 62 | foreach ($tweets as $tweet) { |
||
| 63 | $stat = [ |
||
| 64 | 'origin' => 'Twitter', |
||
| 65 | 'type' => 'dmsout', |
||
| 66 | 'data' => $tweet, |
||
| 67 | 'created' => new \MongoDB\BSON\UTCDatetime(time()), |
||
| 68 | ]; |
||
| 69 | $collection->insertOne($stat); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | $tweets = \Thujohn\Twitter\Facades\Twitter::getFavorites(['format' => 'php']); |
||
| 74 | View Code Duplication | if (!empty($tweets)) { |
|
| 75 | $collection->deleteMany(['origin' => 'Twitter', 'type' => 'favorites']); |
||
| 76 | |||
| 77 | foreach ($tweets as $tweet) { |
||
| 78 | $stat = [ |
||
| 79 | 'origin' => 'Twitter', |
||
| 80 | 'type' => 'favorites', |
||
| 81 | 'data' => $tweet, |
||
| 82 | 'created' => new \MongoDB\BSON\UTCDatetime(time()), |
||
| 83 | ]; |
||
| 84 | $collection->insertOne($stat); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | $tweets = \Thujohn\Twitter\Facades\Twitter::getMentionsTimeline( |
||
| 89 | [ |
||
| 90 | 'count' => 15, |
||
| 91 | 'format' => 'php', ]); |
||
| 92 | |||
| 93 | View Code Duplication | if (!empty($tweets)) { |
|
| 94 | $collection->deleteMany(['origin' => 'Twitter', 'type' => 'mentionstimeline']); |
||
| 95 | |||
| 96 | foreach ($tweets as $tweet) { |
||
| 97 | $stat = [ |
||
| 98 | 'origin' => 'Twitter', |
||
| 99 | 'type' => 'mentionstimeline', |
||
| 100 | 'data' => $tweet, |
||
| 101 | 'created' => new \MongoDB\BSON\UTCDatetime(time()), |
||
| 102 | ]; |
||
| 103 | $collection->insertOne($stat); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | $tweets = \Thujohn\Twitter\Facades\Twitter::getHomeTimeline([ |
||
| 108 | 'count' => 15, |
||
| 109 | 'format' => 'php', |
||
| 110 | ]); |
||
| 111 | |||
| 112 | View Code Duplication | if (!empty($tweets)) { |
|
| 113 | $collection->deleteMany(['origin' => 'Twitter', 'type' => 'hometimeline']); |
||
| 114 | |||
| 115 | foreach ($tweets as $tweet) { |
||
| 116 | $stat = [ |
||
| 117 | 'origin' => 'Twitter', |
||
| 118 | 'type' => 'hometimeline', |
||
| 119 | 'data' => $tweet, |
||
| 120 | 'created' => new \MongoDB\BSON\UTCDatetime(time()), |
||
| 121 | ]; |
||
| 122 | $collection->insertOne($stat); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | $tweets = \Thujohn\Twitter\Facades\Twitter::getUserTimeline([ |
||
| 127 | 'screen_name' => 'allocine', |
||
| 128 | 'count' => 15, |
||
| 129 | 'format' => 'php', |
||
| 130 | ]); |
||
| 131 | |||
| 132 | View Code Duplication | if (!empty($tweets)) { |
|
| 133 | $collection->deleteMany(['origin' => 'Twitter', 'type' => 'usertimeline']); |
||
| 134 | |||
| 135 | foreach ($tweets as $tweet) { |
||
| 136 | $stat = [ |
||
| 137 | 'origin' => 'Twitter', |
||
| 138 | 'type' => 'usertimeline', |
||
| 139 | 'data' => $tweet, |
||
| 140 | 'created' => new \MongoDB\BSON\UTCDatetime(time()), |
||
| 141 | ]; |
||
| 142 | $collection->insertOne($stat); |
||
| 143 | } |
||
| 144 | } |
||
| 145 | } |
||
| 146 | } |
||
| 147 |
This check looks for function calls that miss required arguments.