Conditions | 1 |
Paths | 1 |
Total Lines | 54 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 13 | ||
Bugs | 1 | Features | 11 |
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 |
||
89 | public function dashboard() |
||
90 | { |
||
91 | $nbacteurs = Actors::count(); |
||
92 | $nbcommentaires = Comments::count(); |
||
93 | $nbmovies = Movies::count(); |
||
94 | $nbseances = Sessions::count(); |
||
95 | |||
96 | |||
97 | $manager = new \MongoDB\Driver\Manager("mongodb://localhost:27017"); |
||
98 | $collection = new \MongoDB\Collection($manager, "laravel.videos"); |
||
99 | $videos = collect($collection->find()->toArray())->shuffle(); |
||
100 | |||
101 | $collection = new \MongoDB\Collection($manager, "laravel.stats"); |
||
102 | $youtubeinfo = collect($collection->find(["origin" => "Youtube"])->toArray())->first(); |
||
103 | |||
104 | $collection = new \MongoDB\Collection($manager, "laravel.stats"); |
||
105 | $tweeterinfo = collect($collection->find(['origin' => 'Twitter', 'type' => 'infos'])->toArray())->first(); |
||
106 | |||
107 | |||
108 | $actor = new Actors(); // Je récpere mon modèle |
||
109 | $comment = new Comments(); // Je récpere mon modèle |
||
110 | $movie = new Movies(); // Je récpere mon modèle |
||
111 | $session = new Sessions(); // Je récpere mon modèle |
||
112 | $user = new User(); // Je récpere mon modèle |
||
113 | |||
114 | $avgacteurs = $actor->getAvgActors(); |
||
115 | $avgnotecommentaire = $comment->getAvgNote(); |
||
116 | $avgnotepresse = $movie->getAvgNotePresse(); |
||
117 | $avghour = $session->getAvgHourDate(); |
||
118 | |||
119 | $seances = $session->getNextSession(); |
||
120 | $users = $user->getLastUsers(); |
||
121 | |||
122 | |||
123 | |||
124 | return view('Main/dashboard', [ |
||
125 | 'avgnotecommentaire' => $avgnotecommentaire->avgnote, |
||
126 | 'avgnotepresse' => $avgnotepresse->avgpress, |
||
127 | 'avgacteurs' => $avgacteurs->age, |
||
128 | 'videos' => $videos, |
||
129 | 'video' => $videos[0], |
||
130 | 'youtubeinfo' => $youtubeinfo->data, |
||
131 | 'tweeterinfo' => $tweeterinfo['data'][0], |
||
132 | 'youtubeinfodateupdated' => $youtubeinfo->created, |
||
133 | 'tweeterinfodateupdated' => $tweeterinfo['created_at'], |
||
134 | 'avghour' => $avghour->avghour, |
||
135 | 'nbacteurs' => $nbacteurs, |
||
136 | 'nbcommentaires' => $nbcommentaires, |
||
137 | 'nbmovies' => $nbmovies, |
||
138 | 'nbseances' => $nbseances, |
||
139 | 'seances' => $seances, |
||
140 | 'users' => $users, |
||
141 | ]); |
||
142 | } |
||
143 | } |
||
144 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.