Blobs   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 38
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getBlob() 5 5 1
A createBlob() 9 9 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
namespace FlexyProject\GitHub\Receiver\GitData;
3
4
use Symfony\Component\HttpFoundation\Request;
5
6
/**
7
 * The Blobs API class provides access to GitData's blobs.
8
 *
9
 * @link    https://developer.github.com/v3/git/blobs/
10
 * @package FlexyProject\GitHub\Receiver\GitData
11
 */
12 View Code Duplication
class Blobs extends AbstractGitData
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...
13
{
14
15
    /**
16
     * Get a Blob
17
     *
18
     * @link https://developer.github.com/v3/git/blobs/#get-a-blob
19
     *
20
     * @param string $sha
21
     *
22
     * @return array
23
     */
24
    public function getBlob(string $sha): array
25
    {
26
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/git/blobs/:sha',
27
            $this->getGitData()->getOwner(), $this->getGitData()->getRepo(), $sha));
28
    }
29
30
    /**
31
     * Create a Blob
32
     *
33
     * @link https://developer.github.com/v3/git/blobs/#create-a-blob
34
     *
35
     * @param string $content
36
     * @param string $encoding
37
     *
38
     * @return array
39
     */
40
    public function createBlob(string $content, string $encoding = 'utf-8'): array
41
    {
42
        return $this->getApi()->request($this->getApi()
43
                                             ->sprintf('/repos/:owner/:repo/git/blobs', $this->getGitData()->getOwner(),
44
                                                 $this->getGitData()->getRepo()), Request::METHOD_POST, [
45
                'content'  => $content,
46
                'encoding' => $encoding
47
            ]);
48
    }
49
}