Conditions | 1 |
Paths | 1 |
Total Lines | 97 |
Code Lines | 72 |
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 | #!/usr/bin/php |
||
25 | protected function setup(Options $options) { |
||
26 | /* global */ |
||
27 | $options->registerOption( |
||
28 | 'force', |
||
29 | 'force obtaining a lock for the page (generally bad idea)', |
||
30 | 'f' |
||
31 | ); |
||
32 | $options->registerOption( |
||
33 | 'user', |
||
34 | 'work as this user. defaults to current CLI user', |
||
35 | 'u', |
||
36 | 'username' |
||
37 | ); |
||
38 | $options->setHelp( |
||
39 | 'Utility to help command line Dokuwiki page editing, allow ' . |
||
40 | 'pages to be checked out for editing then committed after changes' |
||
41 | ); |
||
42 | |||
43 | /* checkout command */ |
||
44 | $options->registerCommand( |
||
45 | 'checkout', |
||
46 | 'Checks out a file from the repository, using the wiki id and obtaining ' . |
||
47 | 'a lock for the page. ' . "\n" . |
||
48 | 'If a working_file is specified, this is where the page is copied to. ' . |
||
49 | 'Otherwise defaults to the same as the wiki page in the current ' . |
||
50 | 'working directory.' |
||
51 | ); |
||
52 | $options->registerArgument( |
||
53 | 'wikipage', |
||
54 | 'The wiki page to checkout', |
||
55 | true, |
||
56 | 'checkout' |
||
57 | ); |
||
58 | $options->registerArgument( |
||
59 | 'workingfile', |
||
60 | 'How to name the local checkout', |
||
61 | false, |
||
62 | 'checkout' |
||
63 | ); |
||
64 | |||
65 | /* commit command */ |
||
66 | $options->registerCommand( |
||
67 | 'commit', |
||
68 | 'Checks in the working_file into the repository using the specified ' . |
||
69 | 'wiki id, archiving the previous version.' |
||
70 | ); |
||
71 | $options->registerArgument( |
||
72 | 'workingfile', |
||
73 | 'The local file to commit', |
||
74 | true, |
||
75 | 'commit' |
||
76 | ); |
||
77 | $options->registerArgument( |
||
78 | 'wikipage', |
||
79 | 'The wiki page to create or update', |
||
80 | true, |
||
81 | 'commit' |
||
82 | ); |
||
83 | $options->registerOption( |
||
84 | 'message', |
||
85 | 'Summary describing the change (required)', |
||
86 | 'm', |
||
87 | 'summary', |
||
88 | 'commit' |
||
89 | ); |
||
90 | $options->registerOption( |
||
91 | 'trivial', |
||
92 | 'minor change', |
||
93 | 't', |
||
94 | false, |
||
95 | 'commit' |
||
96 | ); |
||
97 | |||
98 | /* lock command */ |
||
99 | $options->registerCommand( |
||
100 | 'lock', |
||
101 | 'Obtains or updates a lock for a wiki page' |
||
102 | ); |
||
103 | $options->registerArgument( |
||
104 | 'wikipage', |
||
105 | 'The wiki page to lock', |
||
106 | true, |
||
107 | 'lock' |
||
108 | ); |
||
109 | |||
110 | /* unlock command */ |
||
111 | $options->registerCommand( |
||
112 | 'unlock', |
||
113 | 'Removes a lock for a wiki page.' |
||
114 | ); |
||
115 | $options->registerArgument( |
||
116 | 'wikipage', |
||
117 | 'The wiki page to unlock', |
||
118 | true, |
||
119 | 'unlock' |
||
120 | ); |
||
121 | } |
||
122 | |||
323 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.