Passed
Push — master ( ffa8d9...6a6a4c )
by Paul
03:54
created

Multilingual   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 18
dl 0
loc 47
ccs 0
cts 29
cp 0
rs 10
c 1
b 1
f 0
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 6 3
A getIntegration() 0 11 3
A isIntegrated() 0 10 3
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules;
4
5
use GeminiLabs\SiteReviews\Database\OptionManager;
6
use GeminiLabs\SiteReviews\Helpers\Arr;
7
8
/**
9
 * @method \WP_Post|void|null getPost(int|string $postId)
10
 * @method array getPostIds(array $postIds)
11
 * @method bool isActive()
12
 * @method bool isEnabled()
13
 * @method bool isSupported()
14
 */
15
class Multilingual
16
{
17
    protected $integration;
18
19
    /**
20
     * @param string $method
21
     * @param array $args
22
     * @return 
23
     */
24
    public function __call($method, $args = [])
25
    {
26
        if ($this->isIntegrated() && method_exists($this->integration, $method)) {
27
            return call_user_func_array([$this->integration, $method], $args);
28
        }
29
        return Arr::get($args, 0, false);
30
    }
31
32
    /**
33
     * @param string $integration
34
     * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml
35
     */
36
    public function getIntegration($integration = '')
37
    {
38
        if (empty($integration)) {
39
            $integration = ucfirst(glsr(OptionManager::class)->get('settings.general.multilingual'));
40
        }
41
        $integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.$integration;
42
        if (class_exists($integrationClass)) {
43
            return glsr($integrationClass);
1 ignored issue
show
Bug Best Practice introduced by
The expression return glsr($integrationClass) also could return the type GeminiLabs\SiteReviews\Application which is incompatible with the documented return type GeminiLabs\SiteReviews\M...Multilingual\Wpml|false.
Loading history...
44
        }
45
        glsr_log()->error($integrationClass.' does not exist');
46
        return false;
47
    }
48
49
    /**
50
     * return bool
51
     */
52
    public function isIntegrated()
53
    {
54
        if (!empty($this->integration)) {
55
            return true;
56
        }
57
        if ($integration = $this->getIntegration()) {
58
            $this->integration = $integration;
59
            return true;
60
        }
61
        return false;
62
    }
63
}
64