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 |
||
10 | class JsonContext implements Context, SnippetAcceptingContext |
||
|
|||
11 | { |
||
12 | private $jsonInspector; |
||
13 | |||
14 | private $asserter; |
||
15 | |||
16 | private $jsonSchemaBaseUrl; |
||
17 | |||
18 | public function __construct(JsonInspector $jsonInspector, $jsonSchemaBaseUrl = null) |
||
24 | |||
25 | /** |
||
26 | * @When /^I load JSON:$/ |
||
27 | */ |
||
28 | public function iLoadJson(PyStringNode $jsonContent) |
||
32 | |||
33 | /** |
||
34 | * @Then /^the response should be in JSON$/ |
||
35 | */ |
||
36 | public function responseShouldBeInJson() |
||
40 | |||
41 | /** |
||
42 | * @Then /^the JSON node "(?P<jsonNode>[^"]*)" should be equal to "(?P<expectedValue>.*)"$/ |
||
43 | */ |
||
44 | public function theJsonNodeShouldBeEqualTo($jsonNode, $expectedValue) |
||
51 | |||
52 | /** |
||
53 | * @Then /^the JSON node "(?P<jsonNode>[^"]*)" should have (?P<expectedNth>\d+) elements?$/ |
||
54 | * @Then /^the JSON array node "(?P<jsonNode>[^"]*)" should have (?P<expectedNth>\d+) elements?$/ |
||
55 | */ |
||
56 | public function theJsonNodeShouldHaveElements($jsonNode, $expectedNth) |
||
63 | |||
64 | /** |
||
65 | * @Then /^the JSON array node "(?P<jsonNode>[^"]*)" should contain "(?P<expectedValue>.*)" element$/ |
||
66 | */ |
||
67 | View Code Duplication | public function theJsonArrayNodeShouldContainElements($jsonNode, $expectedValue) |
|
74 | |||
75 | /** |
||
76 | * @Then /^the JSON array node "(?P<jsonNode>[^"]*)" should not contain "(?P<expectedValue>.*)" element$/ |
||
77 | */ |
||
78 | public function theJsonArrayNodeShouldNotContainElements($jsonNode, $expectedValue) |
||
85 | |||
86 | /** |
||
87 | * @Then /^the JSON node "(?P<jsonNode>[^"]*)" should contain "(?P<expectedValue>.*)"$/ |
||
88 | */ |
||
89 | View Code Duplication | public function theJsonNodeShouldContain($jsonNode, $expectedValue) |
|
96 | |||
97 | /** |
||
98 | * Checks, that given JSON node does not contain given value |
||
99 | * |
||
100 | * @Then /^the JSON node "(?P<jsonNode>[^"]*)" should not contain "(?P<unexpectedValue>.*)"$/ |
||
101 | */ |
||
102 | View Code Duplication | public function theJsonNodeShouldNotContain($jsonNode, $unexpectedValue) |
|
109 | |||
110 | /** |
||
111 | * Checks, that given JSON node exist |
||
112 | * |
||
113 | * @Given /^the JSON node "(?P<jsonNode>[^"]*)" should exist$/ |
||
114 | */ |
||
115 | public function theJsonNodeShouldExist($jsonNode) |
||
123 | |||
124 | /** |
||
125 | * Checks, that given JSON node does not exist |
||
126 | * |
||
127 | * @Given /^the JSON node "(?P<jsonNode>[^"]*)" should not exist$/ |
||
128 | */ |
||
129 | public function theJsonNodeShouldNotExist($jsonNode) |
||
147 | |||
148 | /** |
||
149 | * @Then /^the JSON should be valid according to this schema:$/ |
||
150 | */ |
||
151 | public function theJsonShouldBeValidAccordingToThisSchema(PyStringNode $jsonSchemaContent) |
||
162 | |||
163 | /** |
||
164 | * @Then /^the JSON should be valid according to the schema "(?P<filename>[^"]*)"$/ |
||
165 | */ |
||
166 | public function theJsonShouldBeValidAccordingToTheSchema($filename) |
||
176 | |||
177 | /** |
||
178 | * @Then /^the JSON should be equal to:$/ |
||
179 | */ |
||
180 | public function theJsonShouldBeEqualTo(PyStringNode $jsonContent) |
||
194 | |||
195 | /** |
||
196 | * @Then the JSON path expression :pathExpression should be equal to json :expectedJson |
||
197 | */ |
||
198 | public function theJsonPathExpressionShouldBeEqualToJson($pathExpression, $expectedJson) |
||
205 | |||
206 | /** |
||
207 | * @Then the JSON path expression :pathExpression should be equal to: |
||
208 | */ |
||
209 | public function theJsonExpressionShouldBeEqualTo($pathExpression, PyStringNode $expectedJson) |
||
213 | |||
214 | /** |
||
215 | * @Then the JSON path expression :pathExpression should have result |
||
216 | */ |
||
217 | public function theJsonPathExpressionShouldHaveResult($pathExpression) |
||
222 | |||
223 | /** |
||
224 | * @Then the JSON path expression :pathExpression should not have result |
||
225 | */ |
||
226 | public function theJsonPathExpressionShouldNotHaveResult($pathExpression) |
||
231 | |||
232 | private function evaluateJsonNodeValue($jsonNode) |
||
236 | |||
237 | private function readJson() |
||
241 | |||
242 | private function resolveFilename($filename) |
||
266 | |||
267 | private function assert(callable $assertion) |
||
275 | } |
||
276 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.