Conditions | 1 |
Paths | 1 |
Total Lines | 53 |
Code Lines | 44 |
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 |
||
6 | public function testMakeLocalBusiness() |
||
7 | { |
||
8 | $profile = array( |
||
9 | 'model' => 'LocalBusiness', |
||
10 | 'options' => array( |
||
11 | 'base' => 'urn:test' |
||
12 | ), |
||
13 | 'datamapper' => function(array $rawdata){ |
||
14 | $data = array(); |
||
15 | $data['id'] = $rawdata[0]; |
||
16 | $data['legalName'] = $rawdata[2] . ' ' . $rawdata[1]; |
||
17 | $data['alternateName'] = $rawdata[2]; |
||
18 | $data['vatID'] = $rawdata[3]; |
||
19 | $data['email'] = $rawdata[4]; |
||
20 | $data['addressLocality'] = $rawdata[5]; |
||
21 | $data['postalCode'] = $rawdata[7]; |
||
22 | $data['addressRegion'] = $rawdata[8]; |
||
23 | $data['streetAddress'] = $rawdata[9] . ' ' . $rawdata[10] . ', ' . $rawdata[11]; |
||
24 | $data['long'] = $rawdata[14]; |
||
25 | $data['lat'] = $rawdata[15]; |
||
26 | |||
27 | return $data; |
||
28 | }, |
||
29 | ); |
||
30 | $rawdata = array( |
||
31 | '10042650', |
||
32 | 'ERBORISTERIA I PRATI DI GIOVANNA MONAMI', |
||
33 | '', |
||
34 | '01209991007', |
||
35 | '', |
||
36 | 'ROMA', |
||
37 | 'ROMA', |
||
38 | '00195', |
||
39 | 'RM', |
||
40 | 'VIA', |
||
41 | 'ANTONIO MORDINI', |
||
42 | '3', |
||
43 | '058091', |
||
44 | '0580912017145', |
||
45 | '12.464163', |
||
46 | '41.914001' |
||
47 | ); |
||
48 | |||
49 | $factsFactory = new \BOTK\FactsFactory($profile); |
||
50 | $facts = $factsFactory->factualize($rawdata); |
||
51 | $structuredData = $facts->asArray(); |
||
52 | |||
53 | $this->assertInstanceOf('\BOTK\Model\LocalBusiness', $facts); |
||
54 | $this->assertEquals($structuredData['vatID'], '01209991007'); |
||
55 | $this->assertEquals($structuredData['id'], '10042650'); |
||
56 | $this->assertEquals($structuredData['long'], '12.464163'); |
||
57 | $this->assertEquals($structuredData['streetAddress'], 'VIA ANTONIO MORDINI, 3'); |
||
58 | } |
||
59 | |||
62 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.