Passed
Push — master ( 7f1e4d...e207fc )
by Paul
04:01
created

Multilingual::getIntegration()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 3
eloc 6
nc 4
nop 1
dl 0
loc 10
ccs 0
cts 10
cp 0
crap 12
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
        return false;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function getPost($postId)
32
    {
33
        return $this->isIntegrated()
34
            ? $this->integration->getPostIds($postId)
35
            : $postId;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getPostIds(array $postIds)
42
    {
43
        return $this->isIntegrated()
44
            ? $this->integration->getPostIds($postIds)
45
            : $postIds;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function isActive()
52
    {
53
        return $this->isIntegrated()
54
            ? $this->integration->isActive()
55
            : false;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function isEnabled()
62
    {
63
        return $this->isIntegrated()
64
            ? $this->integration->isEnabled()
65
            : false;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function isSupported()
72
    {
73
        return $this->isIntegrated()
74
            ? $this->integration->isSupported()
75
            : false;
76
    }
77
78
    /**
79
     * return bool
80
     */
81
    protected function isIntegrated()
82
    {
83
        if (!empty($this->integration)) {
84
            return true;
85
        }
86
        if ($integration = $this->getIntegration()) {
87
            $this->integration = $integration;
88
            return true;
89
        }
90
        glsr_log()->error($integrationClass.' does not exist');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $integrationClass does not exist. Did you maybe mean $integration?
Loading history...
91
        return false;
92
    }
93
}
94