Issues (257)

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 nystudio107\pluginvite\services\VitePluginService;
15
use nystudio107\seomatic\assetbundles\seomatic\SeomaticAsset;
16
use nystudio107\seomatic\services\FrontendTemplates as FrontendTemplatesService;
17
use nystudio107\seomatic\services\Helper as HelperService;
18
use nystudio107\seomatic\services\JsonLd as JsonLdService;
19
use nystudio107\seomatic\services\Link as LinkService;
20
use nystudio107\seomatic\services\MetaBundles as MetaBundlesService;
21
use nystudio107\seomatic\services\MetaContainers as MetaContainersService;
22
use nystudio107\seomatic\services\Script as ScriptService;
23
use nystudio107\seomatic\services\SeoElements as SeoElementsService;
24
use nystudio107\seomatic\services\Sitemaps as SitemapsService;
25
use nystudio107\seomatic\services\Tag as TagService;
26
use nystudio107\seomatic\services\Title as TitleService;
27
use yii\base\InvalidConfigException;
28
29
/**
30
 * @author    nystudio107
31
 * @package   Seomatic
32
 * @since     4.0.8
33
 *
34
 * @property FrontendTemplatesService $frontendTemplates
35
 * @property HelperService $helper
36
 * @property JsonLdService $jsonLd
37
 * @property LinkService $link
38
 * @property MetaBundlesService $metaBundles
39
 * @property MetaContainersService $metaContainers
40
 * @property ScriptService $script
41
 * @property SeoElementsService $seoElements
42
 * @property SitemapsService $sitemaps
43
 * @property TagService $tag
44
 * @property TitleService $title
45
 * @property VitePluginService $vite
46
 */
47
trait ServicesTrait
48
{
49
    // Static Properties
50
    // =========================================================================
51
52
    public static ?string $majorVersion = '';
53
54
    // Static Methods
55
    // =========================================================================
56
57
    /**
58
     * @inheritdoc
59
     */
60
    public static function config(): array
61
    {
62
        // Constants aren't allowed in traits until PHP >= 8.2, and config() is called before __construct(),
63
        // so we can't extract it from the passed in $config
64
        $majorVersion = '5';
65
        // Dev server container name & port are based on the major version of this plugin
66
        $devPort = 3000 + (int)$majorVersion;
67
        $versionName = 'v' . $majorVersion;
68
        return [
69
            'components' => [
70
                'frontendTemplates' => FrontendTemplatesService::class,
71
                'helper' => HelperService::class,
72
                'jsonLd' => JsonLdService::class,
73
                'link' => LinkService::class,
74
                'metaBundles' => MetaBundlesService::class,
75
                'metaContainers' => MetaContainersService::class,
76
                'script' => ScriptService::class,
77
                'seoElements' => SeoElementsService::class,
78
                'sitemaps' => SitemapsService::class,
79
                'tag' => TagService::class,
80
                'title' => TitleService::class,
81
                // Register the vite service
82
                'vite' => [
83
                    'assetClass' => SeomaticAsset::class,
84
                    'checkDevServer' => true,
85
                    'class' => VitePluginService::class,
86
                    'devServerInternal' => 'http://craft-seomatic-' . $versionName . '-buildchain-dev:' . $devPort,
87
                    'devServerPublic' => 'http://localhost:' . $devPort,
88
                    'errorEntry' => 'src/js/seomatic.js',
89
                    'useDevServer' => true,
90
                ],
91
            ],
92
        ];
93
    }
94
95
    // Public Methods
96
    // =========================================================================
97
98
    /**
99
     * Returns the frontendTemplates service
100
     *
101
     * @return FrontendTemplatesService The frontendTemplates service
102
     * @throws InvalidConfigException
103
     */
104
    public function getFrontendTemplates(): FrontendTemplatesService
105
    {
106
        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

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