Completed
Pull Request — master (#8020)
by Julius
22:02
created
lib/private/Avatar.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	/**
82 82
 	 * @inheritdoc
83 83
 	 */
84
-	public function get ($size = 64) {
84
+	public function get($size = 64) {
85 85
 		try {
86 86
 			$file = $this->getFile($size);
87 87
 		} catch (NotFoundException $e) {
@@ -111,16 +111,16 @@  discard block
 block discarded – undo
111 111
 	 * @throws NotSquareException if the image is not square
112 112
 	 * @return void
113 113
 	*/
114
-	public function set ($data) {
114
+	public function set($data) {
115 115
 
116
-		if($data instanceOf IImage) {
116
+		if ($data instanceOf IImage) {
117 117
 			$img = $data;
118 118
 			$data = $img->data();
119 119
 		} else {
120 120
 			$img = new OC_Image();
121 121
 			if (is_resource($data) && get_resource_type($data) === "gd") {
122 122
 				$img->setResource($data);
123
-			} elseif(is_resource($data)) {
123
+			} elseif (is_resource($data)) {
124 124
 				$img->loadFromFileHandle($data);
125 125
 			} else {
126 126
 				try {
@@ -170,11 +170,11 @@  discard block
 block discarded – undo
170 170
 	 * remove the users avatar
171 171
 	 * @return void
172 172
 	*/
173
-	public function remove () {
173
+	public function remove() {
174 174
 		$avatars = $this->folder->getDirectoryListing();
175 175
 
176 176
 		$this->config->setUserValue($this->user->getUID(), 'avatar', 'version',
177
-			(int)$this->config->getUserValue($this->user->getUID(), 'avatar', 'version', 0) + 1);
177
+			(int) $this->config->getUserValue($this->user->getUID(), 'avatar', 'version', 0) + 1);
178 178
 
179 179
 		foreach ($avatars as $avatar) {
180 180
 			$avatar->delete();
@@ -200,9 +200,9 @@  discard block
 block discarded – undo
200 200
 		}
201 201
 
202 202
 		if ($size === -1) {
203
-			$path = 'avatar.' . $ext;
203
+			$path = 'avatar.'.$ext;
204 204
 		} else {
205
-			$path = 'avatar.' . $size . '.' . $ext;
205
+			$path = 'avatar.'.$size.'.'.$ext;
206 206
 		}
207 207
 
208 208
 		try {
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 			} else {
219 219
 				$avatar = new OC_Image();
220 220
 				/** @var ISimpleFile $file */
221
-				$file = $this->folder->getFile('avatar.' . $ext);
221
+				$file = $this->folder->getFile('avatar.'.$ext);
222 222
 				$avatar->loadFromData($file->getContent());
223 223
 				$avatar->resize($size);
224 224
 				$data = $avatar->data();
@@ -228,13 +228,13 @@  discard block
 block discarded – undo
228 228
 				$file = $this->folder->newFile($path);
229 229
 				$file->putContent($data);
230 230
 			} catch (NotPermittedException $e) {
231
-				$this->logger->error('Failed to save avatar for ' . $this->user->getUID());
231
+				$this->logger->error('Failed to save avatar for '.$this->user->getUID());
232 232
 				throw new NotFoundException();
233 233
 			}
234 234
 
235 235
 		}
236 236
 
237
-		if($this->config->getUserValue($this->user->getUID(), 'avatar', 'generated', null) === null) {
237
+		if ($this->config->getUserValue($this->user->getUID(), 'avatar', 'generated', null) === null) {
238 238
 			$generated = $this->folder->fileExists('generated') ? 'true' : 'false';
239 239
 			$this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', $generated);
240 240
 		}
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 		$white = imagecolorallocate($im, 255, 255, 255);
272 272
 		imagefilledrectangle($im, 0, 0, $size, $size, $background);
273 273
 
274
-		$font = __DIR__ . '/../../core/fonts/OpenSans-Semibold.woff';
274
+		$font = __DIR__.'/../../core/fonts/OpenSans-Semibold.woff';
275 275
 
276 276
 		$fontSize = $size * 0.4;
277 277
 		$box = imagettfbbox($fontSize, 0, $font, $text);
@@ -308,12 +308,12 @@  discard block
 block discarded – undo
308 308
 		$h = ($max + $min) / 2.0;
309 309
 		$l = ($max + $min) / 2.0;
310 310
 
311
-		if($max === $min) {
311
+		if ($max === $min) {
312 312
 			$h = $s = 0; // Achromatic
313 313
 		} else {
314 314
 			$d = $max - $min;
315 315
 			$s = $l > 0.5 ? $d / (2 - $max - $min) : $d / ($max + $min);
316
-			switch($max) {
316
+			switch ($max) {
317 317
 				case $r:
318 318
 					$h = ($g - $b) / $d + ($g < $b ? 6 : 0);
319 319
 					break;
@@ -350,14 +350,14 @@  discard block
 block discarded – undo
350 350
 
351 351
 
352 352
 		// Splitting evenly the string
353
-		foreach($hashChars as  $i => $char) {
353
+		foreach ($hashChars as  $i => $char) {
354 354
 			$result[$i % $modulo] .= intval($char, 16);
355 355
 		}
356 356
 
357 357
 		// Converting our data into a usable rgb format
358 358
 		// Start at 1 because 16%3=1 but 15%3=0 and makes the repartition even
359
-		for($count = 1; $count < $modulo; $count++) {
360
-			$rgb[$count%3] += (int)$result[$count];
359
+		for ($count = 1; $count < $modulo; $count++) {
360
+			$rgb[$count % 3] += (int) $result[$count];
361 361
 		}
362 362
 
363 363
 		// Reduce values bigger than rgb requirements
@@ -383,36 +383,36 @@  discard block
 block discarded – undo
383 383
 	 * @param double $l Lightness in range [0, 1]
384 384
 	 * @return int[] Array containing r g b in the range [0, 255]
385 385
 	 */
386
-	private function hslToRgb($h, $s, $l){
387
-		$hue2rgb = function ($p, $q, $t){
388
-			if($t < 0) {
386
+	private function hslToRgb($h, $s, $l) {
387
+		$hue2rgb = function($p, $q, $t) {
388
+			if ($t < 0) {
389 389
 				$t += 1;
390 390
 			}
391
-			if($t > 1) {
391
+			if ($t > 1) {
392 392
 				$t -= 1;
393 393
 			}
394
-			if($t < 1/6) {
394
+			if ($t < 1 / 6) {
395 395
 				return $p + ($q - $p) * 6 * $t;
396 396
 			}
397
-			if($t < 1/2) {
397
+			if ($t < 1 / 2) {
398 398
 				return $q;
399 399
 			}
400
-			if($t < 2/3) {
401
-				return $p + ($q - $p) * (2/3 - $t) * 6;
400
+			if ($t < 2 / 3) {
401
+				return $p + ($q - $p) * (2 / 3 - $t) * 6;
402 402
 			}
403 403
 			return $p;
404 404
 		};
405 405
 
406
-		if($s === 0){
406
+		if ($s === 0) {
407 407
 			$r = $l;
408 408
 			$g = $l;
409 409
 			$b = $l; // achromatic
410
-		}else{
410
+		} else {
411 411
 			$q = $l < 0.5 ? $l * (1 + $s) : $l + $s - $l * $s;
412 412
 			$p = 2 * $l - $q;
413
-			$r = $hue2rgb($p, $q, $h + 1/3);
413
+			$r = $hue2rgb($p, $q, $h + 1 / 3);
414 414
 			$g = $hue2rgb($p, $q, $h);
415
-			$b = $hue2rgb($p, $q, $h - 1/3);
415
+			$b = $hue2rgb($p, $q, $h - 1 / 3);
416 416
 		}
417 417
 
418 418
 		return array(round($r * 255), round($g * 255), round($b * 255));
Please login to merge, or discard this patch.