Conditions | 1 |
Paths | 1 |
Total Lines | 60 |
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 |
||
22 | public function run() |
||
23 | { |
||
24 | factory(History::class)->create(); |
||
25 | $user = factory(User::class)->create(); |
||
26 | $image = factory(Image::class)->create([ |
||
27 | "imagable_id" => $user->id, |
||
28 | "imagable_type" => User::class, |
||
29 | ]); |
||
30 | factory(Image::class)->create([ |
||
31 | "imagable_id" => $user->id, |
||
32 | "imagable_type" => UncachedUser::class, |
||
33 | "path" => $image->path, |
||
34 | ]); |
||
35 | factory(Tag::class, 5)->create(); |
||
36 | $post = factory(Post::class)->create(); |
||
37 | $uncachedPost = (new UncachedPost)->first(); |
||
38 | $post->tags()->attach(1); |
||
39 | $uncachedPost->tags()->attach(1); |
||
40 | factory(Comment::class, 5) |
||
41 | ->create([ |
||
42 | "commentable_id" => $post->id, |
||
43 | "commentable_type" => Post::class, |
||
44 | ]) |
||
45 | ->each(function ($comment) { |
||
46 | (new Comment)->create([ |
||
47 | "commentable_id" => $comment->commentable_id, |
||
48 | "commentable_type" => UncachedPost::class, |
||
49 | "description" => $comment->description, |
||
50 | "subject" => $comment->subject . ' - uncached post', |
||
51 | ]); |
||
52 | }); |
||
53 | $publishers = factory(Publisher::class, 10)->create(); |
||
54 | (new Author)->observe(AuthorObserver::class); |
||
55 | factory(Author::class, 10)->create() |
||
56 | ->each(function ($author) use ($publishers) { |
||
57 | $profile = factory(Profile::class) |
||
58 | ->make(); |
||
59 | $profile->author_id = $author->id; |
||
60 | $profile->save(); |
||
61 | factory(Book::class, random_int(5, 25)) |
||
62 | ->create([ |
||
63 | "author_id" => $author->id, |
||
64 | "publisher_id" => $publishers[rand(0, 9)]->id, |
||
65 | ]) |
||
66 | ->each(function ($book) use ($author, $publishers) { |
||
67 | factory(Printer::class)->create([ |
||
68 | "book_id" => $book->id, |
||
69 | ]); |
||
70 | }); |
||
71 | factory(Profile::class)->make([ |
||
72 | 'author_id' => $author->id, |
||
73 | ]); |
||
74 | }); |
||
75 | |||
76 | $bookIds = (new Book)->all()->pluck('id'); |
||
77 | factory(Store::class, 10)->create() |
||
78 | ->each(function ($store) use ($bookIds) { |
||
79 | $store->books()->sync(rand($bookIds->min(), $bookIds->max())); |
||
80 | }); |
||
81 | } |
||
82 | } |
||
83 |