Conditions | 2 |
Paths | 2 |
Total Lines | 55 |
Code Lines | 38 |
Lines | 0 |
Ratio | 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 |
||
19 | public function setUp() { |
||
20 | parent::setUp(); |
||
21 | |||
22 | Injector::nest(); |
||
23 | |||
24 | // Check dependencies |
||
25 | if (!class_exists('Phockito')) { |
||
26 | $this->skipTest = true; |
||
27 | return $this->markTestSkipped("These tests need the Phockito module installed to run"); |
||
28 | } |
||
29 | |||
30 | // Mock link checker |
||
31 | $checker = Phockito::mock('LinkChecker'); |
||
32 | Phockito::when($checker) |
||
33 | ->checkLink('http://www.working.com') |
||
34 | ->return(200); |
||
35 | |||
36 | Phockito::when($checker) |
||
37 | ->checkLink('http://www.broken.com/url/thing') // 404 on working site |
||
38 | ->return(404); |
||
39 | |||
40 | Phockito::when($checker) |
||
41 | ->checkLink('http://www.broken.com') // 403 on working site |
||
42 | ->return(403); |
||
43 | |||
44 | Phockito::when($checker) |
||
45 | ->checkLink('http://www.nodomain.com') // no ping |
||
46 | ->return(0); |
||
47 | |||
48 | Phockito::when($checker) |
||
49 | ->checkLink('/internal/link') |
||
50 | ->return(null); |
||
51 | |||
52 | Phockito::when($checker) |
||
53 | ->checkLink('[sitetree_link,id=9999]') |
||
54 | ->return(null); |
||
55 | |||
56 | Phockito::when($checker) |
||
57 | ->checkLink('home') |
||
58 | ->return(null); |
||
59 | |||
60 | Phockito::when($checker) |
||
61 | ->checkLink('broken-internal') |
||
62 | ->return(null); |
||
63 | |||
64 | Phockito::when($checker) |
||
65 | ->checkLink('[sitetree_link,id=1]') |
||
66 | ->return(null); |
||
67 | |||
68 | Phockito::when($checker) |
||
69 | ->checkLink(Hamcrest_Matchers::anything()) // anything else is 404 |
||
70 | ->return(404); |
||
71 | |||
72 | Injector::inst()->registerService($checker, 'LinkChecker'); |
||
73 | } |
||
74 | |||
158 |
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.