From c8128b0382cf0357f5746ae5aaef8e4aa40363e8 Mon Sep 17 00:00:00 2001 From: dmitri ponomarjov Date: Wed, 21 Jun 2017 22:23:03 +0300 Subject: [PATCH] PSR code reformatting, invalid path warning fixed. --- src/GifCreator/GifCreator.php | 95 ++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/src/GifCreator/GifCreator.php b/src/GifCreator/GifCreator.php index 91deb62..d109608 100644 --- a/src/GifCreator/GifCreator.php +++ b/src/GifCreator/GifCreator.php @@ -86,7 +86,7 @@ public function create($frames = array(), $durations = array(), $loop = 0) { if (!is_array($frames) && !is_array($durations)) { - throw new \Exception($this->version.': '.$this->errors['ERR00']); + throw new \Exception($this->version . ': ' . $this->errors['ERR00']); } $this->loop = ($loop > -1) ? $loop : 0; @@ -105,7 +105,7 @@ public function create($frames = array(), $durations = array(), $loop = 0) } elseif (is_string($frames[$i])) { // File path or URL or Binary source code - if (file_exists($frames[$i]) || filter_var($frames[$i], FILTER_VALIDATE_URL)) { // File path + if ((substr($frames[$i], 0, 4) != 'GIF8') && file_exists($frames[$i]) || filter_var($frames[$i], FILTER_VALIDATE_URL)) { // File path $frames[$i] = file_get_contents($frames[$i]); } @@ -119,7 +119,7 @@ public function create($frames = array(), $durations = array(), $loop = 0) } else { // Fail - throw new \Exception($this->version.': '.$this->errors['ERR02']);//.' ('.$mode.')'? + throw new \Exception($this->version . ': ' . $this->errors['ERR02']);//.' ('.$mode.')'? } if ($i == 0) { @@ -129,26 +129,26 @@ public function create($frames = array(), $durations = array(), $loop = 0) if (substr($this->frameSources[$i], 0, 6) != 'GIF87a' && substr($this->frameSources[$i], 0, 6) != 'GIF89a') { - throw new \Exception($this->version.': '.$i.' '.$this->errors['ERR01']); + throw new \Exception($this->version . ': ' . $i . ' ' . $this->errors['ERR01']); } - for ($j = (13 + 3 * (2 << (ord($this->frameSources[$i] { 10 }) & 0x07))), $k = TRUE; $k; $j++) { + for ($j = (13 + 3 * (2 << (ord($this->frameSources[$i]{10}) & 0x07))), $k = true; $k; $j++) { - switch ($this->frameSources[$i] { $j }) { + switch ($this->frameSources[$i]{$j}) { case '!': if ((substr($this->frameSources[$i], ($j + 3), 8)) == 'NETSCAPE') { - throw new \Exception($this->version.': '.$this->errors['ERR03'].' ('.($i + 1).' source).'); + throw new \Exception($this->version . ': ' . $this->errors['ERR03'] . ' (' . ($i + 1) . ' source).'); } - break; + break; case ';': $k = false; - break; + break; } } @@ -185,18 +185,18 @@ public function create($frames = array(), $durations = array(), $loop = 0) */ public function gifAddHeader() { - if (ord($this->frameSources[0] { 10 }) & 0x80) { + if (ord($this->frameSources[0]{10}) & 0x80) { - $cmap = 3 * (2 << (ord($this->frameSources[0] { 10 }) & 0x07)); + $cmap = 3 * (2 << (ord($this->frameSources[0]{10}) & 0x07)); $this->gif .= substr($this->frameSources[0], 6, 7); $this->gif .= substr($this->frameSources[0], 13, $cmap); if ($this->loop != 1) { - // Browsers interpret loop count differently, but for loop == 1 - // we can work around this by excluding loop count completely - // since all browsers seem to handle "no loop count" as - // "play once only". - $this->gif .= "!\377\13NETSCAPE2.0\3\1".$this->encodeAsciiToChar($this->loop)."\0"; + // Browsers interpret loop count differently, but for loop == 1 + // we can work around this by excluding loop count completely + // since all browsers seem to handle "no loop count" as + // "play once only". + $this->gif .= "!\377\13NETSCAPE2.0\3\1" . $this->encodeAsciiToChar($this->loop) . "\0"; } } } @@ -209,81 +209,81 @@ public function gifAddHeader() */ public function addGifFrames($i, $d) { - $Locals_str = 13 + 3 * (2 << (ord($this->frameSources[ $i ] { 10 }) & 0x07)); + $Locals_str = 13 + 3 * (2 << (ord($this->frameSources[$i]{10}) & 0x07)); $Locals_end = strlen($this->frameSources[$i]) - $Locals_str - 1; $Locals_tmp = substr($this->frameSources[$i], $Locals_str, $Locals_end); - $Global_len = 2 << (ord($this->frameSources[0 ] { 10 }) & 0x07); - $Locals_len = 2 << (ord($this->frameSources[$i] { 10 }) & 0x07); + $Global_len = 2 << (ord($this->frameSources[0]{10}) & 0x07); + $Locals_len = 2 << (ord($this->frameSources[$i]{10}) & 0x07); - $Global_rgb = substr($this->frameSources[0], 13, 3 * (2 << (ord($this->frameSources[0] { 10 }) & 0x07))); - $Locals_rgb = substr($this->frameSources[$i], 13, 3 * (2 << (ord($this->frameSources[$i] { 10 }) & 0x07))); + $Global_rgb = substr($this->frameSources[0], 13, 3 * (2 << (ord($this->frameSources[0]{10}) & 0x07))); + $Locals_rgb = substr($this->frameSources[$i], 13, 3 * (2 << (ord($this->frameSources[$i]{10}) & 0x07))); - $Locals_ext = "!\xF9\x04".chr(($this->dis << 2) + 0).chr(($d >> 0 ) & 0xFF).chr(($d >> 8) & 0xFF)."\x0\x0"; + $Locals_ext = "!\xF9\x04" . chr(($this->dis << 2) + 0) . chr(($d >> 0) & 0xFF) . chr(($d >> 8) & 0xFF) . "\x0\x0"; - if ($this->colour > -1 && ord($this->frameSources[$i] { 10 }) & 0x80) { + if ($this->colour > -1 && ord($this->frameSources[$i]{10}) & 0x80) { - for ($j = 0; $j < (2 << (ord($this->frameSources[$i] { 10 } ) & 0x07)); $j++) { + for ($j = 0; $j < (2 << (ord($this->frameSources[$i]{10}) & 0x07)); $j++) { - if (ord($Locals_rgb { 3 * $j + 0 }) == (($this->colour >> 16) & 0xFF) && - ord($Locals_rgb { 3 * $j + 1 }) == (($this->colour >> 8) & 0xFF) && - ord($Locals_rgb { 3 * $j + 2 }) == (($this->colour >> 0) & 0xFF) + if (ord($Locals_rgb{3 * $j + 0}) == (($this->colour >> 16) & 0xFF) && + ord($Locals_rgb{3 * $j + 1}) == (($this->colour >> 8) & 0xFF) && + ord($Locals_rgb{3 * $j + 2}) == (($this->colour >> 0) & 0xFF) ) { - $Locals_ext = "!\xF9\x04".chr(($this->dis << 2) + 1).chr(($d >> 0) & 0xFF).chr(($d >> 8) & 0xFF).chr($j)."\x0"; + $Locals_ext = "!\xF9\x04" . chr(($this->dis << 2) + 1) . chr(($d >> 0) & 0xFF) . chr(($d >> 8) & 0xFF) . chr($j) . "\x0"; break; } } } $Locals_img = ''; - switch ($Locals_tmp { 0 }) { + switch ($Locals_tmp{0}) { case '!': $Locals_img = substr($Locals_tmp, 8, 10); $Locals_tmp = substr($Locals_tmp, 18, strlen($Locals_tmp) - 18); - break; + break; case ',': $Locals_img = substr($Locals_tmp, 0, 10); $Locals_tmp = substr($Locals_tmp, 10, strlen($Locals_tmp) - 10); - break; + break; } - if (ord($this->frameSources[$i] { 10 }) & 0x80 && $this->imgBuilt) { + if (ord($this->frameSources[$i]{10}) & 0x80 && $this->imgBuilt) { if ($Global_len == $Locals_len) { if ($this->gifBlockCompare($Global_rgb, $Locals_rgb, $Global_len)) { - $this->gif .= $Locals_ext.$Locals_img.$Locals_tmp; + $this->gif .= $Locals_ext . $Locals_img . $Locals_tmp; } else { - $byte = ord($Locals_img { 9 }); + $byte = ord($Locals_img{9}); $byte |= 0x80; $byte &= 0xF8; - $byte |= (ord($this->frameSources[0] { 10 }) & 0x07); - $Locals_img { 9 } = chr($byte); - $this->gif .= $Locals_ext.$Locals_img.$Locals_rgb.$Locals_tmp; + $byte |= (ord($this->frameSources[0]{10}) & 0x07); + $Locals_img{9} = chr($byte); + $this->gif .= $Locals_ext . $Locals_img . $Locals_rgb . $Locals_tmp; } } else { - $byte = ord($Locals_img { 9 }); + $byte = ord($Locals_img{9}); $byte |= 0x80; $byte &= 0xF8; - $byte |= (ord($this->frameSources[$i] { 10 }) & 0x07); - $Locals_img { 9 } = chr($byte); - $this->gif .= $Locals_ext.$Locals_img.$Locals_rgb.$Locals_tmp; + $byte |= (ord($this->frameSources[$i]{10}) & 0x07); + $Locals_img{9} = chr($byte); + $this->gif .= $Locals_ext . $Locals_img . $Locals_rgb . $Locals_tmp; } } else { - $this->gif .= $Locals_ext.$Locals_img.$Locals_tmp; + $this->gif .= $Locals_ext . $Locals_img . $Locals_tmp; } $this->imgBuilt = true; @@ -310,9 +310,10 @@ public function gifBlockCompare($globalBlock, $localBlock, $length) { for ($i = 0; $i < $length; $i++) { - if ($globalBlock { 3 * $i + 0 } != $localBlock { 3 * $i + 0 } || - $globalBlock { 3 * $i + 1 } != $localBlock { 3 * $i + 1 } || - $globalBlock { 3 * $i + 2 } != $localBlock { 3 * $i + 2 }) { + if ($globalBlock{3 * $i + 0} != $localBlock{3 * $i + 0} || + $globalBlock{3 * $i + 1} != $localBlock{3 * $i + 1} || + $globalBlock{3 * $i + 2} != $localBlock{3 * $i + 2} + ) { return 0; } @@ -331,7 +332,7 @@ public function gifBlockCompare($globalBlock, $localBlock, $length) */ public function encodeAsciiToChar($char) { - return (chr($char & 0xFF).chr(($char >> 8) & 0xFF)); + return (chr($char & 0xFF) . chr(($char >> 8) & 0xFF)); } /** @@ -339,7 +340,7 @@ public function encodeAsciiToChar($char) */ public function reset() { - $this->frameSources=[]; + $this->frameSources = []; $this->gif = 'GIF89a'; // the GIF header $this->imgBuilt = false; $this->loop = 0;