| Conditions | 11 |
| Paths | 47 |
| Total Lines | 47 |
| Lines | 12 |
| Ratio | 25.53 % |
| 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 |
||
| 110 | protected function execute(InputInterface $input, OutputInterface $output) { |
||
| 111 | $this->input = $input; |
||
| 112 | $this->output = $output; |
||
| 113 | |||
| 114 | $config = $this->getApplication()->getConfig(); |
||
| 115 | |||
| 116 | if ($input->getOption('id')) |
||
| 117 | $appId = $input->getOption('id'); |
||
| 118 | elseif (array_key_exists('appId', $config)) |
||
| 119 | $appId = $config['appId']; |
||
| 120 | else |
||
| 121 | throw new InvalidOptionException('Facebook Open Graph requires an App ID.'); |
||
| 122 | |||
| 123 | View Code Duplication | if ($input->getOption('secret')) |
|
| 124 | $appSecret = $input->getOption('secret'); |
||
| 125 | elseif (array_key_exists('appSecret', $config)) |
||
| 126 | $appSecret = $config['appSecret']; |
||
| 127 | else |
||
| 128 | throw new InvalidOptionException('Facebook Open Graph requires an App Secret.'); |
||
| 129 | |||
| 130 | View Code Duplication | if ($input->getOption('token')) |
|
| 131 | $accessToken = $input->getOption('token'); |
||
| 132 | elseif (array_key_exists('appAccessToken', $config)) |
||
| 133 | $accessToken = $config['appAccessToken']; |
||
| 134 | else |
||
| 135 | throw new InvalidOptionException('Facebook Open Graph requires an App|User Access Token.'); |
||
| 136 | |||
| 137 | $this->fb = new Facebook([ |
||
| 138 | 'app_id' => $appId, |
||
| 139 | 'app_secret' => $appSecret, |
||
| 140 | 'default_access_token' => $accessToken, |
||
| 141 | 'default_graph_version' => 'v2.8', |
||
| 142 | ]); |
||
| 143 | |||
| 144 | if ($url = $input->getOption('url')) { |
||
| 145 | $this->scrape($url); |
||
| 146 | } |
||
| 147 | elseif ($fileName = $input->getOption('file')) { |
||
| 148 | $urls = file($fileName, FILE_IGNORE_NEW_LINES); |
||
| 149 | |||
| 150 | if ($urls === FALSE) |
||
| 151 | throw new \RuntimeException('Cannot open the file.'); |
||
| 152 | |||
| 153 | foreach ($urls as $url) |
||
| 154 | $this->scrape($url); |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.