Completed
Push — develop ( 3ac71a...ed5a59 )
by Josef
01:53
created

Block::blockTarget()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
namespace ritero\SDK\TwitchTV\Methods;
4
5
use ritero\SDK\TwitchTV\TwitchException;
6
use ritero\SDK\TwitchTV\TwitchRequest;
7
8
/**
9
 * TwitchTV API SDK for PHP
10
 *
11
 * Block method class
12
 *
13
 * @author Josef Ohnheiser <[email protected]>
14
 * @license https://github.com/jofner/Twitch-SDK/blob/master/LICENSE.md MIT
15
 * @homepage https://github.com/jofner/Twitch-SDK
16
 */
17 View Code Duplication
class Block
1 ignored issue
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...
18
{
19
    /** @var TwitchRequest */
20
    protected $request;
21
22
    const URI_BLOCK_USER = 'users/%s/blocks';
23
    const URI_BLOCK_TARGET = 'users/%s/blocks/%s';
24
25
    /**
26
     * Block constructor
27
     * @param TwitchRequest $request
28
     */
29
    public function __construct(TwitchRequest $request)
30
    {
31
        $this->request = $request;
32
    }
33
34
    /**
35
     * Returns a list of blocks
36
     *  - requires scope 'user_blocks_read'
37
     * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/blocks.md#get-usersuserblocks
38
     * @param string $user
39
     * @param string $queryString
40
     * @return \stdClass
41
     * @throws TwitchException
42
     */
43
    public function getBlocks($user, $queryString)
44
    {
45
        return $this->request->request(sprintf(self::URI_BLOCK_USER, $user) . $queryString);
46
    }
47
48
    /**
49
     * Adds $target to $user block list
50
     *  - requires scope 'user_blocks_edit'
51
     * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/blocks.md#put-usersuserblockstarget
52
     * @param string $user
53
     * @param string $target
54
     * @param string $queryString
55
     * @return \stdClass
56
     * @throws TwitchException
57
     */
58
    public function blockTarget($user, $target, $queryString)
59
    {
60
        return $this->request->request(sprintf(self::URI_BLOCK_TARGET, $user, $target) . $queryString, 'PUT');
61
    }
62
63
    /**
64
     * Removes $target from $user block list
65
     *  - requires scope 'user_blocks_edit'
66
     * @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/blocks.md#delete-usersuserblockstarget
67
     * @param string $user
68
     * @param string $target
69
     * @param string $queryString
70
     * @return \stdClass
71
     * @throws TwitchException
72
     */
73
    public function removeTarget($user, $target, $queryString)
74
    {
75
        return $this->request->request(sprintf(self::URI_BLOCK_TARGET, $user, $target) . $queryString, 'DELETE');
76
    }
77
}
78