Post   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 68
loc 68
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A send() 20 20 2
A getAll() 22 22 1
A getRelations() 4 4 1
A getFollows() 4 4 1
A getComments() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Integrations\Connectors\Googledrive;
4
5
use Log;
6
use App\Models\User;
7
8 View Code Duplication
class Post extends Googledrive
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    
11
    public function __construct()
12
    {
13
        
14
    }
15
16
    public function send($component, $text = 'Hello word')
17
    {
18
        try {
19
            // The most basic upload command, if you're sure that your photo file is
20
            // valid on Googledrive (that it fits all requirements), is the following:
21
            // $ig->timeline->uploadPhoto($photoFilename, ['caption' => $text]);
22
            // However, if you want to guarantee that the file is valid (correct format,
23
            // width, height and aspect ratio), then you can run it through our
24
            // automatic photo processing class. It is pretty fast, and only does any
25
            // work when the input file is invalid, so you may want to always use it.
26
            // You have nothing to worry about, since the class uses temporary files if
27
            // the input needs processing, and it never overwrites your original file.
28
            //
29
            // Also note that it has lots of options, so read its class documentation!
30
            $photo = new \GoogledriveAPI\Media\Photo\GoogledrivePhoto($component->getTarget());
31
            $this->getConnection()->timeline->uploadPhoto($photo->getFile(), ['caption' => $text]);
32
        } catch (\Exception $e) {
33
            echo 'Something went wrong: '.$e->getMessage()."\n";
34
        }
35
    }
36
37
    public function getAll()
38
    {
39
        $instagram = $this->getConnection()->likeMedia();
40
41
        // set user's accesstoken (can be received after authentication)
42
        $instagram->setAccessToken("2823787.9687902.21u77429n3r79o08233122306fa78902");
43
44
        // follow user (snoopdogg)
45
        $instagram->modifyRelationship('follow', $component->getReference());
0 ignored issues
show
Bug introduced by
The variable $component does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
46
47
        // receive the list of users this user follows
48
        $follows = $instagram->getUserFollows();
49
50
        // dump response object
51
        echo '<pre>';
52
        print_r($follows);
53
        echo '<pre>';
54
55
        
56
        
57
        $result = $this->getConnection()->likeMedia($component->getReference());
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
58
    }
59
60
    public function getRelations()
61
    {
62
        $this->getFollows();
63
    }
64
65
    protected function getFollows()
66
    {
67
68
    }
69
70
    protected function getComments()
71
    {
72
73
    }
74
75
}
76