Blobs::createBlob()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
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
}