Notification Setup Error

We have detected an error in your notification set-up (Event-ID dab39dc24f564ec7bd4628d1305fd03c). Currently, we cannot inform you about inspection progress. Please check that the user 557058:bca11929-8c2d-43f2-8a82-c5416880d395 still has access to your repository or update the API account.

Completed
Pull Request — master ( #42 )
by
unknown
14:21
created

Src::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 0
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 6
1
<?php
2
3
/**
4
 * This file is part of the bitbucket-api package.
5
 *
6
 * (c) Alexandru G. <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Bitbucket\API\Repositories;
13
14
use Bitbucket\API;
15
use Buzz\Message\MessageInterface;
16
17
/**
18
 * Allows you to browse directories and view files.
19
 *
20
 * NOTE: This is read-only!
21
 *
22
 * @author  Alexandru G.    <[email protected]>
23
 */
24
class Src extends API\Api
25
{
26
    /**
27
     * Get a list of repo source
28
     *
29
     * @access public
30
     * @param  string           $account  The team or individual account owning the repository.
31
     * @param  string           $repo     The repository identifier.
32
     * @param  string           $revision A value representing the revision or branch to list.
33
     * @param  string           $path     The path can be a filename or a directory path.
34
     * @return MessageInterface
35
     */
36 1
    public function get($account, $repo, $revision, $path)
37
    {
38 1
        return $this->requestGet(
39 1
            sprintf('repositories/%s/%s/src/%s/%s', $account, $repo, $revision, $path)
40 1
        );
41
    }
42
43
    /**
44
     * Get raw content of an individual file
45
     *
46
     * @access public
47
     * @param  string           $account  The team or individual account owning the repository.
48
     * @param  string           $repo     The repository identifier.
49
     * @param  string           $revision A value representing the revision or branch to list.
50
     * @param  string           $path     The path can be a filename or a directory path.
51
     * @return MessageInterface
52
     */
53 1
    public function raw($account, $repo, $revision, $path)
54
    {
55 1
        return $this->requestGet(
56 1
            sprintf('repositories/%s/%s/raw/%s/%s', $account, $repo, $revision, $path)
57 1
        );
58
    }
59
60
    /**
61
     * Create file in repository
62
     *      $params contains the files to create, the key is the file (with path) to create and the value is the
63
     *      data that will be written to the file.
64
     *      See https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/src#post
65
     *      for details on what options are available
66
     * @param $account
67
     * @param $repo
68
     * @param array $params
69
     * @return MessageInterface
70
     */
71
    public function create($account, $repo, array $params = array())
72
    {
73
        $mandatory = array(
74
            'author'   => '',
75
            'message'  => '',
76
        );
77
78
        $diff = array_diff(array_keys($mandatory), array_keys($params));
79
80
        if (count($diff) > 0) {
81
            throw new \InvalidArgumentException('Missing parameters for creating new files.');
82
        }
83
84
        return $this->getClient()->setApiVersion('2.0')->post(
85
            sprintf('repositories/%s/%s/src', $account, $repo),
86
            $params
87
        );
88
    }
89
}
90