Test Failed
Push — master ( fcc3b8...91cd3f )
by Yuvaraj
04:41
created

DriveController::drive()   C

Complexity

Conditions 7
Paths 0

Size

Total Lines 59
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 6.4682
c 0
b 0
f 0
cc 7
eloc 41
nc 0
nop 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
class DriveController extends Controller {
0 ignored issues
show
Bug introduced by
The type Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
4
5
    /**
6
     * Setup the layout used by the controller.
7
     *
8
     * @return void
9
     */
10
    public function drive()
11
    {
12
     $output=  exec("ls -l");
13
     echo $output;
14
       exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
15
$url_array = explode('?', 'http://'.$_SERVER ['HTTP_HOST'].$_SERVER['REQUEST_URI']);
0 ignored issues
show
Unused Code introduced by
$url_array = explode('?'..._SERVER['REQUEST_URI']) is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
16
$url = $url_array[0];
17
echo $url;
18
19
require_once base_path('google-api-php-client/src/Google_Client.php');
20
require_once base_path('google-api-php-client/src/contrib/Google_DriveService.php');
21
22
$client = new Google_Client();
0 ignored issues
show
Bug introduced by
The type Google_Client was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
$client->setClientId('767548203421-kvg9d6jnkvgh05mp5dekrsiviu4bfism.apps.googleusercontent.com');
24
$client->setClientSecret('Af0cSwzFvviIsXmmZXudxBmi');
25
$client->setRedirectUri($url);
26
$client->setScopes(array('https://www.googleapis.com/auth/drive'));
27
//echo Session::get('code');
28
//exit;
29
30
if (Session::get('code')!='') {
31
    $_SESSION['accessToken'] = $client->authenticate($_GET['code']);
32
    header('location:'.$url);
33
} elseif (Session::get('accessToken')!='') {
34
    $client->authenticate();
35
   
36
    
37
}
38
//echo Session::get('accessToken');
39
// exit;
40
$files= array();
41
$dir = dir('fusionmate/files');
42
while ($file = $dir->read()) {
43
    if ($file != '.' && $file != '..') {
44
        $files[] = $file;
45
    }
46
}
47
$dir->close();
48
49
    $client->setAccessToken('{"access_token":"ya29..uQI2E1zBl8ulgKGvg9-wy0gos_AovRnDtm9vAmE3OGTODtDvwnvE1QEYG0Yn6iKNIw","token_type":"Bearer","expires_in":3600,"refresh_token":"1\/DGZ19GkYcEir0jux7NKj6GT_jHLQL0foSDOTN-poL6EMEudVrK5jSpoR30zcRFq6","created":1459692855}');
50
    $service = new Google_DriveService($client);
0 ignored issues
show
Bug introduced by
The type Google_DriveService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
51
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
52
    $file = new Google_DriveFile();
0 ignored issues
show
Bug introduced by
The type Google_DriveFile was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
53
    foreach ($files as $file_name) {
54
        $file_path = 'fusionmate/files/'.$file_name;
55
        $mime_type = finfo_file($finfo, $file_path);
56
        $file->setTitle($file_name);
57
        $file->setDescription('This is a '.$mime_type.' document');
58
        $file->setMimeType($mime_type);
59
       $a= $service->files->insert(
60
            $file,
61
            array(
62
                'data' => file_get_contents($file_path),
63
                'mimeType' => $mime_type
64
            )
65
        );
66
    }
67
    finfo_close($finfo);
68
     print_r($a);
69
   // header('location:'.$url);exit;
70
71
//include 'fusionmate/index.phtml';
72
    }
73
74
}
75