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 |
||
12 | class SoapSearchApiTest extends WebTestCase |
||
13 | { |
||
14 | /** Default value for offset and max_records */ |
||
15 | const DEFAULT_VALUE = 0; |
||
16 | |||
17 | protected function setUp() |
||
18 | { |
||
19 | $this->initClient([], $this->generateWsseAuthHeader()); |
||
20 | $this->initSoapClient(); |
||
21 | |||
22 | $this->loadFixtures(['Oro\Bundle\SearchBundle\Tests\Functional\Controller\DataFixtures\LoadSearchItemData']); |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * @param array $request |
||
27 | * @param array $response |
||
28 | * @SuppressWarnings(PHPMD.NPathComplexity) |
||
29 | * @dataProvider searchDataProvider |
||
30 | */ |
||
31 | public function testSearch(array $request, array $response) |
||
81 | |||
82 | /** |
||
83 | * Data provider for SOAP API tests |
||
84 | * |
||
85 | * @return array |
||
86 | */ |
||
87 | public function searchDataProvider() |
||
93 | |||
94 | /** |
||
95 | * @param array $items |
||
96 | * @param array $result |
||
97 | */ |
||
98 | protected function assertResultHasItems(array $items, array $result) |
||
104 | } |
||
105 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: