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.

Src::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 8
cts 8
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2
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 Psr\Http\Message\ResponseInterface;
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 raw content of an individual file, or the contents of a directory
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 ResponseInterface
35
     */
36 2
    public function get($account, $repo, $revision, $path)
37
    {
38 2
        return $this->getClient()->setApiVersion("2.0")->get(
39 2
            sprintf('/repositories/%s/%s/src/%s/%s', $account, $repo, $revision, $path)
40
        );
41
    }
42
43
    /**
44
     * Create file in repository
45
     *      $params contains the files to create, the key is the file (with path) to create and the value is the
46
     *      data that will be written to the file.
47
     *      See https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/src#post
48
     *      for details on what options are available
49
     * @param string $account
50
     * @param string $repo
51
     * @param array $params
52
     * @return ResponseInterface
53
     */
54 3
    public function create($account, $repo, array $params = array())
55
    {
56
        $mandatory = array(
57 3
            'author'   => '',
58
            'message'  => '',
59
        );
60
61 3
        $diff = array_diff(array_keys($mandatory), array_keys($params));
62
63 3
        if (count($diff) > 0) {
64 1
            throw new \InvalidArgumentException('Missing parameters for creating new files.');
65
        }
66
67 2
        return $this->getClient()->setApiVersion('2.0')->post(
68 2
            sprintf('/repositories/%s/%s/src', $account, $repo),
69 2
            $params
70
        );
71
    }
72
}
73