Rutube   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 10
c 5
b 0
f 0
lcom 1
cbo 5
dl 0
loc 111
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 3
A isAuthorized() 0 4 1
A isSecure() 0 4 1
A video() 0 4 1
A account() 0 4 1
A search() 0 4 1
A raw() 0 4 1
A getTransport() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Rutube PHP API Client package.
5
 *
6
 * (c) Rutube
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 Rutube;
13
14
use Rutube\Transports\DefaultTransport as Transport;
15
16
/**
17
 * Корневой класс работы с библиотекой
18
 *
19
 * @package Rutube
20
 */
21
class Rutube
22
{
23
    /**
24
     * Транспорт выполнения запроса к API
25
     *
26
     * @var Transport
27
     */
28
    protected $transport;
29
30
    /**
31
     * Признак выполнения запросов через https
32
     *
33
     * @var bool
34
     */
35
    protected $secure = false;
36
37
    /**
38
     * Инициализация
39
     *
40
     * @param string|null $username логин Rutube
41
     * @param string|null $password пароль
42
     * @param bool $secure Использовать https
43
     * @param string $host Домен API
44
     * @param string $transport Транспорт
45
     */
46
    public function __construct(
47
        $username = null,
48
        $password = null,
49
        $secure = true,
50
        $host = 'rutube.ru',
51
        $transport = 'httpful'
52
    ) {
53
        $this->secure = $secure;
54
        $this->transport = new Transport($transport, $secure, $host);
55
56
        if ($username !== null && $password !== null) {
57
            $this->transport->authorize($username, $password);
58
        }
59
    }
60
61
    /**
62
     * Авторизован ли пользователь
63
     *
64
     * @return bool
65
     */
66
    public function isAuthorized()
67
    {
68
        return $this->transport->hasToken();
69
    }
70
71
    /**
72
     * Используется ли безопасное соединение
73
     *
74
     * @return bool
75
     */
76
    public function isSecure()
77
    {
78
        return $this->transport->isSecure();
79
    }
80
81
82
    /**
83
     * Стартовая точка работы с видео
84
     *
85
     * @return Video
86
     */
87
    public function video()
88
    {
89
        return new Video($this->getTransport());
90
    }
91
92
    /**
93
     * Стартовая точка работы с аккаунтом
94
     *
95
     * @return Account
96
     */
97
    public function account()
98
    {
99
        return new Account($this->getTransport());
100
    }
101
102
    /**
103
     * Стартовая точка поиска через API
104
     *
105
     * @return Search
106
     */
107
    public function search()
108
    {
109
        return new Search($this->getTransport());
110
    }
111
112
    /**
113
     * Стартовая точка прямых запросов к Rutube
114
     *
115
     * @return Raw
116
     */
117
    public function raw()
118
    {
119
        return new Raw($this->getTransport());
120
    }
121
122
    /**
123
     * Возвращает текущий транспорт
124
     *
125
     * @return Transport
126
     */
127
    public function getTransport()
128
    {
129
        return $this->transport;
130
    }
131
}
132