Passed
Push — master ( 823e5a...6ca56e )
by Quim González
04:15
created

AsksForUsers   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
dl 19
loc 19
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A askForUsers() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace App\Http\Requests\Traits;
4
5
6
use App\User;
7
8
/**
9
 * Trait ChecksPermissions.
10
 */
11 View Code Duplication
trait AsksForUsers
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
12
{
13
    /**
14
     * @param $user
15
     *
16
     * @return mixed
17
     */
18
    protected function askForUsers()
19
    {
20
        $users = User::all();
21
22
        //pluck és com si es fes un foreach buscant per nom i afegir-ho a un array.
23
        //el que fa es agafar el valor a partir d'una clau.
24
        // ho passem a array i ho mostrem.
25
        // + info README
26
        $user_names = $users->pluck('name')->toArray();
27
        $user_name = $this->choice('User id?', $user_names);
0 ignored issues
show
Bug introduced by
It seems like choice() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        /** @scrutinizer ignore-call */ 
28
        $user_name = $this->choice('User id?', $user_names);
Loading history...
28
29
        return $users->where('name', $user_name)->first()->id;
30
    }
31
}
32