Skip to content

Commit cfa6e97

Browse files
Merge pull request #18115 from MoonE/gis-label-trim
Trim label before passing it on to GIS classes
2 parents 368dfe5 + 366daac commit cfa6e97

10 files changed

Lines changed: 128 additions & 158 deletions

libraries/classes/Gis/GisGeometry.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ abstract class GisGeometry
3737
*
3838
* @return string the code related to a row in the GIS dataset
3939
*/
40-
abstract public function prepareRowAsSvg($spatial, $label, array $color, array $scale_data);
40+
abstract public function prepareRowAsSvg($spatial, string $label, array $color, array $scale_data);
4141

4242
/**
4343
* Adds to the PNG image object, the data related to a row in the GIS dataset.
4444
*
45-
* @param string $spatial GIS POLYGON object
46-
* @param string|null $label Label for the GIS POLYGON object
47-
* @param int[] $color Color for the GIS POLYGON object
48-
* @param array $scale_data Array containing data related to scaling
45+
* @param string $spatial GIS POLYGON object
46+
* @param string $label Label for the GIS POLYGON object
47+
* @param int[] $color Color for the GIS POLYGON object
48+
* @param array $scale_data Array containing data related to scaling
4949
*/
5050
abstract public function prepareRowAsPng(
5151
$spatial,
52-
string|null $label,
52+
string $label,
5353
array $color,
5454
array $scale_data,
5555
ImageWrapper $image
@@ -58,17 +58,17 @@ abstract public function prepareRowAsPng(
5858
/**
5959
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
6060
*
61-
* @param string $spatial GIS data object
62-
* @param string|null $label label for the GIS data object
63-
* @param int[] $color color for the GIS data object
64-
* @param array $scale_data array containing data related to scaling
65-
* @param TCPDF $pdf
61+
* @param string $spatial GIS data object
62+
* @param string $label label for the GIS data object
63+
* @param int[] $color color for the GIS data object
64+
* @param array $scale_data array containing data related to scaling
65+
* @param TCPDF $pdf
6666
*
6767
* @return TCPDF the modified TCPDF instance
6868
*/
6969
abstract public function prepareRowAsPdf(
7070
$spatial,
71-
string|null $label,
71+
string $label,
7272
array $color,
7373
array $scale_data,
7474
$pdf
@@ -89,7 +89,7 @@ abstract public function prepareRowAsPdf(
8989
abstract public function prepareRowAsOl(
9090
$spatial,
9191
int $srid,
92-
$label,
92+
string $label,
9393
array $color,
9494
array $scale_data
9595
);

libraries/classes/Gis/GisGeometryCollection.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ public function scaleRow(string $spatial): ScaleData|null
8484
/**
8585
* Adds to the PNG image object, the data related to a row in the GIS dataset.
8686
*
87-
* @param string $spatial GIS POLYGON object
88-
* @param string|null $label Label for the GIS POLYGON object
89-
* @param int[] $color Color for the GIS POLYGON object
90-
* @param array $scale_data Array containing data related to scaling
87+
* @param string $spatial GIS POLYGON object
88+
* @param string $label Label for the GIS POLYGON object
89+
* @param int[] $color Color for the GIS POLYGON object
90+
* @param array $scale_data Array containing data related to scaling
9191
*/
9292
public function prepareRowAsPng(
9393
$spatial,
94-
string|null $label,
94+
string $label,
9595
array $color,
9696
array $scale_data,
9797
ImageWrapper $image
@@ -123,15 +123,15 @@ public function prepareRowAsPng(
123123
/**
124124
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
125125
*
126-
* @param string $spatial GIS GEOMETRYCOLLECTION object
127-
* @param string|null $label label for the GIS GEOMETRYCOLLECTION object
128-
* @param int[] $color color for the GIS GEOMETRYCOLLECTION object
129-
* @param array $scale_data array containing data related to scaling
130-
* @param TCPDF $pdf
126+
* @param string $spatial GIS GEOMETRYCOLLECTION object
127+
* @param string $label label for the GIS GEOMETRYCOLLECTION object
128+
* @param int[] $color color for the GIS GEOMETRYCOLLECTION object
129+
* @param array $scale_data array containing data related to scaling
130+
* @param TCPDF $pdf
131131
*
132132
* @return TCPDF the modified TCPDF instance
133133
*/
134-
public function prepareRowAsPdf($spatial, string|null $label, array $color, array $scale_data, $pdf)
134+
public function prepareRowAsPdf($spatial, string $label, array $color, array $scale_data, $pdf)
135135
{
136136
// Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
137137
$goem_col = mb_substr($spatial, 19, -1);
@@ -167,7 +167,7 @@ public function prepareRowAsPdf($spatial, string|null $label, array $color, arra
167167
*
168168
* @return string the code related to a row in the GIS dataset
169169
*/
170-
public function prepareRowAsSvg($spatial, $label, array $color, array $scale_data)
170+
public function prepareRowAsSvg($spatial, string $label, array $color, array $scale_data)
171171
{
172172
$row = '';
173173

@@ -207,7 +207,7 @@ public function prepareRowAsSvg($spatial, $label, array $color, array $scale_dat
207207
*
208208
* @return string JavaScript related to a row in the GIS dataset
209209
*/
210-
public function prepareRowAsOl($spatial, int $srid, $label, array $color, array $scale_data)
210+
public function prepareRowAsOl($spatial, int $srid, string $label, array $color, array $scale_data)
211211
{
212212
$row = '';
213213

libraries/classes/Gis/GisLineString.php

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ public function scaleRow(string $spatial): ScaleData|null
6464
/**
6565
* Adds to the PNG image object, the data related to a row in the GIS dataset.
6666
*
67-
* @param string $spatial GIS POLYGON object
68-
* @param string|null $label Label for the GIS POLYGON object
69-
* @param int[] $color Color for the GIS POLYGON object
70-
* @param array $scale_data Array containing data related to scaling
67+
* @param string $spatial GIS POLYGON object
68+
* @param string $label Label for the GIS POLYGON object
69+
* @param int[] $color Color for the GIS POLYGON object
70+
* @param array $scale_data Array containing data related to scaling
7171
*/
7272
public function prepareRowAsPng(
7373
$spatial,
74-
string|null $label,
74+
string $label,
7575
array $color,
7676
array $scale_data,
7777
ImageWrapper $image
@@ -80,8 +80,6 @@ public function prepareRowAsPng(
8080
$black = $image->colorAllocate(0, 0, 0);
8181
$line_color = $image->colorAllocate(...$color);
8282

83-
$label = trim($label ?? '');
84-
8583
// Trim to remove leading 'LINESTRING(' and trailing ')'
8684
$lineString = mb_substr($spatial, 11, -1);
8785
$points_arr = $this->extractPoints($lineString, $scale_data);
@@ -118,23 +116,21 @@ public function prepareRowAsPng(
118116
/**
119117
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
120118
*
121-
* @param string $spatial GIS LINESTRING object
122-
* @param string|null $label Label for the GIS LINESTRING object
123-
* @param int[] $color Color for the GIS LINESTRING object
124-
* @param array $scale_data Array containing data related to scaling
125-
* @param TCPDF $pdf
119+
* @param string $spatial GIS LINESTRING object
120+
* @param string $label Label for the GIS LINESTRING object
121+
* @param int[] $color Color for the GIS LINESTRING object
122+
* @param array $scale_data Array containing data related to scaling
123+
* @param TCPDF $pdf
126124
*
127125
* @return TCPDF the modified TCPDF instance
128126
*/
129-
public function prepareRowAsPdf($spatial, string|null $label, array $color, array $scale_data, $pdf)
127+
public function prepareRowAsPdf($spatial, string $label, array $color, array $scale_data, $pdf)
130128
{
131129
$line = [
132130
'width' => 1.5,
133131
'color' => $color,
134132
];
135133

136-
$label = trim($label ?? '');
137-
138134
// Trim to remove leading 'LINESTRING(' and trailing ')'
139135
$linesrting = mb_substr($spatial, 11, -1);
140136
$points_arr = $this->extractPoints($linesrting, $scale_data);
@@ -168,7 +164,7 @@ public function prepareRowAsPdf($spatial, string|null $label, array $color, arra
168164
*
169165
* @return string the code related to a row in the GIS dataset
170166
*/
171-
public function prepareRowAsSvg($spatial, $label, array $color, array $scale_data)
167+
public function prepareRowAsSvg($spatial, string $label, array $color, array $scale_data)
172168
{
173169
$line_options = [
174170
'name' => $label,
@@ -190,7 +186,7 @@ public function prepareRowAsSvg($spatial, $label, array $color, array $scale_dat
190186

191187
$row .= '"';
192188
foreach ($line_options as $option => $val) {
193-
$row .= ' ' . $option . '="' . trim((string) $val) . '"';
189+
$row .= ' ' . $option . '="' . $val . '"';
194190
}
195191

196192
$row .= '/>';
@@ -210,7 +206,7 @@ public function prepareRowAsSvg($spatial, $label, array $color, array $scale_dat
210206
*
211207
* @return string JavaScript related to a row in the GIS dataset
212208
*/
213-
public function prepareRowAsOl($spatial, int $srid, $label, array $color, array $scale_data)
209+
public function prepareRowAsOl($spatial, int $srid, string $label, array $color, array $scale_data)
214210
{
215211
$stroke_style = [
216212
'color' => $color,
@@ -219,8 +215,8 @@ public function prepareRowAsOl($spatial, int $srid, $label, array $color, array
219215

220216
$result = 'var style = new ol.style.Style({'
221217
. 'stroke: new ol.style.Stroke(' . json_encode($stroke_style) . ')';
222-
if (trim($label) !== '') {
223-
$text_style = ['text' => trim($label)];
218+
if ($label !== '') {
219+
$text_style = ['text' => $label];
224220
$result .= ', text: new ol.style.Text(' . json_encode($text_style) . ')';
225221
}
226222

libraries/classes/Gis/GisMultiLineString.php

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ public function scaleRow(string $spatial): ScaleData|null
7373
/**
7474
* Adds to the PNG image object, the data related to a row in the GIS dataset.
7575
*
76-
* @param string $spatial GIS POLYGON object
77-
* @param string|null $label Label for the GIS POLYGON object
78-
* @param int[] $color Color for the GIS POLYGON object
79-
* @param array $scale_data Array containing data related to scaling
76+
* @param string $spatial GIS POLYGON object
77+
* @param string $label Label for the GIS POLYGON object
78+
* @param int[] $color Color for the GIS POLYGON object
79+
* @param array $scale_data Array containing data related to scaling
8080
*/
8181
public function prepareRowAsPng(
8282
$spatial,
83-
string|null $label,
83+
string $label,
8484
array $color,
8585
array $scale_data,
8686
ImageWrapper $image
@@ -89,8 +89,6 @@ public function prepareRowAsPng(
8989
$black = $image->colorAllocate(0, 0, 0);
9090
$line_color = $image->colorAllocate(...$color);
9191

92-
$label = trim($label ?? '');
93-
9492
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
9593
$multilinestirng = mb_substr($spatial, 17, -2);
9694
// Separate each linestring
@@ -135,23 +133,21 @@ public function prepareRowAsPng(
135133
/**
136134
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
137135
*
138-
* @param string $spatial GIS MULTILINESTRING object
139-
* @param string|null $label Label for the GIS MULTILINESTRING object
140-
* @param int[] $color Color for the GIS MULTILINESTRING object
141-
* @param array $scale_data Array containing data related to scaling
142-
* @param TCPDF $pdf
136+
* @param string $spatial GIS MULTILINESTRING object
137+
* @param string $label Label for the GIS MULTILINESTRING object
138+
* @param int[] $color Color for the GIS MULTILINESTRING object
139+
* @param array $scale_data Array containing data related to scaling
140+
* @param TCPDF $pdf
143141
*
144142
* @return TCPDF the modified TCPDF instance
145143
*/
146-
public function prepareRowAsPdf($spatial, string|null $label, array $color, array $scale_data, $pdf)
144+
public function prepareRowAsPdf($spatial, string $label, array $color, array $scale_data, $pdf)
147145
{
148146
$line = [
149147
'width' => 1.5,
150148
'color' => $color,
151149
];
152150

153-
$label = trim($label ?? '');
154-
155151
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
156152
$multilinestirng = mb_substr($spatial, 17, -2);
157153
// Separate each linestring
@@ -193,7 +189,7 @@ public function prepareRowAsPdf($spatial, string|null $label, array $color, arra
193189
*
194190
* @return string the code related to a row in the GIS dataset
195191
*/
196-
public function prepareRowAsSvg($spatial, $label, array $color, array $scale_data)
192+
public function prepareRowAsSvg($spatial, string $label, array $color, array $scale_data)
197193
{
198194
$line_options = [
199195
'name' => $label,
@@ -220,7 +216,7 @@ public function prepareRowAsSvg($spatial, $label, array $color, array $scale_dat
220216
$row .= '"';
221217
$line_options['id'] = $label . $this->getRandomId();
222218
foreach ($line_options as $option => $val) {
223-
$row .= ' ' . $option . '="' . trim((string) $val) . '"';
219+
$row .= ' ' . $option . '="' . $val . '"';
224220
}
225221

226222
$row .= '/>';
@@ -241,7 +237,7 @@ public function prepareRowAsSvg($spatial, $label, array $color, array $scale_dat
241237
*
242238
* @return string JavaScript related to a row in the GIS dataset
243239
*/
244-
public function prepareRowAsOl($spatial, int $srid, $label, array $color, array $scale_data)
240+
public function prepareRowAsOl($spatial, int $srid, string $label, array $color, array $scale_data)
245241
{
246242
$stroke_style = [
247243
'color' => $color,
@@ -250,8 +246,8 @@ public function prepareRowAsOl($spatial, int $srid, $label, array $color, array
250246

251247
$row = 'var style = new ol.style.Style({'
252248
. 'stroke: new ol.style.Stroke(' . json_encode($stroke_style) . ')';
253-
if (trim($label) !== '') {
254-
$text_style = ['text' => trim($label)];
249+
if ($label !== '') {
250+
$text_style = ['text' => $label];
255251
$row .= ', text: new ol.style.Text(' . json_encode($text_style) . ')';
256252
}
257253

0 commit comments

Comments
 (0)