Completed
Push — develop ( 2f90e1...bffb25 )
by Kirill
07:59
created

Client::isFallbackMode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of GitterBot package.
4
 *
5
 * @author Serafim <[email protected]>
6
 * @date 28.01.2016 16:35
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace App\Gitter;
12
13
use Gitter\Client as BaseClient;
14
use App\Exceptions\GitterHandler;
15
use React\EventLoop\LoopInterface;
16
17
/**
18
 * Class Client
19
 * @package App\Gitter
20
 */
21
class Client extends BaseClient
22
{
23
    /**
24
     * @var bool
25
     */
26
    protected $fallbackMode = false;
27
28
    /**
29
     * @var array
30
     */
31
    protected $fallbackSubscribers = [];
32
33
    /**
34
     * Client constructor.
35
     * @param LoopInterface $loop
36
     * @param string $token
37
     */
38
    public function __construct(LoopInterface $loop, $token)
39
    {
40
        parent::__construct($loop, $token);
41
        $this->setErrorHandler(new GitterHandler());
42
    }
43
44
    /**
45
     * @param bool $value
46
     * @return $this
47
     */
48
    public function setFallbackMode(bool $value = true)
49
    {
50
        if ($this->fallbackMode !== $value) {
51
            foreach ($this->fallbackSubscribers as $subscriber) {
52
                $subscriber($value);
53
            }
54
        }
55
        $this->fallbackMode = $value;
56
        return $this;
57
    }
58
59
    /**
60
     * @return bool
61
     */
62
    public function isFallbackMode()
63
    {
64
        return $this->fallbackMode;
65
    }
66
67
    /**
68
     * @param \Closure $callback
69
     * @return $this
70
     */
71
    public function onChangeFallbackMode(\Closure $callback)
72
    {
73
        $this->fallbackSubscribers[] = $callback;
74
        return $this;
75
    }
76
}
77