Commits::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
namespace FlexyProject\GitHub\Receiver\GitData;
3
4
use DateTime;
5
use Symfony\Component\HttpFoundation\Request;
6
7
/**
8
 * The Commits API class provides access to GitData's commits.
9
 *
10
 * @link    https://developer.github.com/v3/git/commits/
11
 * @package FlexyProject\GitHub\Receiver\GitData
12
 */
13
class Commits extends AbstractGitData
14
{
15
16
    /**
17
     * Get a Commit
18
     *
19
     * @link https://developer.github.com/v3/git/commits/#get-a-commit
20
     *
21
     * @param string $sha
22
     *
23
     * @return array
24
     */
25
    public function get(string $sha): array
26
    {
27
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/git/commits/:sha',
28
            $this->getGitData()->getOwner(), $this->getGitData()->getRepo(), $sha));
29
    }
30
31
    /**
32
     * Create a Commit
33
     *
34
     * @link https://developer.github.com/v3/git/commits/#create-a-commit
35
     *
36
     * @param string       $message
37
     * @param string       $tree
38
     * @param array|string $parents
39
     * @param string       $name
40
     * @param string       $email
41
     * @param string       $date
42
     *
43
     * @return array
44
     * @throws \Exception
45
     */
46
    public function create(string $message, string $tree, $parents, string $name = null, string $email = null,
47
                           string $date = 'now'): array
48
    {
49
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/git/commits',
50
            $this->getGitData()->getOwner(), $this->getGitData()->getRepo()), Request::METHOD_POST, [
51
                'message' => $message,
52
                'tree'    => $tree,
53
                'parents' => $parents,
54
                'name'    => $name,
55
                'email'   => $email,
56
                'date'    => (new DateTime($date))->format(DateTime::ATOM)
57
            ]);
58
    }
59
}