Issues (45)

src/base/PluginTrait.php (4 issues)

1
<?php
2
/**
3
 * @link      https://dukt.net/twitter/
4
 * @copyright Copyright (c) Dukt
5
 * @license   https://github.com/dukt/twitter/blob/master/LICENSE.md
6
 */
7
8
namespace dukt\twitter\base;
9
10
use Craft;
11
use dukt\twitter\Plugin;
12
13
/**
14
 * PluginTrait implements the common methods and properties for plugin classes.
15
 *
16
 * @property \dukt\twitter\services\Twitter $twitter    The twitter service
17
 * @property \dukt\twitter\services\Api     $api        The api service
18
 * @property \dukt\twitter\services\Cache   $cache      The cache service
19
 * @property \dukt\twitter\services\Oauth   $oauth      The oauth service
20
 * @property \dukt\twitter\services\Publish $publish    The publish service
21
 */
22
trait PluginTrait
23
{
24
    /**
25
     * Returns the twitter service.
26
     *
27
     * @return \dukt\twitter\services\Twitter The twitter service
28
     */
29
    public function getTwitter()
30
    {
31
        /** @var Twitter $this */
32
        return $this->get('twitter');
33
    }
34
35
    /**
36
     * Returns the accounts service.
37
     *
38
     * @return \dukt\twitter\services\Accounts The accounts service
39
     */
40
    public function getAccounts()
41
    {
42
        /** @var Twitter $this */
43
        return $this->get('accounts');
44
    }
45
46
    /**
47
     * Returns the api service.
48
     *
49
     * @return \dukt\twitter\services\Api The api service
50
     */
51
    public function getApi()
52
    {
53
        /** @var Twitter $this */
54
        return $this->get('api');
55
    }
56
57
    /**
58
     * Returns the cache service.
59
     *
60
     * @return \dukt\twitter\services\Cache The cache service
61
     */
62
    public function getCache()
63
    {
64
        /** @var Twitter $this */
65
        return $this->get('cache');
66
    }
67
68
    /**
69
     * Returns the oauth service.
70
     *
71
     * @return \dukt\twitter\services\Oauth The oauth service
72
     */
73
    public function getOauth()
74
    {
75
        /** @var Twitter $this */
76
        return $this->get('oauth');
77
    }
78
79
    /**
80
     * Returns the publish service.
81
     *
82
     * @return \dukt\twitter\services\Publish The publish service
83
     */
84
    public function getPublish()
85
    {
86
        /** @var Twitter $this */
87
        return $this->get('publish');
88
    }
89
90
    /**
91
     * Gets the OAuth consumer key
92
     *
93
     * @param bool $parse
94
     * @return string|null
95
     */
96
    public function getConsumerKey(bool $parse = true)
97
    {
98
        $consumerKey = Plugin::$plugin->getSettings()->oauthConsumerKey;
99
100
        if (!$consumerKey) {
101
            return null;
102
        }
103
104
        return $parse ? Craft::parseEnv($consumerKey) : $consumerKey;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $parse ? Craft::p...umerKey) : $consumerKey also could return the type boolean which is incompatible with the documented return type null|string.
Loading history...
Deprecated Code introduced by
The function Craft::parseEnv() has been deprecated: in 3.7.29. [[App::parseEnv()]] should be used instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

104
        return $parse ? /** @scrutinizer ignore-deprecated */ Craft::parseEnv($consumerKey) : $consumerKey;

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
105
    }
106
107
    /**
108
     * Gets the OAuth consumer secret
109
     *
110
     * @param bool $parse
111
     * @return string|null
112
     */
113
    public function getConsumerSecret(bool $parse = true)
114
    {
115
        $consumerSecret = Plugin::$plugin->getSettings()->oauthConsumerSecret;
116
117
        if (!$consumerSecret) {
118
            return null;
119
        }
120
121
        return $parse ? Craft::parseEnv($consumerSecret) : $consumerSecret;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $parse ? Craft::p...cret) : $consumerSecret also could return the type boolean which is incompatible with the documented return type null|string.
Loading history...
Deprecated Code introduced by
The function Craft::parseEnv() has been deprecated: in 3.7.29. [[App::parseEnv()]] should be used instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

121
        return $parse ? /** @scrutinizer ignore-deprecated */ Craft::parseEnv($consumerSecret) : $consumerSecret;

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
122
    }
123
}
124