Conditions | 1 |
Paths | 1 |
Total Lines | 79 |
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 | $optionArray = |
||
32 | [ |
||
33 | 'adminName' => 'Test', |
||
34 | 'adminUser' => 'test', |
||
35 | 'adminPassword' => 'test', |
||
36 | 'adminEmail' => '[email protected]' |
||
37 | ]; |
||
38 | $installer = $this->installerFactory(); |
||
39 | $installer->init(); |
||
40 | $installer->rawCreate(); |
||
41 | $installer->insertSettings($optionArray); |
||
42 | $articleOne = Db::forTablePrefix('articles')->create(); |
||
43 | $articleOne |
||
44 | ->set( |
||
45 | [ |
||
46 | 'title' => 'Article One', |
||
47 | 'alias' => 'article-one', |
||
48 | 'language' => 'en', |
||
49 | 'rank' => 1 |
||
50 | ]) |
||
51 | ->save(); |
||
52 | Db::forTablePrefix('articles') |
||
53 | ->create() |
||
54 | ->set( |
||
55 | [ |
||
56 | 'title' => 'Article One Sister', |
||
57 | 'alias' => 'article-one-sister', |
||
58 | 'language' => 'de', |
||
59 | 'sibling' => $articleOne->id, |
||
60 | 'rank' => 2 |
||
61 | ]) |
||
62 | ->save(); |
||
63 | Db::forTablePrefix('articles') |
||
64 | ->create() |
||
65 | ->set( |
||
66 | [ |
||
67 | 'title' => 'Article One Brother', |
||
68 | 'alias' => 'article-one-brother', |
||
69 | 'language' => 'fr', |
||
70 | 'sibling' => $articleOne->id, |
||
71 | 'rank' => 2 |
||
72 | ]) |
||
73 | ->save(); |
||
74 | $articleThree = Db::forTablePrefix('articles')->create(); |
||
75 | $articleThree |
||
76 | ->set( |
||
77 | [ |
||
78 | 'title' => 'Article Two', |
||
79 | 'alias' => 'article-two', |
||
80 | 'language' => 'en', |
||
81 | 'rank' => 3 |
||
82 | ]) |
||
83 | ->save(); |
||
84 | Db::forTablePrefix('articles') |
||
85 | ->create() |
||
86 | ->set( |
||
87 | [ |
||
88 | 'title' => 'Article Two Sister', |
||
89 | 'alias' => 'article-two-sister', |
||
90 | 'language' => 'de', |
||
91 | 'sibling' => $articleThree->id, |
||
92 | 'rank' => 4 |
||
93 | ]) |
||
94 | ->save(); |
||
95 | Db::forTablePrefix('articles') |
||
96 | ->create() |
||
97 | ->set( |
||
98 | [ |
||
99 | 'title' => 'Article Three', |
||
100 | 'alias' => 'article-three', |
||
101 | 'date' => 1456786800, |
||
102 | 'rank' => 5, |
||
103 | 'status' => 2 |
||
104 | ]) |
||
105 | ->save(); |
||
106 | } |
||
107 | |||
276 |
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.