Conditions | 10 |
Paths | 288 |
Total Lines | 50 |
Code Lines | 29 |
Lines | 10 |
Ratio | 20 % |
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 |
||
31 | public function testSearch(array $request, array $response) |
||
32 | { |
||
33 | View Code Duplication | if (array_key_exists('supported_engines', $request)) { |
|
34 | $engine = $this->getContainer()->getParameter('oro_search.engine'); |
||
35 | if (!in_array($engine, $request['supported_engines'])) { |
||
36 | $this->markTestIncomplete('Test should not be executed on this engine'); |
||
37 | } |
||
38 | unset($request['supported_engines']); |
||
39 | } |
||
40 | |||
41 | if (is_null($request['search'])) { |
||
42 | $request['search'] =''; |
||
43 | } |
||
44 | if (is_null($request['offset'])) { |
||
45 | $request['offset'] = self::DEFAULT_VALUE; |
||
46 | } |
||
47 | if (is_null($request['max_results'])) { |
||
48 | $request['max_results'] = self::DEFAULT_VALUE; |
||
49 | } |
||
50 | |||
51 | $result = $this->soapClient->search( |
||
|
|||
52 | $request['search'], |
||
53 | $request['offset'], |
||
54 | $request['max_results'] |
||
55 | ); |
||
56 | $result = $this->valueToArray($result); |
||
57 | |||
58 | $this->assertEquals($response['records_count'], $result['recordsCount']); |
||
59 | $this->assertEquals($response['count'], $result['count']); |
||
60 | |||
61 | if (empty($result['elements']['item'])) { |
||
62 | $result['elements']['item'] = []; |
||
63 | } |
||
64 | |||
65 | // if only one element |
||
66 | View Code Duplication | if (empty($result['elements']['item'][0])) { |
|
67 | $result['elements']['item'] = [$result['elements']['item']]; |
||
68 | } |
||
69 | |||
70 | // remove ID references |
||
71 | $recordsRequired = !empty($response['soap']['item'][0]['recordTitle']); |
||
72 | foreach (array_keys($result['elements']['item']) as $key) { |
||
73 | unset($result['elements']['item'][$key]['recordId']); |
||
74 | if (!$recordsRequired) { |
||
75 | unset($result['elements']['item'][$key]['recordTitle']); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | $this->assertResultHasItems($response['soap']['item'], $result['elements']['item']); |
||
80 | } |
||
81 | |||
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: