Issues (231)

src/services/ServicesTrait.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * SEOmatic plugin for Craft CMS
4
 *
5
 * A turnkey SEO implementation for Craft CMS that is comprehensive, powerful,
6
 * and flexible
7
 *
8
 * @link      https://nystudio107.com
9
 * @copyright Copyright (c) 2022 nystudio107
10
 */
11
12
namespace nystudio107\seomatic\services;
13
14
use craft\helpers\ArrayHelper;
15
use nystudio107\pluginvite\services\VitePluginService;
16
use nystudio107\seomatic\assetbundles\seomatic\SeomaticAsset;
17
use nystudio107\seomatic\services\FrontendTemplates as FrontendTemplatesService;
18
use nystudio107\seomatic\services\Helper as HelperService;
19
use nystudio107\seomatic\services\JsonLd as JsonLdService;
20
use nystudio107\seomatic\services\Link as LinkService;
21
use nystudio107\seomatic\services\MetaBundles as MetaBundlesService;
22
use nystudio107\seomatic\services\MetaContainers as MetaContainersService;
23
use nystudio107\seomatic\services\Script as ScriptService;
24
use nystudio107\seomatic\services\SeoElements as SeoElementsService;
25
use nystudio107\seomatic\services\Sitemaps as SitemapsService;
26
use nystudio107\seomatic\services\Tag as TagService;
27
use nystudio107\seomatic\services\Title as TitleService;
28
use yii\base\InvalidConfigException;
29
30
/**
31
 * @author    nystudio107
32
 * @package   Seomatic
33
 * @since     3.4.38
34
 *
35
 * @property FrontendTemplatesService $frontendTemplates
36
 * @property HelperService $helper
37
 * @property JsonLdService $jsonLd
38
 * @property LinkService $link
39
 * @property MetaBundlesService $metaBundles
40
 * @property MetaContainersService $metaContainers
41
 * @property ScriptService $script
42
 * @property SeoElementsService $seoElements
43
 * @property SitemapsService $sitemaps
44
 * @property TagService $tag
45
 * @property TitleService $title
46
 * @property VitePluginService $vite
47
 */
48
trait ServicesTrait
49
{
50
    // Public Methods
51
    // =========================================================================
52
53
    /**
54
     * @inheritdoc
55
     */
56
    public function __construct($id, $parent = null, array $config = [])
57
    {
58
        // Constants aren't allowed in traits until PHP >= 8.2
59
        $majorVersion = '3';
60
        // Dev server container name & port are based on the major version of this plugin
61
        $devPort = 3000 + (int)$majorVersion;
62
        $versionName = 'v' . $majorVersion;
63
        // Merge in the passed config, so it our config can be overridden by Plugins::pluginConfigs['vite']
64
        // ref: https://github.com/craftcms/cms/issues/1989
65
        $config = ArrayHelper::merge([
66
            'components' => [
67
                'frontendTemplates' => FrontendTemplatesService::class,
68
                'helper' => HelperService::class,
69
                'jsonLd' => JsonLdService::class,
70
                'link' => LinkService::class,
71
                'metaBundles' => MetaBundlesService::class,
72
                'metaContainers' => MetaContainersService::class,
73
                'script' => ScriptService::class,
74
                'seoElements' => SeoElementsService::class,
75
                'sitemaps' => SitemapsService::class,
76
                'tag' => TagService::class,
77
                'title' => TitleService::class,
78
                // Register the vite service
79
                'vite' => [
80
                    'assetClass' => SeomaticAsset::class,
81
                    'checkDevServer' => true,
82
                    'class' => VitePluginService::class,
83
                    'devServerInternal' => 'http://craft-seomatic-' . $versionName . '-buildchain-dev:' . $devPort,
84
                    'devServerPublic' => 'http://localhost:' . $devPort,
85
                    'errorEntry' => 'src/js/seomatic.js',
86
                    'useDevServer' => true,
87
                ],
88
            ],
89
        ], $config);
90
91
        parent::__construct($id, $parent, $config);
92
    }
93
94
    /**
95
     * Returns the frontendTemplates service
96
     *
97
     * @return FrontendTemplatesService The frontendTemplates service
98
     * @throws InvalidConfigException
99
     */
100
    public function getFrontendTemplates(): FrontendTemplatesService
101
    {
102
        return $this->get('frontendTemplates');
0 ignored issues
show
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

102
        return $this->/** @scrutinizer ignore-call */ get('frontendTemplates');
Loading history...
103
    }
104
105
    /**
106
     * Returns the helper service
107
     *
108
     * @return HelperService The helper service
109
     * @throws InvalidConfigException
110
     */
111
    public function getHelper(): HelperService
112
    {
113
        return $this->get('helper');
114
    }
115
116
    /**
117
     * Returns the jsonLd service
118
     *
119
     * @return JsonLdService The jsonLd service
120
     * @throws InvalidConfigException
121
     */
122
    public function getJsonLd(): JsonLdService
123
    {
124
        return $this->get('jsonLd');
125
    }
126
127
    /**
128
     * Returns the link service
129
     *
130
     * @return LinkService The link service
131
     * @throws InvalidConfigException
132
     */
133
    public function getLink(): LinkService
134
    {
135
        return $this->get('link');
136
    }
137
138
    /**
139
     * Returns the metaBundles service
140
     *
141
     * @return MetaBundlesService The metaBundles service
142
     * @throws InvalidConfigException
143
     */
144
    public function getMetaBundles(): MetaBundlesService
145
    {
146
        return $this->get('metaBundles');
147
    }
148
149
    /**
150
     * Returns the metaContainers service
151
     *
152
     * @return MetaContainersService The metaContainers service
153
     * @throws InvalidConfigException
154
     */
155
    public function getMetaContainers(): MetaContainersService
156
    {
157
        return $this->get('metaContainers');
158
    }
159
160
    /**
161
     * Returns the script service
162
     *
163
     * @return ScriptService The script service
164
     * @throws InvalidConfigException
165
     */
166
    public function getScript(): ScriptService
167
    {
168
        return $this->get('script');
169
    }
170
171
    /**
172
     * Returns the seoElements service
173
     *
174
     * @return SeoElementsService The seoElements service
175
     * @throws InvalidConfigException
176
     */
177
    public function getSeoElements(): SeoElementsService
178
    {
179
        return $this->get('seoElements');
180
    }
181
182
    /**
183
     * Returns the sitemaps service
184
     *
185
     * @return SitemapsService The sitemaps service
186
     * @throws InvalidConfigException
187
     */
188
    public function getSitemaps(): SitemapsService
189
    {
190
        return $this->get('sitemaps');
191
    }
192
193
    /**
194
     * Returns the tag service
195
     *
196
     * @return TagService The tag service
197
     * @throws InvalidConfigException
198
     */
199
    public function getTag(): TagService
200
    {
201
        return $this->get('tag');
202
    }
203
204
    /**
205
     * Returns the title service
206
     *
207
     * @return TitleService The title service
208
     * @throws InvalidConfigException
209
     */
210
    public function getTitle(): TitleService
211
    {
212
        return $this->get('title');
213
    }
214
215
    /**
216
     * Returns the vite service
217
     *
218
     * @return VitePluginService The vite service
219
     * @throws InvalidConfigException
220
     */
221
    public function getVite(): VitePluginService
222
    {
223
        return $this->get('vite');
224
    }
225
}
226