Skip to content

Commit cb06f4a

Browse files
committed
cleanups
1 parent 8c137df commit cb06f4a

File tree

2 files changed

+45
-51
lines changed

2 files changed

+45
-51
lines changed

src/Peachpie.Library.Graphics/Exif.cs

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,8 @@ static PhpValue ExifValueToPhpValue(object value)
130130
{
131131
if (value != null)
132132
{
133-
if (value is Array)
133+
if (value is Array arr)
134134
{
135-
var arr = (Array)value;
136135
var phparr = new PhpArray(arr.Length);
137136

138137
for (int i = 0; i < arr.Length; i++)
@@ -171,15 +170,15 @@ static bool TryAsDouble(object value, out double dval)
171170
{
172171
dval = 0.0;
173172

174-
if (value is float)
173+
if (value is float f)
175174
{
176-
dval = (float)value;
175+
dval = f;
177176
return true;
178177
}
179178

180-
if (value is double)
179+
if (value is double d)
181180
{
182-
dval = (double)value;
181+
dval = d;
183182
return true;
184183
}
185184

@@ -190,45 +189,45 @@ static bool TryAsLong(object value, out long ival)
190189
{
191190
ival = 0;
192191

193-
if (value is int)
192+
if (value is int i)
194193
{
195-
ival = (int)value;
194+
ival = i;
196195
return true;
197196
}
198197

199-
if (value is long)
198+
if (value is long l)
200199
{
201-
ival = (long)value;
200+
ival = l;
202201
return true;
203202
}
204203

205-
if (value is uint)
204+
if (value is uint u)
206205
{
207-
ival = (uint)value;
206+
ival = u;
208207
return true;
209208
}
210209

211-
if (value is byte)
210+
if (value is byte b)
212211
{
213-
ival = (byte)value;
212+
ival = b;
214213
return true;
215214
}
216215

217-
if (value is sbyte)
216+
if (value is sbyte sb)
218217
{
219-
ival = (sbyte)value;
218+
ival = sb;
220219
return true;
221220
}
222221

223-
if (value is short)
222+
if (value is short s)
224223
{
225-
ival = (short)value;
224+
ival = s;
226225
return true;
227226
}
228227

229-
if (value is ushort)
228+
if (value is ushort us)
230229
{
231-
ival = (ushort)value;
230+
ival = us;
232231
return true;
233232
}
234233

@@ -260,14 +259,7 @@ public static string exif_tagname(int index)
260259
//}
261260
//return null;
262261

263-
if (GetExifTagMap().TryGetValue((ushort)index, out var name))
264-
{
265-
return name;
266-
}
267-
else
268-
{
269-
return null;
270-
}
262+
return GetExifTagMap().GetValueOrDefault((ushort)index);
271263
}
272264

273265
/// <summary>
@@ -284,7 +276,7 @@ Dictionary<ushort, string> BuildMap()
284276
var props = typeof(ExifTag).GetProperties();
285277
foreach (var p in props)
286278
{
287-
if (p.GetMethod.IsStatic && p.GetValue(null) is ExifTag exiftag)
279+
if (p.GetMethod?.IsStatic == true && p.GetValue(null) is ExifTag exiftag)
288280
{
289281
map[(ushort)exiftag] = exiftag.ToString();
290282
}

src/Peachpie.Library.Graphics/PhpGd2.cs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics;
43
using System.IO;
5-
using System.Linq;
64
using System.Numerics;
75
using Pchp.Core;
86
using Pchp.Library.Streams;
97
using SixLabors.Fonts;
108
using SixLabors.ImageSharp;
11-
using SixLabors.ImageSharp.Advanced;
129
using SixLabors.ImageSharp.Drawing;
1310
using SixLabors.ImageSharp.Drawing.Processing;
1411
using SixLabors.ImageSharp.Formats;
@@ -53,7 +50,7 @@ public static class PhpGd2
5350
public const string GD_EXTRA_VERSION = ""; //"beta";
5451

5552
/// <summary>
56-
/// When the bundled version of GD is used this is 1 otherwise its set to 0.
53+
/// When the bundled version of GD is used, this is 1 otherwise it's set to 0.
5754
/// </summary>
5855
public const int GD_BUNDLED = 1;
5956

@@ -186,12 +183,12 @@ public enum FilledArcStyles
186183
public enum ColorValues
187184
{
188185
/// <summary>
189-
/// Special color option which can be used in stead of color allocated with <see cref="imagecolorallocate"/> or <see cref="imagecolorallocatealpha"/>.
186+
/// Special color option which can be used instead of color allocated with <see cref="imagecolorallocate"/> or <see cref="imagecolorallocatealpha"/>.
190187
/// </summary>
191188
STYLED = -2,
192189

193190
/// <summary>
194-
/// Special color option which can be used in stead of color allocated with <see cref="imagecolorallocate"/> or <see cref="imagecolorallocatealpha"/>.
191+
/// Special color option which can be used instead of color allocated with <see cref="imagecolorallocate"/> or <see cref="imagecolorallocatealpha"/>.
195192
/// </summary>
196193
BRUSHED = -3,
197194

@@ -227,51 +224,51 @@ public enum ColorValues
227224
public enum FilterTypes
228225
{
229226
/// <summary>
230-
/// Special GD filter used by the <see cref="imagefilter(PhpResource,int)"/> function.
227+
/// Special GD filter used by the <see cref="imagefilter"/> function.
231228
/// </summary>
232229
NEGATE,
233230
/// <summary>
234-
/// Special GD filter used by the <see cref="imagefilter(PhpResource,int)"/> function.
231+
/// Special GD filter used by the <see cref="imagefilter"/> function.
235232
/// </summary>
236233
GRAYSCALE,
237234
/// <summary>
238-
/// Special GD filter used by the <see cref="imagefilter(PhpResource,int)"/> function.
235+
/// Special GD filter used by the <see cref="imagefilter"/> function.
239236
/// </summary>
240237
BRIGHTNESS,
241238
/// <summary>
242-
/// Special GD filter used by the <see cref="imagefilter(PhpResource,int)"/> function.
239+
/// Special GD filter used by the <see cref="imagefilter"/> function.
243240
/// </summary>
244241
CONTRAST,
245242
/// <summary>
246-
/// Special GD filter used by the <see cref="imagefilter(PhpResource,int)"/> function.
243+
/// Special GD filter used by the <see cref="imagefilter"/> function.
247244
/// </summary>
248245
COLORIZE,
249246
/// <summary>
250-
/// Special GD filter used by the <see cref="imagefilter(PhpResource,int)"/> function.
247+
/// Special GD filter used by the <see cref="imagefilter"/> function.
251248
/// </summary>
252249
EDGEDETECT,
253250
/// <summary>
254-
/// Special GD filter used by the <see cref="imagefilter(PhpResource,int)"/> function.
251+
/// Special GD filter used by the <see cref="imagefilter"/> function.
255252
/// </summary>
256253
EMBOSS,
257254
/// <summary>
258-
/// Special GD filter used by the <see cref="imagefilter(PhpResource,int)"/> function.
255+
/// Special GD filter used by the <see cref="imagefilter"/> function.
259256
/// </summary>
260257
GAUSSIAN_BLUR,
261258
/// <summary>
262-
/// Special GD filter used by the <see cref="imagefilter(PhpResource,int)"/> function.
259+
/// Special GD filter used by the <see cref="imagefilter"/> function.
263260
/// </summary>
264261
SELECTIVE_BLUR,
265262
/// <summary>
266-
/// Special GD filter used by the <see cref="imagefilter(PhpResource,int)"/> function.
263+
/// Special GD filter used by the <see cref="imagefilter"/> function.
267264
/// </summary>
268265
MEAN_REMOVAL,
269266
/// <summary>
270-
/// Special GD filter used by the <see cref="imagefilter(PhpResource,int)"/> function.
267+
/// Special GD filter used by the <see cref="imagefilter"/> function.
271268
/// </summary>
272269
SMOOTH,
273270
/// <summary>
274-
/// Special GD filter used by the <see cref="imagefilter(PhpResource,int)"/> function.
271+
/// Special GD filter used by the <see cref="imagefilter"/> function.
275272
/// </summary>
276273
PIXELATE,
277274
}
@@ -1032,8 +1029,13 @@ public static bool imagerectangle(PhpResource im, int x1, int y1, int x2, int y2
10321029

10331030
var rect = new RectangleF(x1, y1, x2 - x1, y2 - y1);
10341031

1035-
var opt = new DrawingOptions();
1036-
opt.GraphicsOptions.Antialias = img.AntiAlias;
1032+
var opt = new DrawingOptions
1033+
{
1034+
GraphicsOptions =
1035+
{
1036+
Antialias = img.AntiAlias
1037+
}
1038+
};
10371039

10381040
img.Image.Mutate(o => o.Draw(opt, FromRGBA(col), 1.0f, rect));
10391041

@@ -1356,8 +1358,8 @@ public static bool imagegd(PhpResource im)
13561358
/// </summary>
13571359
/// <param name="ctx">Runtime context.</param>
13581360
/// <param name="im">Image resource.</param>
1359-
/// <param name="to">Optional. Filename or stream. If not specified the function saves the image to output stream.</param>
1360-
/// <param name="saveaction">Callback that actually save the image to given stream. Called when all checks pass.</param>
1361+
/// <param name="to">Optional. Filename or stream. If not specified, the function saves the image to output stream.</param>
1362+
/// <param name="saveaction">Callback that actually saves the image to given stream. Called when all checks pass.</param>
13611363
/// <returns>True if save succeeded.</returns>
13621364
static bool imagesave(Context ctx, PhpResource im, PhpValue to/* = null*/, Action<Image<Rgba32>, Stream> saveaction)
13631365
{

0 commit comments

Comments
 (0)