Conditions | 1 |
Paths | 1 |
Total Lines | 60 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
38 | public function setUp(){ |
||
39 | $this->appName = 'chat'; |
||
40 | $this->request = $this->getMockBuilder('\OCP\IRequest') |
||
41 | ->disableOriginalConstructor() |
||
42 | ->getMock(); |
||
43 | |||
44 | $this->userOnlineMapper = $this->getMockBuilder('\OCA\Chat\OCH\Db\UserOnlineMapper') |
||
|
|||
45 | ->disableOriginalConstructor() |
||
46 | ->getMock(); |
||
47 | |||
48 | $this->och = $this->getMockBuilder('\OCA\Chat\OCH\OCH') |
||
49 | ->disableOriginalConstructor() |
||
50 | ->getMock(); |
||
51 | |||
52 | $this->syncOnline = $this->getMockBuilder('\OCA\Chat\OCH\Commands\SyncOnline') |
||
53 | ->disableOriginalConstructor() |
||
54 | ->getMock(); |
||
55 | |||
56 | $this->contactsManager = $this->getMockBuilder('\OCP\Contacts\IManager') |
||
57 | ->disableOriginalConstructor() |
||
58 | ->getMock(); |
||
59 | |||
60 | $this->backendManager = $this->getMockBuilder('\OCA\Chat\IBackendManager') |
||
61 | ->disableOriginalConstructor() |
||
62 | ->getMock(); |
||
63 | |||
64 | $this->user = $this->getMockBuilder('\OCP\IUser') |
||
65 | ->disableOriginalConstructor() |
||
66 | ->getMock(); |
||
67 | |||
68 | $this->rootFolder = $this->getMockBuilder('\OCP\Files\IRootFolder') |
||
69 | ->disableOriginalConstructor() |
||
70 | ->getMock(); |
||
71 | |||
72 | $this->greet = $this->getMockBuilder('\OCA\Chat\OCH\Commands\Greet') |
||
73 | ->disableOriginalConstructor() |
||
74 | ->getMock(); |
||
75 | |||
76 | $this->greet = $this->getMockBuilder('\OCP\IConfig') |
||
77 | ->disableOriginalConstructor() |
||
78 | ->getMock(); |
||
79 | |||
80 | $this->chat = new Chat( |
||
81 | $this->backendManager, |
||
82 | $this->userOnlineMapper, |
||
83 | $this->syncOnline, |
||
84 | $this->user, |
||
85 | $this->contactsManager, |
||
86 | $this->rootFolder |
||
87 | ); |
||
88 | |||
89 | $this->controller = new AppController( |
||
90 | $this->appName, |
||
91 | $this->request, |
||
92 | $this->chat, |
||
93 | $this->contactsManager, |
||
94 | $this->config, |
||
95 | $this->greet |
||
96 | ); |
||
97 | } |
||
98 | |||
265 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: