Conditions | 1 |
Paths | 1 |
Total Lines | 59 |
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 |
||
28 | public function setUp() : void |
||
29 | { |
||
30 | parent::setUp(); |
||
31 | $installer = $this->installerFactory(); |
||
32 | $installer->init(); |
||
33 | $installer->rawCreate(); |
||
34 | $categoryOne = Db::forTablePrefix('categories')->create(); |
||
35 | $categoryOne |
||
36 | ->set( |
||
37 | [ |
||
38 | 'title' => 'Category One', |
||
39 | 'alias' => 'category-one' |
||
40 | ]) |
||
41 | ->save(); |
||
42 | Db::forTablePrefix('categories') |
||
43 | ->create() |
||
44 | ->set( |
||
45 | [ |
||
46 | 'title' => 'Category Two', |
||
47 | 'alias' => 'category-two' |
||
48 | ]) |
||
49 | ->save(); |
||
50 | $articleOne = Db::forTablePrefix('articles')->create(); |
||
51 | $articleOne |
||
52 | ->set( |
||
53 | [ |
||
54 | 'title' => 'Article One', |
||
55 | 'alias' => 'article-one', |
||
56 | 'category' => $categoryOne->id |
||
57 | ]) |
||
58 | ->save(); |
||
59 | Db::forTablePrefix('articles') |
||
60 | ->create() |
||
61 | ->set( |
||
62 | [ |
||
63 | 'title' => 'Article Two', |
||
64 | 'alias' => 'article-two', |
||
65 | 'category' => $categoryOne->id |
||
66 | ]) |
||
67 | ->save(); |
||
68 | Db::forTablePrefix('comments') |
||
69 | ->create() |
||
70 | ->set( |
||
71 | [ |
||
72 | 'author' => 'Comment One', |
||
73 | 'text' => 'comment-one', |
||
74 | 'article' => $articleOne->id |
||
75 | ]) |
||
76 | ->save(); |
||
77 | Db::forTablePrefix('comments') |
||
78 | ->create() |
||
79 | ->set( |
||
80 | [ |
||
81 | 'author' => 'Comment Two', |
||
82 | 'text' => 'comment-two', |
||
83 | 'article' => $articleOne->id |
||
84 | ]) |
||
85 | ->save(); |
||
86 | } |
||
87 | |||
196 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.