| Conditions | 3 |
| Paths | 4 |
| Total Lines | 58 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 47 | public static function moveToDrive($job = null) { |
||
| 48 | $data = unserialize($job->workload()); |
||
| 49 | global $main_arr; |
||
| 50 | $fb = new Facebook\Facebook( |
||
| 51 | [ |
||
| 52 | 'app_id' => 'XXXXXXXXXX', |
||
| 53 | 'app_secret' => 'XXXXXXXXXX', |
||
| 54 | 'default_graph_version' => 'v2.2' |
||
| 55 | ] |
||
| 56 | ); |
||
| 57 | $client = new Google_Client(); |
||
| 58 | $client->setAuthConfigFile(__DIR__ . '/client_secret.json'); |
||
| 59 | $client->setAccessType("online"); |
||
| 60 | $client->setIncludeGrantedScopes(true); |
||
| 61 | $client->addScope(Google_Service_Drive::DRIVE); |
||
| 62 | $client->setAccessToken($data['google_access_token']); |
||
| 63 | $fileMetadata = new Google_Service_Drive_DriveFile( |
||
| 64 | array( |
||
| 65 | 'name' => $data['albumName'], |
||
| 66 | 'mimeType' => 'application/vnd.google-apps.folder', |
||
| 67 | 'parents' => array($data['parentFolderId'])) |
||
| 68 | ); |
||
| 69 | $drive = new Google_Service_Drive($client); |
||
| 70 | $SubFolder = $drive->files->create( |
||
| 71 | $fileMetadata, |
||
| 72 | array('fields' => 'id') |
||
| 73 | ); |
||
| 74 | |||
| 75 | $request_albums_photo = $fb->get($data['albumId'] ."/photos?fields=images&limit=100", $data['accessToken']); |
||
| 76 | $arr_alb = $request_albums_photo->getGraphEdge(); |
||
| 77 | $i = 0; |
||
| 78 | $resultAlbum = self::getAlbum($fb, $arr_alb, $i); |
||
| 79 | |||
| 80 | $count = 1; |
||
| 81 | foreach ($resultAlbum as $images) { |
||
| 82 | $url = $images['images']; |
||
| 83 | $img = $count.".jpeg"; |
||
| 84 | $folderId = $SubFolder->id; |
||
| 85 | $fileMetadata = new Google_Service_Drive_DriveFile( |
||
| 86 | array( |
||
| 87 | 'name' => $img, |
||
| 88 | 'parents' => array($folderId)) |
||
| 89 | ); |
||
| 90 | try { |
||
| 91 | $fileContent = file_get_contents($url); |
||
| 92 | $file = $drive->files->create( |
||
| 93 | $fileMetadata, |
||
| 94 | array( |
||
| 95 | 'data' => $fileContent, 'mimeType' => 'image/jpeg', |
||
| 96 | 'uploadType' => 'multipart', 'fields' => 'id') |
||
| 97 | ); |
||
| 98 | }catch (Exception $e) { |
||
| 99 | print "An error occurred: " . $e->getMessage(); |
||
| 100 | } |
||
| 101 | |||
| 102 | $count++; |
||
| 103 | } |
||
| 104 | $main_arr = array(); |
||
| 105 | } |
||
| 124 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.