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 |
||
9 | class FeatureContext implements Context |
||
10 | { |
||
11 | |||
12 | use \JuliusHaertl\NextcloudBehat\FilesSharingContextTrait; |
||
13 | use \JuliusHaertl\NextcloudBehat\FilesDavContextTrait; |
||
14 | use \JuliusHaertl\NextcloudBehat\UserContextTrait; |
||
15 | use \JuliusHaertl\NextcloudBehat\UserWebContextTrait; |
||
16 | |||
17 | /** |
||
18 | * Initializes context. |
||
19 | * |
||
20 | * Every scenario gets its own context instance. |
||
21 | * You can also pass arbitrary arguments to the |
||
22 | * context constructor through behat.yml. |
||
23 | */ |
||
24 | public function __construct($baseUrl) |
||
28 | |||
29 | /** |
||
30 | * @When User :user opens :file |
||
31 | */ |
||
32 | public function userOpens($user, $file) |
||
55 | |||
56 | |||
57 | /** |
||
58 | * @Then a guest opens the share link |
||
59 | */ |
||
60 | public function aGuestOpensTheShareLink() |
||
83 | |||
84 | /** |
||
85 | * @Then Collabora fetches checkFileInfo |
||
86 | */ |
||
87 | public function collaboraFetchesCheckfileinfo() { |
||
93 | |||
94 | /** |
||
95 | * @Then Collabora puts :source |
||
96 | */ |
||
97 | public function collaboraPuts($source) |
||
114 | |||
115 | /** |
||
116 | * @Then /^the HTTP status code should be "([^"]*)"$/ |
||
117 | * @param int $statusCode |
||
118 | */ |
||
119 | public function theHTTPStatusCodeShouldBe($statusCode) { |
||
122 | |||
123 | |||
124 | /** |
||
125 | * @Then checkFileInfo :arg1 is ":arg2" |
||
126 | */ |
||
127 | public function checkfileinfoIs($arg1, $arg2) |
||
131 | |||
132 | |||
133 | /** |
||
134 | * @Then checkFileInfo :arg1 matches ":arg2" |
||
135 | */ |
||
136 | public function checkfileinfoMatches($arg1, $arg2) |
||
140 | |||
141 | /** |
||
142 | * @Then checkFileInfo :arg1 is true |
||
143 | */ |
||
144 | public function checkfileinfoIsTrue($arg1) |
||
148 | |||
149 | /** |
||
150 | * @Then checkFileInfo :arg1 is false |
||
151 | */ |
||
152 | public function checkfileinfoIsFalse($arg1) |
||
156 | |||
157 | } |
||
158 |
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.