Passed
Push — master ( ac4e16...62cea4 )
by Paul
04:17
created

Multilingual::isActive()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 6
rs 10
c 1
b 1
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules;
4
5
use GeminiLabs\SiteReviews\Contracts\MultilingualContract as Contract;
6
use GeminiLabs\SiteReviews\Database\OptionManager;
7
8
class Multilingual implements Contract
9
{
10
    protected $integration;
11
12
    /**
13
     * @param string $integration
14
     * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml
15
     */
16
    public function getIntegration($integration = '')
17
    {
18
        if (empty($integration)) {
19
            $integration = ucfirst(glsr(OptionManager::class)->get('settings.general.multilingual'));
20
        }
21
        $integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.$integration;
22
        if (class_exists($integrationClass)) {
23
            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...
24
        }
25
        glsr_log()->error($integrationClass.' does not exist');
26
        return false;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function getPost($postId)
33
    {
34
        return $this->isIntegrated()
35
            ? $this->integration->getPostIds($postId)
36
            : $postId;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getPostIds(array $postIds)
43
    {
44
        return $this->isIntegrated()
45
            ? $this->integration->getPostIds($postIds)
46
            : $postIds;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function isActive()
53
    {
54
        return $this->isIntegrated()
55
            ? $this->integration->isActive()
56
            : false;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function isEnabled()
63
    {
64
        return $this->isIntegrated()
65
            ? $this->integration->isEnabled()
66
            : false;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function isSupported()
73
    {
74
        return $this->isIntegrated()
75
            ? $this->integration->isSupported()
76
            : false;
77
    }
78
79
    /**
80
     * return bool
81
     */
82
    protected function isIntegrated()
83
    {
84
        if (!empty($this->integration)) {
85
            return true;
86
        }
87
        if ($integration = $this->getIntegration()) {
88
            $this->integration = $integration;
89
            return true;
90
        }
91
        return false;
92
    }
93
}
94