Passed
Push — master ( 42c775...8465d2 )
by Matthew
06:09
created

LocatorControllerExtension::onBeforeInit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2.0023

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 24
ccs 11
cts 12
cp 0.9167
crap 2.0023
rs 9.8666
1
<?php
2
3
namespace Dynamic\Locator\React\Extensions;
4
5
use Dynamic\SilverStripeGeocoder\AddressDataExtension;
6
use Dynamic\SilverStripeGeocoder\GoogleGeocoder;
7
use SilverStripe\Admin\LeftAndMain;
8
use SilverStripe\Control\Director;
9
use SilverStripe\Control\HTTPResponse;
10
use SilverStripe\Core\Config\Config;
11
use SilverStripe\Core\Convert;
12
use SilverStripe\Core\Extension;
13
use SilverStripe\Core\Injector\Injector;
14
use SilverStripe\Core\Manifest\ModuleResourceLoader;
15
use SilverStripe\Forms\Schema\FormSchema;
16
use SilverStripe\Security\SecurityToken;
17
use SilverStripe\View\Requirements;
18
use SilverStripe\View\SSViewer;
19
use SilverStripe\View\ThemeResourceLoader;
20
21
/**
22
 * Class LocatorControllerExtension
23
 * @package Dynamic\Locator\React\Extensions
24
 *
25
 * @property \Dynamic\Locator\LocatorController|LocatorControllerExtension|LocatorExtension $owner
26
 */
27
class LocatorControllerExtension extends Extension
28
{
29
30
    /**
31
     * @var array
32
     */
33
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
34
        'schema',
35
    ];
36
37
    /**
38
     * @var array
39
     */
40
    private static $dependencies = [
0 ignored issues
show
introduced by
The private property $dependencies is not used, and could be removed.
Loading history...
41
        'FormSchema' => '%$' . FormSchema::class,
42
    ];
43
44
    /**
45
     * Current form schema helper
46
     *
47
     * @var FormSchema
48
     */
49
    protected $schema = null;
50
51
    /**
52
     * Get form schema helper
53
     *
54
     * @return FormSchema
55
     */
56 3
    public function getFormSchema()
57
    {
58 3
        return $this->schema;
59
    }
60
61
    /**
62
     * Set form schema helper for this controller
63
     *
64
     * @param FormSchema $schema
65
     * @return $this
66
     */
67 3
    public function setFormSchema(FormSchema $schema)
68
    {
69 3
        $this->schema = $schema;
70 3
        return $this;
71
    }
72
73
    /**
74
     *
75
     */
76 1
    public function onBeforeInit()
77
    {
78
        // stops script from loading
79 1
        Requirements::block('jquery-locator');
80
81
        // google maps api key
82 1
        $key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key');
83 1
        if (!$this->owner->Autocomplete) {
0 ignored issues
show
Bug Best Practice introduced by
The property Autocomplete does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. Did you maybe forget to declare it?
Loading history...
84
            Requirements::javascript("https://maps.google.com/maps/api/js?key={$key}");
85
        } else {
86 1
            Requirements::block("https://maps.google.com/maps/api/js?key={$key}");
87 1
            Requirements::javascript("https://maps.google.com/maps/api/js?key={$key}&libraries=places");
88
        }
89
90
        // require i18n translation stuff
91 1
        Requirements::javascript('silverstripe/admin: client/dist/js/i18n.js');
92 1
        Requirements::add_i18n_javascript('dynamic/silverstripe-locator-react: client/lang');
0 ignored issues
show
Deprecated Code introduced by
The function SilverStripe\View\Requir...::add_i18n_javascript() has been deprecated. ( Ignorable by Annotation )

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

92
        /** @scrutinizer ignore-deprecated */ Requirements::add_i18n_javascript('dynamic/silverstripe-locator-react: client/lang');
Loading history...
93
94 1
        Requirements::customScript("
95
            window.ss = window.ss || {};
96 1
            window.ss.config = " . $this->owner->getClientConfig() . ";
0 ignored issues
show
Bug introduced by
The method getClientConfig() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

96
            window.ss.config = " . $this->owner->/** @scrutinizer ignore-call */ getClientConfig() . ";

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
97
        ");
98
99 1
        $this->owner->customScript();
0 ignored issues
show
Bug introduced by
The method customScript() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

99
        $this->owner->/** @scrutinizer ignore-call */ 
100
                      customScript();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
100
    }
101
102
    /**
103
     * Generates the custom script for settings
104
     */
105 2
    public function customScript()
106
    {
107 2
        $radii = $this->owner->getShowRadius() ? $this->owner->getRadii() : [];
0 ignored issues
show
Bug introduced by
The method getRadii() does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. ( Ignorable by Annotation )

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

107
        $radii = $this->owner->getShowRadius() ? $this->owner->/** @scrutinizer ignore-call */ getRadii() : [];

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getShowRadius() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

107
        $radii = $this->owner->/** @scrutinizer ignore-call */ getShowRadius() ? $this->owner->getRadii() : [];

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getShowRadius() does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. ( Ignorable by Annotation )

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

107
        $radii = $this->owner->/** @scrutinizer ignore-call */ getShowRadius() ? $this->owner->getRadii() : [];

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getRadii() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

107
        $radii = $this->owner->getShowRadius() ? $this->owner->/** @scrutinizer ignore-call */ getRadii() : [];

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
108 2
        $radiiString = json_encode($radii);
109
110 2
        $categories = $this->owner->getUsedCategories();
0 ignored issues
show
Bug introduced by
The method getUsedCategories() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

110
        /** @scrutinizer ignore-call */ 
111
        $categories = $this->owner->getUsedCategories();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getUsedCategories() does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. ( Ignorable by Annotation )

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

110
        /** @scrutinizer ignore-call */ 
111
        $categories = $this->owner->getUsedCategories();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
111 2
        $categoriesString = $this->owner->categoriesString($categories);
0 ignored issues
show
Bug introduced by
The method categoriesString() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

111
        /** @scrutinizer ignore-call */ 
112
        $categoriesString = $this->owner->categoriesString($categories);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
112
113 2
        $unit = $this->owner->Unit ? $this->owner->Unit : 'm';
0 ignored issues
show
Bug Best Practice introduced by
The property Unit does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. Did you maybe forget to declare it?
Loading history...
Bug introduced by
The property Unit does not seem to exist on Dynamic\Locator\React\Extensions\LocatorExtension.
Loading history...
114
        // otherwise this is 0 or 1
115 2
        $clusters = $this->owner->Clusters ? 'true' : 'false';
0 ignored issues
show
Bug Best Practice introduced by
The property Clusters does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. Did you maybe forget to declare it?
Loading history...
116 2
        $autocomplete = $this->owner->Autocomplete ? 'true' : 'false';
0 ignored issues
show
Bug Best Practice introduced by
The property Autocomplete does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. Did you maybe forget to declare it?
Loading history...
117
118 2
        $stylePath = ModuleResourceLoader::singleton()->resolveURL(
119 2
            $this->owner->getMapStyle()
0 ignored issues
show
Bug introduced by
The method getMapStyle() does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. ( Ignorable by Annotation )

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

119
            $this->owner->/** @scrutinizer ignore-call */ 
120
                          getMapStyle()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getMapStyle() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

119
            $this->owner->/** @scrutinizer ignore-call */ 
120
                          getMapStyle()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
120
        );
121 2
        $searchMarkerIconPath = $this->owner->getSearchIconImage();
0 ignored issues
show
Bug introduced by
The method getSearchIconImage() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

121
        /** @scrutinizer ignore-call */ 
122
        $searchMarkerIconPath = $this->owner->getSearchIconImage();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
122 2
        $markerIconPath = AddressDataExtension::getIconImage(true);
123
124 2
        if ($this->owner->SearchMarkerImageID) {
0 ignored issues
show
Bug Best Practice introduced by
The property SearchMarkerImageID does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. Did you maybe forget to declare it?
Loading history...
125
            $searchMarkerIconPath = $this->owner->SearchMarkerImage()->URL;
0 ignored issues
show
Bug introduced by
The method SearchMarkerImage() does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. ( Ignorable by Annotation )

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

125
            $searchMarkerIconPath = $this->owner->/** @scrutinizer ignore-call */ SearchMarkerImage()->URL;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
126
        }
127 2
        if ($this->owner->DefaultMarkerImageID) {
0 ignored issues
show
Bug Best Practice introduced by
The property DefaultMarkerImageID does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. Did you maybe forget to declare it?
Loading history...
128
            $markerIconPath = $this->owner->DefaultMarkerImage()->URL;
0 ignored issues
show
Bug introduced by
The method DefaultMarkerImage() does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. ( Ignorable by Annotation )

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

128
            $markerIconPath = $this->owner->/** @scrutinizer ignore-call */ DefaultMarkerImage()->URL;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
129
        }
130
131 2
        $clusterImages = json_encode($this->getClusterImages());
132
133
        // force to float
134 2
        $defaultLat = (float)$this->owner->DefaultLat;
0 ignored issues
show
Bug Best Practice introduced by
The property DefaultLat does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. Did you maybe forget to declare it?
Loading history...
135 2
        $defaultLng = (float)$this->owner->DefaultLng;
0 ignored issues
show
Bug Best Practice introduced by
The property DefaultLng does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. Did you maybe forget to declare it?
Loading history...
136
137 2
        Requirements::customScript("
138
            window.dynamic_locator = {
139 2
                'radii': {$radiiString},
140 2
                'categories': {$categoriesString},
141 2
                'unit': '{$unit}',
142 2
                'limit': {$this->owner->getLimit()},
0 ignored issues
show
Bug introduced by
The method getLimit() does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. ( Ignorable by Annotation )

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

142
                'limit': {$this->owner->/** @scrutinizer ignore-call */ getLimit()},

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getLimit() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

142
                'limit': {$this->owner->/** @scrutinizer ignore-call */ getLimit()},

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
143 2
                'clusters': {$clusters},
144 2
                'mapStylePath': '{$stylePath}',
145 2
                'searchMarkerImagePath': '{$searchMarkerIconPath}',
146 2
                'markerImagePath': '{$markerIconPath}',
147 2
                'clusterImages': {$clusterImages},
148
                'defaultCenter': {
149 2
                    'lat': {$defaultLat},
150 2
                    'lng': {$defaultLng}
151
                },
152 2
                'autocomplete': {$autocomplete}
153
            };
154 2
        ", 'react-locator');
155
    }
156
157
    /**
158
     * Gets the maker icon image
159
     * @return null|string
160
     * @var boolean $svg if svgs should be included
161
     */
162 2
    public static function getSearchIconImage($svg = true)
163
    {
164
        $folders = [
165 2
            'client/dist/img/',
166
            'client/dist/images/',
167
            'dist/img/',
168
            'dist/images/',
169
            'img/',
170
            'images/',
171
        ];
172
173
        $extensions = [
174 2
            'png',
175
            'jpg',
176
            'jpeg',
177
            'gif',
178
        ];
179
180 2
        if ($svg === true) {
181 2
            array_unshift($extensions, 'svg');
182
        }
183
184 2
        $file = 'mapSearchIcon';
185
186 2
        foreach ($folders as $folder) {
187 2
            foreach ($extensions as $extension) {
188 2
                if ($icon = ThemeResourceLoader::inst()->findThemedResource(
189 2
                    "{$folder}{$file}.{$extension}",
190 2
                    SSViewer::get_themes()
191
                )) {
192 2
                    return ModuleResourceLoader::resourceURL($icon);
193
                }
194
            }
195
        }
196
197 2
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type null|string.
Loading history...
198
    }
199
200
    /**
201
     * @param string $path
202
     * @return bool
203
     */
204
    public function isResourcePath($path)
205
    {
206
        $path = ltrim($path, '/');
207
        return substr($path, 0, strlen(RESOURCES_DIR)) === RESOURCES_DIR;
208
    }
209
210
    /**
211
     * @param string $path
212
     * @return bool|string
213
     */
214
    public function getClusterImageFromPath($path)
215
    {
216
        // valid full url
217
        if (filter_var($path, FILTER_VALIDATE_URL)) {
218
            return $path;
219
        }
220
221
        if ($this->owner->isResourcePath($path)) {
0 ignored issues
show
Bug introduced by
The method isResourcePath() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

221
        if ($this->owner->/** @scrutinizer ignore-call */ isResourcePath($path)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
222
            return $path;
223
        }
224
225
        $icon = ThemeResourceLoader::inst()->findThemedResource($path, SSViewer::get_themes());
226
        if ($icon) {
227
            return ModuleResourceLoader::resourceURL($icon);
228
        }
229
230
        return false;
231
    }
232
233
    /**
234
     * @return array|bool
235
     */
236 2
    public function getClusterImages()
237
    {
238 2
        $iconPaths = $this->owner->getFailover()->config()->get('ClusterImages');
0 ignored issues
show
Bug introduced by
The method getFailover() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

238
        $iconPaths = $this->owner->/** @scrutinizer ignore-call */ getFailover()->config()->get('ClusterImages');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getFailover() does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. ( Ignorable by Annotation )

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

238
        $iconPaths = $this->owner->/** @scrutinizer ignore-call */ getFailover()->config()->get('ClusterImages');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
239 2
        $icons = [];
240 2
        if (!$iconPaths) {
241 2
            return $icons;
242
        }
243
244
        foreach ($iconPaths as $path) {
245
            $iconPath = $this->owner->getClusterImageFromPath($path);
0 ignored issues
show
Bug introduced by
The method getClusterImageFromPath() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

245
            /** @scrutinizer ignore-call */ 
246
            $iconPath = $this->owner->getClusterImageFromPath($path);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
246
            if ($iconPath) {
247
                $icons[] = $iconPath;
248
            }
249
        }
250
251
        return $icons;
252
    }
253
254
    /**
255
     * @param $categories
256
     *
257
     * @return string
258
     */
259 3
    public function categoriesString($categories)
260
    {
261 3
        $string = '[';
262 3
        for ($i = 0; $i < $categories->count(); $i++) {
263 1
            $cat = $categories[$i];
264 1
            $ID = $cat->ID;
265 1
            $Name = $cat->Name;
266
            $string .= "{
267 1
                'ID': {$ID},
268 1
                'Name': '{$Name}'
269
            }";
270
271 1
            if ($i !== $categories->count() - 1) {
272 1
                $string .= ',';
273
            }
274
        }
275 3
        $string .= ']';
276
277 3
        return $string;
278
    }
279
280
    /**
281
     * @return string
282
     */
283 1
    public function getClientConfig()
284
    {
285 1
        $token = SecurityToken::inst();
286
287
        $clientConfig = [
288 1
            'name' => get_class($this->owner),
289 1
            'url' => trim($this->owner->Link(), '/'),
0 ignored issues
show
Bug introduced by
The method Link() does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. ( Ignorable by Annotation )

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

289
            'url' => trim($this->owner->/** @scrutinizer ignore-call */ Link(), '/'),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method Link() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

289
            'url' => trim($this->owner->/** @scrutinizer ignore-call */ Link(), '/'),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
290 1
            'baseUrl' => Director::baseURL(),
291 1
            'absoluteBaseUrl' => Director::absoluteBaseURL(),
292 1
            $token->getName() => $token->getValue(),
293
            'sections' => [],
294 1
            'debugging' => $this->owner->config()->get('debugging'),
0 ignored issues
show
Bug introduced by
The method config() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

294
            'debugging' => $this->owner->/** @scrutinizer ignore-call */ config()->get('debugging'),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method config() does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. ( Ignorable by Annotation )

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

294
            'debugging' => $this->owner->/** @scrutinizer ignore-call */ config()->get('debugging'),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
295
        ];
296
297 1
        $clientConfig['sections'][] = Injector::inst()->get(LeftAndMain::class)->getClientConfig();
298
299 1
        $this->owner->extend('updateClientConfig', $clientConfig);
0 ignored issues
show
Bug introduced by
The method extend() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

299
        $this->owner->/** @scrutinizer ignore-call */ 
300
                      extend('updateClientConfig', $clientConfig);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method extend() does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. ( Ignorable by Annotation )

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

299
        $this->owner->/** @scrutinizer ignore-call */ 
300
                      extend('updateClientConfig', $clientConfig);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
300
301 1
        return Convert::raw2json($clientConfig);
0 ignored issues
show
Deprecated Code introduced by
The function SilverStripe\Core\Convert::raw2json() has been deprecated: 4.4.0:5.0.0 Use json_encode() instead ( Ignorable by Annotation )

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

301
        return /** @scrutinizer ignore-deprecated */ Convert::raw2json($clientConfig);

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...
302
    }
303
304
    /**
305
     * Gets a JSON schema representing the search form.
306
     *
307
     * @param HTTPRequest $request
0 ignored issues
show
Bug introduced by
The type Dynamic\Locator\React\Extensions\HTTPRequest was not found. Did you mean HTTPRequest? If so, make sure to prefix the type with \.
Loading history...
308
     * @return HTTPResponse
309
     */
310
    public function schema($request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

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

310
    public function schema(/** @scrutinizer ignore-unused */ $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
311
    {
312
        return $this->getSchemaResponse("Locator.SearchForm", $this->owner->LocationSearch());
0 ignored issues
show
Bug introduced by
The method LocationSearch() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

312
        return $this->getSchemaResponse("Locator.SearchForm", $this->owner->/** @scrutinizer ignore-call */ LocationSearch());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method LocationSearch() does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. ( Ignorable by Annotation )

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

312
        return $this->getSchemaResponse("Locator.SearchForm", $this->owner->/** @scrutinizer ignore-call */ LocationSearch());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
313
    }
314
315
    /**
316
     * Check if the current request has a X-Formschema-Request header set.
317
     * Used by conditional logic that responds to validation results
318
     *
319
     * @return bool
320
     */
321
    protected function getSchemaRequested()
322
    {
323
        $parts = $this->owner->getRequest()->getHeader(LeftAndMain::SCHEMA_HEADER);
0 ignored issues
show
Bug introduced by
The method getRequest() does not exist on Dynamic\Locator\React\Ex...atorControllerExtension. ( Ignorable by Annotation )

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

323
        $parts = $this->owner->/** @scrutinizer ignore-call */ getRequest()->getHeader(LeftAndMain::SCHEMA_HEADER);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getRequest() does not exist on Dynamic\Locator\React\Extensions\LocatorExtension. ( Ignorable by Annotation )

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

323
        $parts = $this->owner->/** @scrutinizer ignore-call */ getRequest()->getHeader(LeftAndMain::SCHEMA_HEADER);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
324
        return !empty($parts);
325
    }
326
327
    /**
328
     * Generate schema for the given form based on the X-Formschema-Request header value
329
     *
330
     * @param string $schemaID ID for this schema. Required.
331
     * @param Form $form Required for 'state' or 'schema' response
0 ignored issues
show
Bug introduced by
The type Dynamic\Locator\React\Extensions\Form was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
332
     * @param ValidationResult $errors Required for 'error' response
333
     * @param array $extraData Any extra data to be merged with the schema response
334
     * @return HTTPResponse
335
     */
336
    protected function getSchemaResponse($schemaID, $form = null, ValidationResult $errors = null, $extraData = [])
0 ignored issues
show
Bug introduced by
The type Dynamic\Locator\React\Extensions\ValidationResult was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
337
    {
338
        $parts = $this->owner->getRequest()->getHeader(LeftAndMain::SCHEMA_HEADER);
339
        $data = $this
340
            ->getFormSchema()
341
            ->getMultipartSchema($parts, $schemaID, $form, $errors);
342
343
        if ($extraData) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $extraData of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
344
            $data = array_merge($data, $extraData);
345
        }
346
347
        $response = new HTTPResponse(Convert::raw2json($data));
0 ignored issues
show
Deprecated Code introduced by
The function SilverStripe\Core\Convert::raw2json() has been deprecated: 4.4.0:5.0.0 Use json_encode() instead ( Ignorable by Annotation )

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

347
        $response = new HTTPResponse(/** @scrutinizer ignore-deprecated */ Convert::raw2json($data));

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...
348
        $response->addHeader('Content-Type', 'application/json');
349
        return $response;
350
    }
351
}
352