Passed
Push — master ( fb8a8c...61ccf5 )
by Matthew
03:13
created

LocatorControllerExtension::getSearchIconImage()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 36
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 22
nc 8
nop 1
dl 0
loc 36
ccs 13
cts 13
cp 1
crap 5
rs 9.2568
c 0
b 0
f 0
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
        // require i18n translation stuff
82 1
        Requirements::javascript('silverstripe/admin: client/dist/js/i18n.js');
83 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

83
        /** @scrutinizer ignore-deprecated */ Requirements::add_i18n_javascript('dynamic/silverstripe-locator-react: client/lang');
Loading history...
84
85
        // because we need another library when using autocomplete
86 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...
87
            // google maps api key
88 1
            $key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key');
89 1
            Requirements::block("https://maps.google.com/maps/api/js?key={$key}");
90 1
            Requirements::javascript("https://maps.google.com/maps/api/js?key={$key}&libraries=places");
91
        }
92
93 1
        Requirements::customScript("
94
            window.ss = window.ss || {};
95 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

95
            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...
96
        ");
97
98 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

98
        $this->owner->/** @scrutinizer ignore-call */ 
99
                      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...
99
    }
100
101
    /**
102
     * Generates the custom script for settings
103
     */
104 2
    public function customScript()
105
    {
106 2
        $radii = $this->owner->getShowRadius() ? $this->owner->getRadii() : [];
0 ignored issues
show
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

106
        $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\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

106
        $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\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

106
        $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 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

106
        $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...
107 2
        $radiiString = json_encode($radii);
108
109 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

109
        /** @scrutinizer ignore-call */ 
110
        $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

109
        /** @scrutinizer ignore-call */ 
110
        $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...
110 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

110
        /** @scrutinizer ignore-call */ 
111
        $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...
111
112 2
        $unit = $this->owner->Unit ? $this->owner->Unit : 'm';
0 ignored issues
show
Bug introduced by
The property Unit does not seem to exist on Dynamic\Locator\React\Extensions\LocatorExtension.
Loading history...
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...
113
        // otherwise this is 0 or 1
114 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...
115 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...
116
117 2
        $stylePath = ModuleResourceLoader::singleton()->resolveURL(
118 2
            $this->owner->getMapStyle()
0 ignored issues
show
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

118
            $this->owner->/** @scrutinizer ignore-call */ 
119
                          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\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

118
            $this->owner->/** @scrutinizer ignore-call */ 
119
                          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...
119
        );
120 2
        $searchMarkerIconPath = ModuleResourceLoader::singleton()->resolveURL(
121 2
            $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
            $this->owner->/** @scrutinizer ignore-call */ 
122
                          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
        );
123 2
        $markerIconPath = ModuleResourceLoader::singleton()->resolveURL(
124 2
            AddressDataExtension::getIconImage(true)
125
        );
126
127 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...
128
            $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

128
            $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...
129
        }
130 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...
131
            $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

131
            $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...
132
        }
133
134
        // force to float
135 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...
136 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...
137
138 2
        Requirements::customScript("
139
            window.dynamic_locator = {
140 2
                'radii': {$radiiString},
141 2
                'categories': {$categoriesString},
142 2
                'unit': '{$unit}',
143 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

143
                '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

143
                '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...
144 2
                'clusters': {$clusters},
145 2
                'mapStylePath': '{$stylePath}',
146 2
                'searchMarkerImagePath': '{$searchMarkerIconPath}',
147 2
                'markerImagePath': '{$markerIconPath}',
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 $categories
202
     *
203
     * @return string
204
     */
205 3
    public function categoriesString($categories)
206
    {
207 3
        $string = '[';
208 3
        for ($i = 0; $i < $categories->count(); $i++) {
209 1
            $cat = $categories[$i];
210 1
            $ID = $cat->ID;
211 1
            $Name = $cat->Name;
212
            $string .= "{
213 1
                'ID': {$ID},
214 1
                'Name': '{$Name}'
215
            }";
216
217 1
            if ($i !== $categories->count() - 1) {
218 1
                $string .= ',';
219
            }
220
        }
221 3
        $string .= ']';
222
223 3
        return $string;
224
    }
225
226
    /**
227
     * @return string
228
     */
229 1
    public function getClientConfig()
230
    {
231 1
        $token = SecurityToken::inst();
232
233
        $clientConfig = [
234 1
            'name' => get_class($this->owner),
235 1
            'url' => trim($this->owner->Link(), '/'),
0 ignored issues
show
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

235
            '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\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

235
            '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...
236 1
            'baseUrl' => Director::baseURL(),
237 1
            'absoluteBaseUrl' => Director::absoluteBaseURL(),
238 1
            $token->getName() => $token->getValue(),
239
            'sections' => [],
240 1
            'debugging' => $this->owner->config()->get('debugging'),
0 ignored issues
show
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

240
            '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\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

240
            '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...
241
        ];
242
243 1
        $clientConfig['sections'][] = Injector::inst()->get(LeftAndMain::class)->getClientConfig();
244
245 1
        $this->owner->extend('updateClientConfig', $clientConfig);
0 ignored issues
show
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

245
        $this->owner->/** @scrutinizer ignore-call */ 
246
                      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\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
        $this->owner->/** @scrutinizer ignore-call */ 
246
                      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...
246
247 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

247
        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...
248
    }
249
250
    /**
251
     * Gets a JSON schema representing the search form.
252
     *
253
     * @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...
254
     * @return HTTPResponse
255
     */
256
    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

256
    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...
257
    {
258
        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\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

258
        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\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

258
        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...
259
    }
260
261
    /**
262
     * Check if the current request has a X-Formschema-Request header set.
263
     * Used by conditional logic that responds to validation results
264
     *
265
     * @return bool
266
     */
267
    protected function getSchemaRequested()
268
    {
269
        $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\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

269
        $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\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

269
        $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...
270
        return !empty($parts);
271
    }
272
273
    /**
274
     * Generate schema for the given form based on the X-Formschema-Request header value
275
     *
276
     * @param string $schemaID ID for this schema. Required.
277
     * @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...
278
     * @param ValidationResult $errors Required for 'error' response
279
     * @param array $extraData Any extra data to be merged with the schema response
280
     * @return HTTPResponse
281
     */
282
    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...
283
    {
284
        $parts = $this->owner->getRequest()->getHeader(LeftAndMain::SCHEMA_HEADER);
285
        $data = $this
286
            ->getFormSchema()
287
            ->getMultipartSchema($parts, $schemaID, $form, $errors);
288
289
        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...
290
            $data = array_merge($data, $extraData);
291
        }
292
293
        $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

293
        $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...
294
        $response->addHeader('Content-Type', 'application/json');
295
        return $response;
296
    }
297
}
298