Conditions | 1 |
Paths | 1 |
Total Lines | 59 |
Code Lines | 29 |
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 |
||
24 | protected function configure() |
||
25 | { |
||
26 | // @codingStandardsIgnoreStart |
||
27 | $this |
||
28 | ->setName('devhelp_piwik:api:call') |
||
29 | ->setDescription('Calls piwik api method') |
||
30 | ->addArgument( |
||
31 | 'method', |
||
32 | InputArgument::REQUIRED, |
||
33 | 'Method to call. Can be either a service id (without @) or method name (like "Actions.getPageUrls")' |
||
34 | ) |
||
35 | ->addOption( |
||
36 | 'params', |
||
37 | 'p', |
||
38 | InputOption::VALUE_OPTIONAL, |
||
39 | 'Method parameters as string (must be valid for parse_str function). '. |
||
40 | 'They will be merged with params from method service (if it has any) and will override existing ones if names are the same' |
||
41 | ) |
||
42 | ->addOption( |
||
43 | 'api', |
||
44 | null, |
||
45 | InputOption::VALUE_OPTIONAL, |
||
46 | 'Api that will be used to call the method (name from configuration). '. |
||
47 | 'If not specified default api is used. Is ignored if "method" is passed as a service' |
||
48 | )->addOption( |
||
49 | 'show-response', |
||
50 | 'r', |
||
51 | InputOption::VALUE_NONE, |
||
52 | 'If set then response is logged. '. |
||
53 | 'Verbosity level must be at least -vv and used together with this option in order to display the response' |
||
54 | ) |
||
55 | ->setHelp(<<<HELP |
||
56 | The <info>%command.name%</info> command calls Piwik API method. |
||
57 | |||
58 | Method can be either service id or method name: |
||
59 | |||
60 | <info>php %command.full_name% SitesManager.getAllSites</info> |
||
61 | <info>php %command.full_name% my_method_service_id</info> |
||
62 | |||
63 | If method name is used then you can use <comment>--api</comment> to set api name from which the method is to be called (if not specified then default api is used): |
||
64 | |||
65 | <info>php %command.full_name% SitesManager.getAllSites --api=reader</info> |
||
66 | |||
67 | Use <comment>--params</comment> in order to set call parameters (they will be merged with default params defined for the method service): |
||
68 | |||
69 | <info>php %command.full_name% my_method_service_id --params='idSite=2&token_auth=MY_TOKEN'</info> |
||
70 | |||
71 | Use <comment>-vv</comment> in order to display relevant information about the ongoing request |
||
72 | |||
73 | <info>php %command.full_name% my_method_service_id -vv</info> |
||
74 | |||
75 | Use <comment>--show-response</comment> together with <comment>-vv</comment> in order to display the response. <comment>Response must be PSR-7 compatible</comment> |
||
76 | |||
77 | <info>php %command.full_name% my_method_service_id -vv --show-response</info> |
||
78 | |||
79 | HELP |
||
80 | ); |
||
81 | // @codingStandardsIgnoreEnd |
||
82 | } |
||
83 | |||
137 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.