Completed
Push — master ( 23650d...b8cfa5 )
by Jignesh
01:07
created

initExtra::initIsConnect()   B

Complexity

Conditions 6
Paths 7

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 7
nop 0
dl 0
loc 40
rs 8.6577
c 0
b 0
f 0
1
<?php
2
3
4
namespace JoisarJignesh\Bigbluebutton\Services;
5
6
7
use BigBlueButton\Parameters\IsMeetingRunningParameters;
8
9
trait initExtra
10
{
11
    /**
12
     * Check if connection to api can be established with the end point url and secret
13
     *
14
     * @return array connection successful
15
     */
16
    private function initIsConnect()
17
    {
18
        if (!filter_var(config('bigbluebutton.BBB_SERVER_BASE_URL'), FILTER_VALIDATE_URL)) {
19
            return [
20
                'flag'    => false,
21
                'message' => 'invalid url'
22
            ];
23
        }
24
25
        try {
26
            $response = $this->bbb->isMeetingRunning(
0 ignored issues
show
Bug introduced by
The property bbb does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
                new IsMeetingRunningParameters('connection_check')
28
            );
29
30
            // url and secret working
31
            if ($response->success()) {
32
                return ['flag' => true];
33
            }
34
35
            // Checksum error - invalid secret
36
            if ($response->failed() && $response->getMessageKey() == "checksumError") {
37
                return [
38
                    'flag'    => false,
39
                    'message' => 'invalid secret key'
40
                ];
41
            }
42
43
            // HTTP exception or XML parse
44
        } catch (\Exception $e) {
45
            return [
46
                'flag'    => false,
47
                'message' => 'invalid url and secret key'
48
            ];
49
        }
50
51
        return [
52
            'flag'    => false,
53
            'message' => 'invalid url'
54
        ];
55
    }
56
}
57