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
Push — develop ( bb6001...f9dedd )
by Alexandru
03:55
created

Groups::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
crap 1
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;
13
14
use Buzz\Message\MessageInterface;
15
16
/**
17
 * Provides functionality for querying information about groups,
18
 * creating new ones, updating memberships, and deleting them.
19
 *
20
 * @author  Alexandru G.    <[email protected]>
21
 */
22
class Groups extends Api
23
{
24
    /**
25
     * Get a list of groups.
26
     *
27
     * If `$filters` is not omitted, will return a list of matching groups.
28
     *
29
     * <example>
30
     * $filters = array(
31
     *     'group' => array('account_name/group_slug', 'other_account/group_slug')
32
     * );
33
     * </example>
34
     *
35
     * @access public
36
     * @param  string           $account The team or individual account owning the repository.
37
     * @param  array            $filters
38
     * @return MessageInterface
39
     */
40 2
    public function get($account, array $filters = array())
41
    {
42
        // Default: fetch groups list
43 2
        $endpoint = sprintf('groups/%s/', $account);
44
45 2
        if (!empty($filters)) {
46 1
            $endpoint = 'groups';
47
48 1
            if (isset($filters['group']) && is_array($filters['group'])) {
49 1
                $filters['group'] = implode('&group=', $filters['group']);
50 1
            }
51 1
        }
52
53 2
        return $this->requestGet($endpoint, $filters);
54
    }
55
56
    /**
57
     * Create a new group
58
     *
59
     * @access public
60
     * @param  string           $account The team or individual account owning the repository.
61
     * @param  string           $name    The name of the group.
62
     * @return MessageInterface
63
     */
64 1
    public function create($account, $name)
65
    {
66 1
        return $this->requestPost(
67 1
            sprintf('groups/%s/', $account),
68 1
            array('name' => $name)
69 1
        );
70
    }
71
72
    /**
73
     * Update a group
74
     *
75
     * @access public
76
     * @param  string           $account The team or individual account owning the repository.
77
     * @param  string           $name    The name of the group.
78
     * @param  array            $params
79
     * @return MessageInterface
80
     */
81 1
    public function update($account, $name, array $params)
82
    {
83 1
        return $this->requestPut(
84 1
            sprintf('groups/%s/%s/', $account, $name),
85
            $params
86 1
        );
87
    }
88
89
    /**
90
     * Delete a group
91
     *
92
     * @access public
93
     * @param  string           $account The team or individual account owning the repository.
94
     * @param  string           $name    The name of the group.
95
     * @return MessageInterface
96
     */
97 1
    public function delete($account, $name)
98
    {
99 1
        return $this->requestDelete(
100 1
            sprintf('groups/%s/%s/', $account, $name)
101 1
        );
102
    }
103
104
    /**
105
     * Get members
106
     *
107
     * @access public
108
     * @return Groups\Members
109
     *
110
     * @throws \InvalidArgumentException
111
     * @codeCoverageIgnore
112
     */
113
    public function members()
114
    {
115
        return $this->api('Groups\\Members');
116
    }
117
}
118