mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-09-16 20:56:28 +00:00
:octocat: +backslashes for built-in functions
This commit is contained in:
@@ -51,13 +51,13 @@ class AlphaNum extends QRDataAbstract{
|
||||
* @throws \chillerlan\QRCode\Data\QRCodeDataException
|
||||
*/
|
||||
protected function getCharCode(string $chr):int{
|
||||
$i = array_search($chr, $this::ALPHANUM_CHAR_MAP);
|
||||
$i = \array_search($chr, $this::ALPHANUM_CHAR_MAP);
|
||||
|
||||
if($i !== false){
|
||||
return $i;
|
||||
}
|
||||
|
||||
throw new QRCodeDataException('illegal char: "'.$chr.'" ['.ord($chr).']');
|
||||
throw new QRCodeDataException('illegal char: "'.$chr.'" ['.\ord($chr).']');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ class Byte extends QRDataAbstract{
|
||||
$i = 0;
|
||||
|
||||
while($i < $this->strlen){
|
||||
$this->bitBuffer->put(ord($data[$i]), 8);
|
||||
$this->bitBuffer->put(\ord($data[$i]), 8);
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -33,7 +33,7 @@ class Kanji extends QRDataAbstract{
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function getLength(string $data):int{
|
||||
return mb_strlen($data, 'SJIS');
|
||||
return \mb_strlen($data, 'SJIS');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,10 +43,10 @@ class Kanji extends QRDataAbstract{
|
||||
* @throws \chillerlan\QRCode\Data\QRCodeDataException
|
||||
*/
|
||||
protected function write(string $data):void{
|
||||
$len = strlen($data);
|
||||
$len = \strlen($data);
|
||||
|
||||
for($i = 0; $i + 1 < $len; $i += 2){
|
||||
$c = ((0xff & ord($data[$i])) << 8) | (0xff & ord($data[$i + 1]));
|
||||
$c = ((0xff & \ord($data[$i])) << 8) | (0xff & \ord($data[$i + 1]));
|
||||
|
||||
if(0x8140 <= $c && $c <= 0x9FFC){
|
||||
$c -= 0x8140;
|
||||
|
||||
@@ -56,7 +56,7 @@ class MaskPatternTester{
|
||||
$penalty = 0;
|
||||
|
||||
for($level = 1; $level <= 4; $level++){
|
||||
$penalty += call_user_func([$this, 'testLevel'.$level]);
|
||||
$penalty += \call_user_func([$this, 'testLevel'.$level]);
|
||||
}
|
||||
|
||||
return (int)$penalty;
|
||||
@@ -212,7 +212,7 @@ class MaskPatternTester{
|
||||
}
|
||||
}
|
||||
|
||||
return (abs(100 * $count / $this->moduleCount / $this->moduleCount - 50) / 5) * 10;
|
||||
return (\abs(100 * $count / $this->moduleCount / $this->moduleCount - 50) / 5) * 10;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-5
@@ -36,18 +36,18 @@ class Number extends QRDataAbstract{
|
||||
$i = 0;
|
||||
|
||||
while($i + 2 < $this->strlen){
|
||||
$this->bitBuffer->put($this->parseInt(substr($data, $i, 3)), 10);
|
||||
$this->bitBuffer->put($this->parseInt(\substr($data, $i, 3)), 10);
|
||||
$i += 3;
|
||||
}
|
||||
|
||||
if($i < $this->strlen){
|
||||
|
||||
if($this->strlen - $i === 1){
|
||||
$this->bitBuffer->put($this->parseInt(substr($data, $i, $i + 1)), 4);
|
||||
$this->bitBuffer->put($this->parseInt(\substr($data, $i, $i + 1)), 4);
|
||||
}
|
||||
// @codeCoverageIgnoreStart
|
||||
elseif($this->strlen - $i === 2){
|
||||
$this->bitBuffer->put($this->parseInt(substr($data, $i, $i + 2)), 7);
|
||||
$this->bitBuffer->put($this->parseInt(\substr($data, $i, $i + 2)), 7);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
@@ -66,13 +66,13 @@ class Number extends QRDataAbstract{
|
||||
|
||||
$len = strlen($string);
|
||||
for($i = 0; $i < $len; $i++){
|
||||
$c = ord($string[$i]);
|
||||
$c = \ord($string[$i]);
|
||||
|
||||
if(!in_array($string[$i], $this::NUMBER_CHAR_MAP, true)){
|
||||
throw new QRCodeDataException('illegal char: "'.$string[$i].'" ['.$c.']');
|
||||
}
|
||||
|
||||
$c = $c - ord('0');
|
||||
$c = $c - \ord('0');
|
||||
|
||||
$num = $num * 10 + $c;
|
||||
}
|
||||
|
||||
+14
-14
@@ -104,7 +104,7 @@ abstract class QRDataAbstract implements QRDataInterface{
|
||||
public function setData(string $data):QRDataInterface{
|
||||
|
||||
if($this->datamode === QRCode::DATA_KANJI){
|
||||
$data = mb_convert_encoding($data, 'SJIS', mb_detect_encoding($data));
|
||||
$data = \mb_convert_encoding($data, 'SJIS', \mb_detect_encoding($data));
|
||||
}
|
||||
|
||||
$this->strlen = $this->getLength($data);
|
||||
@@ -169,7 +169,7 @@ abstract class QRDataAbstract implements QRDataInterface{
|
||||
* @return int
|
||||
*/
|
||||
protected function getLength(string $data):int{
|
||||
return strlen($data);
|
||||
return \strlen($data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,7 +182,7 @@ abstract class QRDataAbstract implements QRDataInterface{
|
||||
$maxlength = 0;
|
||||
|
||||
// guess the version number within the given range
|
||||
foreach(range($this->options->versionMin, $this->options->versionMax) as $version){
|
||||
foreach(\range($this->options->versionMin, $this->options->versionMax) as $version){
|
||||
$maxlength = $this::MAX_LENGTH[$version][QRCode::DATA_MODES[$this->datamode]][QRCode::ECC_MODES[$this->options->eccLevel]];
|
||||
|
||||
if($this->strlen <= $maxlength){
|
||||
@@ -270,13 +270,13 @@ abstract class QRDataAbstract implements QRDataInterface{
|
||||
protected function maskECC():array{
|
||||
[$l1, $l2, $b1, $b2] = $this::RSBLOCKS[$this->version][QRCode::ECC_MODES[$this->options->eccLevel]];
|
||||
|
||||
$rsBlocks = array_fill(0, $l1, [$b1, $b2]);
|
||||
$rsBlocks = \array_fill(0, $l1, [$b1, $b2]);
|
||||
$rsCount = $l1 + $l2;
|
||||
$this->ecdata = array_fill(0, $rsCount, null);
|
||||
$this->ecdata = \array_fill(0, $rsCount, null);
|
||||
$this->dcdata = $this->ecdata;
|
||||
|
||||
if($l2 > 0){
|
||||
$rsBlocks = array_merge($rsBlocks, array_fill(0, $l2, [$b1 + 1, $b2 + 1]));
|
||||
$rsBlocks = \array_merge($rsBlocks, \array_fill(0, $l2, [$b1 + 1, $b2 + 1]));
|
||||
}
|
||||
|
||||
$totalCodeCount = 0;
|
||||
@@ -288,9 +288,9 @@ abstract class QRDataAbstract implements QRDataInterface{
|
||||
[$rsBlockTotal, $dcCount] = $block;
|
||||
|
||||
$ecCount = $rsBlockTotal - $dcCount;
|
||||
$maxDcCount = max($maxDcCount, $dcCount);
|
||||
$maxEcCount = max($maxEcCount, $ecCount);
|
||||
$this->dcdata[$key] = array_fill(0, $dcCount, null);
|
||||
$maxDcCount = \max($maxDcCount, $dcCount);
|
||||
$maxEcCount = \max($maxEcCount, $ecCount);
|
||||
$this->dcdata[$key] = \array_fill(0, $dcCount, null);
|
||||
|
||||
foreach($this->dcdata[$key] as $a => $_z){
|
||||
$this->dcdata[$key][$a] = 0xff & $this->bitBuffer->buffer[$a + $offset];
|
||||
@@ -307,13 +307,13 @@ abstract class QRDataAbstract implements QRDataInterface{
|
||||
$totalCodeCount += $rsBlockTotal;
|
||||
}
|
||||
|
||||
$data = array_fill(0, $totalCodeCount, null);
|
||||
$data = \array_fill(0, $totalCodeCount, null);
|
||||
$index = 0;
|
||||
|
||||
$mask = function($arr, $count) use (&$data, &$index, $rsCount){
|
||||
for($x = 0; $x < $count; $x++){
|
||||
for($y = 0; $y < $rsCount; $y++){
|
||||
if($x < count($arr[$y])){
|
||||
if($x < \count($arr[$y])){
|
||||
$data[$index] = $arr[$y][$x];
|
||||
$index++;
|
||||
}
|
||||
@@ -342,19 +342,19 @@ abstract class QRDataAbstract implements QRDataInterface{
|
||||
$rsPoly->multiply($modPoly->getNum());
|
||||
}
|
||||
|
||||
$rsPolyCount = count($rsPoly->getNum());
|
||||
$rsPolyCount = \count($rsPoly->getNum());
|
||||
|
||||
$modPoly
|
||||
->setNum($this->dcdata[$key], $rsPolyCount - 1)
|
||||
->mod($rsPoly->getNum())
|
||||
;
|
||||
|
||||
$this->ecdata[$key] = array_fill(0, $rsPolyCount - 1, null);
|
||||
$this->ecdata[$key] = \array_fill(0, $rsPolyCount - 1, null);
|
||||
$num = $modPoly->getNum();
|
||||
|
||||
return [
|
||||
$num,
|
||||
count($num) - count($this->ecdata[$key]),
|
||||
\count($num) - \count($this->ecdata[$key]),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
+13
-13
@@ -135,18 +135,18 @@ class QRMatrix{
|
||||
*/
|
||||
public function __construct(int $version, int $eclevel){
|
||||
|
||||
if(!in_array($version, range(1, 40), true)){
|
||||
if(!\in_array($version, \range(1, 40), true)){
|
||||
throw new QRCodeDataException('invalid QR Code version');
|
||||
}
|
||||
|
||||
if(!array_key_exists($eclevel, QRCode::ECC_MODES)){
|
||||
if(!\array_key_exists($eclevel, QRCode::ECC_MODES)){
|
||||
throw new QRCodeDataException('invalid ecc level');
|
||||
}
|
||||
|
||||
$this->version = $version;
|
||||
$this->eclevel = $eclevel;
|
||||
$this->moduleCount = $this->version * 4 + 17;
|
||||
$this->matrix = array_fill(0, $this->moduleCount, array_fill(0, $this->moduleCount, $this::M_NULL));
|
||||
$this->matrix = \array_fill(0, $this->moduleCount, \array_fill(0, $this->moduleCount, $this::M_NULL));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -346,7 +346,7 @@ class QRMatrix{
|
||||
*/
|
||||
public function setTimingPattern():QRMatrix{
|
||||
|
||||
foreach(range(8, $this->moduleCount - 8 - 1) as $i){
|
||||
foreach(\range(8, $this->moduleCount - 8 - 1) as $i){
|
||||
|
||||
if($this->matrix[6][$i] !== $this::M_NULL || $this->matrix[$i][6] !== $this::M_NULL){
|
||||
continue;
|
||||
@@ -375,7 +375,7 @@ class QRMatrix{
|
||||
if($bits !== false){
|
||||
|
||||
for($i = 0; $i < 18; $i++){
|
||||
$a = (int)floor($i / 3);
|
||||
$a = (int)\floor($i / 3);
|
||||
$b = $i % 3 + $this->moduleCount - 8 - 3;
|
||||
$v = !$test && (($bits >> $i) & 1) === 1;
|
||||
|
||||
@@ -445,22 +445,22 @@ class QRMatrix{
|
||||
throw new QRCodeDataException('use only after writing data');
|
||||
}
|
||||
|
||||
$size = $size !== null ? max(0, min($size, floor($this->moduleCount / 2))) : 4;
|
||||
$size = $size !== null ? \max(0, \min($size, \floor($this->moduleCount / 2))) : 4;
|
||||
$t = $this::M_QUIETZONE;
|
||||
|
||||
for($y = 0; $y < $this->moduleCount; $y++){
|
||||
for($i = 0; $i < $size; $i++){
|
||||
array_unshift($this->matrix[$y], $t);
|
||||
array_push($this->matrix[$y], $t);
|
||||
\array_unshift($this->matrix[$y], $t);
|
||||
\array_push($this->matrix[$y], $t);
|
||||
}
|
||||
}
|
||||
|
||||
$this->moduleCount += ($size * 2);
|
||||
$r = array_fill(0, $this->moduleCount, $t);
|
||||
$r = \array_fill(0, $this->moduleCount, $t);
|
||||
|
||||
for($i = 0; $i < $size; $i++){
|
||||
array_unshift($this->matrix, $r);
|
||||
array_push($this->matrix, $r);
|
||||
\array_unshift($this->matrix, $r);
|
||||
\array_push($this->matrix, $r);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -478,7 +478,7 @@ class QRMatrix{
|
||||
*/
|
||||
public function mapData(array $data, int $maskPattern):QRMatrix{
|
||||
$this->maskPattern = $maskPattern;
|
||||
$byteCount = count($data);
|
||||
$byteCount = \count($data);
|
||||
$size = $this->moduleCount - 1;
|
||||
|
||||
for($i = $size, $y = $size, $inc = -1, $byteIndex = 0, $bitIndex = 7; $i > 0; $i -= 2){
|
||||
@@ -551,7 +551,7 @@ class QRMatrix{
|
||||
$y % 2,
|
||||
$x % 3,
|
||||
$a % 3,
|
||||
(floor($y / 2) + floor($x / 3)) % 2,
|
||||
(\floor($y / 2) + \floor($x / 3)) % 2,
|
||||
$m % 2 + $m % 3,
|
||||
($m % 2 + $m % 3) % 2,
|
||||
($m % 3 + $a % 2) % 2
|
||||
|
||||
@@ -55,9 +55,9 @@ class BitBuffer{
|
||||
* @return \chillerlan\QRCode\Helpers\BitBuffer
|
||||
*/
|
||||
public function putBit(bool $bit):BitBuffer{
|
||||
$bufIndex = floor($this->length / 8);
|
||||
$bufIndex = \floor($this->length / 8);
|
||||
|
||||
if(count($this->buffer) <= $bufIndex){
|
||||
if(\count($this->buffer) <= $bufIndex){
|
||||
$this->buffer[] = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,13 +87,13 @@ class Polynomial{
|
||||
*/
|
||||
public function setNum(array $num, int $shift = null):Polynomial{
|
||||
$offset = 0;
|
||||
$numCount = count($num);
|
||||
$numCount = \count($num);
|
||||
|
||||
while($offset < $numCount && $num[$offset] === 0){
|
||||
$offset++;
|
||||
}
|
||||
|
||||
$this->num = array_fill(0, $numCount - $offset + ($shift ?? 0), 0);
|
||||
$this->num = \array_fill(0, $numCount - $offset + ($shift ?? 0), 0);
|
||||
|
||||
for($i = 0; $i < $numCount - $offset; $i++){
|
||||
$this->num[$i] = $num[$i + $offset];
|
||||
@@ -108,7 +108,7 @@ class Polynomial{
|
||||
* @return \chillerlan\QRCode\Helpers\Polynomial
|
||||
*/
|
||||
public function multiply(array $e):Polynomial{
|
||||
$n = array_fill(0, count($this->num) + count($e) - 1, 0);
|
||||
$n = \array_fill(0, \count($this->num) + \count($e) - 1, 0);
|
||||
|
||||
foreach($this->num as $i => $vi){
|
||||
$vi = $this->glog($vi);
|
||||
@@ -132,7 +132,7 @@ class Polynomial{
|
||||
public function mod(array $e):Polynomial{
|
||||
$n = $this->num;
|
||||
|
||||
if(count($n) - count($e) < 0){
|
||||
if(\count($n) - \count($e) < 0){
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
+20
-20
@@ -51,13 +51,13 @@ class QRImage extends QROutputAbstract{
|
||||
foreach($this::DEFAULT_MODULE_VALUES as $M_TYPE => $defaultValue){
|
||||
$v = $this->options->moduleValues[$M_TYPE] ?? null;
|
||||
|
||||
if(!is_array($v) || count($v) < 3){
|
||||
if(!\is_array($v) || \count($v) < 3){
|
||||
$this->moduleValues[$M_TYPE] = $defaultValue
|
||||
? [0, 0, 0]
|
||||
: [255, 255, 255];
|
||||
}
|
||||
else{
|
||||
$this->moduleValues[$M_TYPE] = array_values($v);
|
||||
$this->moduleValues[$M_TYPE] = \array_values($v);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -70,14 +70,14 @@ class QRImage extends QROutputAbstract{
|
||||
* @return string
|
||||
*/
|
||||
public function dump(string $file = null):string{
|
||||
$this->image = imagecreatetruecolor($this->length, $this->length);
|
||||
$this->background = imagecolorallocate($this->image, ...$this->options->imageTransparencyBG);
|
||||
$this->image = \imagecreatetruecolor($this->length, $this->length);
|
||||
$this->background = \imagecolorallocate($this->image, ...$this->options->imageTransparencyBG);
|
||||
|
||||
if((bool)$this->options->imageTransparent && in_array($this->options->outputType, $this::TRANSPARENCY_TYPES, true)){
|
||||
imagecolortransparent($this->image, $this->background);
|
||||
if((bool)$this->options->imageTransparent && \in_array($this->options->outputType, $this::TRANSPARENCY_TYPES, true)){
|
||||
\imagecolortransparent($this->image, $this->background);
|
||||
}
|
||||
|
||||
imagefilledrectangle($this->image, 0, 0, $this->length, $this->length, $this->background);
|
||||
\imagefilledrectangle($this->image, 0, 0, $this->length, $this->length, $this->background);
|
||||
|
||||
foreach($this->matrix->matrix() as $y => $row){
|
||||
foreach($row as $x => $M_TYPE){
|
||||
@@ -88,7 +88,7 @@ class QRImage extends QROutputAbstract{
|
||||
$imageData = $this->dumpImage($file);
|
||||
|
||||
if((bool)$this->options->imageBase64){
|
||||
$imageData = 'data:image/'.$this->options->outputType.';base64,'.base64_encode($imageData);
|
||||
$imageData = 'data:image/'.$this->options->outputType.';base64,'.\base64_encode($imageData);
|
||||
}
|
||||
|
||||
return $imageData;
|
||||
@@ -102,13 +102,13 @@ class QRImage extends QROutputAbstract{
|
||||
* @return void
|
||||
*/
|
||||
protected function setPixel(int $x, int $y, array $rgb):void{
|
||||
imagefilledrectangle(
|
||||
\imagefilledrectangle(
|
||||
$this->image,
|
||||
$x * $this->scale,
|
||||
$y * $this->scale,
|
||||
($x + 1) * $this->scale,
|
||||
($y + 1) * $this->scale,
|
||||
imagecolorallocate($this->image, ...$rgb)
|
||||
\imagecolorallocate($this->image, ...$rgb)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -122,10 +122,10 @@ class QRImage extends QROutputAbstract{
|
||||
protected function dumpImage(string $file = null):string{
|
||||
$file = $file ?? $this->options->cachefile;
|
||||
|
||||
ob_start();
|
||||
\ob_start();
|
||||
|
||||
try{
|
||||
call_user_func([$this, $this->outputMode ?? $this->defaultMode]);
|
||||
\call_user_func([$this, $this->outputMode ?? $this->defaultMode]);
|
||||
}
|
||||
// not going to cover edge cases
|
||||
// @codeCoverageIgnoreStart
|
||||
@@ -134,10 +134,10 @@ class QRImage extends QROutputAbstract{
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
$imageData = ob_get_contents();
|
||||
imagedestroy($this->image);
|
||||
$imageData = \ob_get_contents();
|
||||
\imagedestroy($this->image);
|
||||
|
||||
ob_end_clean();
|
||||
\ob_end_clean();
|
||||
|
||||
if($file !== null){
|
||||
$this->saveToFile($imageData, $file);
|
||||
@@ -150,10 +150,10 @@ class QRImage extends QROutputAbstract{
|
||||
* @return void
|
||||
*/
|
||||
protected function png():void{
|
||||
imagepng(
|
||||
\imagepng(
|
||||
$this->image,
|
||||
null,
|
||||
in_array($this->options->pngCompression, range(-1, 9), true)
|
||||
\in_array($this->options->pngCompression, \range(-1, 9), true)
|
||||
? $this->options->pngCompression
|
||||
: -1
|
||||
);
|
||||
@@ -164,17 +164,17 @@ class QRImage extends QROutputAbstract{
|
||||
* @return void
|
||||
*/
|
||||
protected function gif():void{
|
||||
imagegif($this->image);
|
||||
\imagegif($this->image);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function jpg():void{
|
||||
imagejpeg(
|
||||
\imagejpeg(
|
||||
$this->image,
|
||||
null,
|
||||
in_array($this->options->jpegQuality, range(0, 100), true)
|
||||
\in_array($this->options->jpegQuality, \range(0, 100), true)
|
||||
? $this->options->jpegQuality
|
||||
: 85
|
||||
);
|
||||
|
||||
@@ -39,13 +39,13 @@ class QRMarkup extends QROutputAbstract{
|
||||
foreach($this::DEFAULT_MODULE_VALUES as $M_TYPE => $defaultValue){
|
||||
$v = $this->options->moduleValues[$M_TYPE] ?? null;
|
||||
|
||||
if(!is_string($v)){
|
||||
if(!\is_string($v)){
|
||||
$this->moduleValues[$M_TYPE] = $defaultValue
|
||||
? $this->options->markupDark
|
||||
: $this->options->markupLight;
|
||||
}
|
||||
else{
|
||||
$this->moduleValues[$M_TYPE] = trim(strip_tags($v), '\'"');
|
||||
$this->moduleValues[$M_TYPE] = \trim(\strip_tags($v), '\'"');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -85,7 +85,7 @@ class QRMarkup extends QROutputAbstract{
|
||||
protected function svg():string{
|
||||
$matrix = $this->matrix->matrix();
|
||||
|
||||
$svg = sprintf($this->svgHeader, $this->options->cssClass, $this->options->svgViewBoxSize ?? $this->moduleCount)
|
||||
$svg = \sprintf($this->svgHeader, $this->options->cssClass, $this->options->svgViewBoxSize ?? $this->moduleCount)
|
||||
.$this->options->eol
|
||||
.'<defs>'.$this->options->svgDefs.'</defs>'
|
||||
.$this->options->eol;
|
||||
|
||||
@@ -73,9 +73,9 @@ abstract class QROutputAbstract implements QROutputInterface{
|
||||
$this->scale = $this->options->scale;
|
||||
$this->length = $this->moduleCount * $this->scale;
|
||||
|
||||
$class = get_called_class();
|
||||
$class = \get_called_class();
|
||||
|
||||
if(array_key_exists($class, QRCode::OUTPUT_MODES) && in_array($this->options->outputType, QRCode::OUTPUT_MODES[$class])){
|
||||
if(\array_key_exists($class, QRCode::OUTPUT_MODES) && \in_array($this->options->outputType, QRCode::OUTPUT_MODES[$class])){
|
||||
$this->outputMode = $this->options->outputType;
|
||||
}
|
||||
|
||||
@@ -100,11 +100,11 @@ abstract class QROutputAbstract implements QROutputInterface{
|
||||
*/
|
||||
protected function saveToFile(string $data, string $file):bool{
|
||||
|
||||
if(!is_writable(dirname($file))){
|
||||
if(!\is_writable(\dirname($file))){
|
||||
throw new QRCodeOutputException('Could not write data to cache file: '.$file);
|
||||
}
|
||||
|
||||
return (bool)file_put_contents($file, $data);
|
||||
return (bool)\file_put_contents($file, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,7 +113,7 @@ abstract class QROutputAbstract implements QROutputInterface{
|
||||
* @return string|mixed
|
||||
*/
|
||||
public function dump(string $file = null){
|
||||
$data = call_user_func([$this, $this->outputMode ?? $this->defaultMode]);
|
||||
$data = \call_user_func([$this, $this->outputMode ?? $this->defaultMode]);
|
||||
$file = $file ?? $this->options->cachefile;
|
||||
|
||||
if($file !== null){
|
||||
|
||||
@@ -58,17 +58,17 @@ class QRString extends QROutputAbstract{
|
||||
$r[] = $this->moduleValues[$M_TYPE];
|
||||
}
|
||||
|
||||
$str[] = implode('', $r);
|
||||
$str[] = \implode('', $r);
|
||||
}
|
||||
|
||||
return implode($this->options->eol, $str);
|
||||
return \implode($this->options->eol, $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function json():string{
|
||||
return json_encode($this->matrix->matrix());
|
||||
return \json_encode($this->matrix->matrix());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-11
@@ -111,9 +111,9 @@ class QRCode{
|
||||
*/
|
||||
public function __construct(SettingsContainerInterface $options = null){
|
||||
// save the current mb encoding (in case it differs from UTF-8)
|
||||
$this->mbCurrentEncoding = mb_internal_encoding();
|
||||
$this->mbCurrentEncoding = \mb_internal_encoding();
|
||||
// use UTF-8 from here on
|
||||
mb_internal_encoding('UTF-8');
|
||||
\mb_internal_encoding('UTF-8');
|
||||
|
||||
$this->options = $options ?? new QROptions;
|
||||
}
|
||||
@@ -123,7 +123,7 @@ class QRCode{
|
||||
*/
|
||||
public function __destruct(){
|
||||
// restore the previous mb_internal_encoding, so that we don't mess up the rest of the script
|
||||
mb_internal_encoding($this->mbCurrentEncoding);
|
||||
\mb_internal_encoding($this->mbCurrentEncoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,7 +183,7 @@ class QRCode{
|
||||
$penalties[$pattern] = $tester->testPattern();
|
||||
}
|
||||
|
||||
return array_search(min($penalties), $penalties, true);
|
||||
return \array_search(\min($penalties), $penalties, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,7 +199,7 @@ class QRCode{
|
||||
foreach(['Number', 'AlphaNum', 'Kanji', 'Byte'] as $mode){
|
||||
$dataInterface = __NAMESPACE__.'\\Data\\'.$mode;
|
||||
|
||||
if(call_user_func_array([$this, 'is'.$mode], [$data]) && class_exists($dataInterface)){
|
||||
if(\call_user_func_array([$this, 'is'.$mode], [$data]) && \class_exists($dataInterface)){
|
||||
return new $dataInterface($this->options, $data);
|
||||
}
|
||||
|
||||
@@ -218,13 +218,13 @@ class QRCode{
|
||||
*/
|
||||
protected function initOutputInterface(string $data):QROutputInterface{
|
||||
|
||||
if($this->options->outputType === $this::OUTPUT_CUSTOM && class_exists($this->options->outputInterface)){
|
||||
if($this->options->outputType === $this::OUTPUT_CUSTOM && \class_exists($this->options->outputInterface)){
|
||||
return new $this->options->outputInterface($this->options, $this->getMatrix($data));
|
||||
}
|
||||
|
||||
foreach($this::OUTPUT_MODES as $outputInterface => $modes){
|
||||
|
||||
if(in_array($this->options->outputType, $modes, true) && class_exists($outputInterface)){
|
||||
if(in_array($this->options->outputType, $modes, true) && \class_exists($outputInterface)){
|
||||
return new $outputInterface($this->options, $this->getMatrix($data));
|
||||
}
|
||||
|
||||
@@ -264,10 +264,10 @@ class QRCode{
|
||||
* @return bool
|
||||
*/
|
||||
protected function checkString(string $string, array $charmap):bool{
|
||||
$len = strlen($string);
|
||||
$len = \strlen($string);
|
||||
|
||||
for($i = 0; $i < $len; $i++){
|
||||
if(!in_array($string[$i], $charmap, true)){
|
||||
if(!\in_array($string[$i], $charmap, true)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -284,10 +284,10 @@ class QRCode{
|
||||
*/
|
||||
public function isKanji(string $string):bool{
|
||||
$i = 0;
|
||||
$len = strlen($string);
|
||||
$len = \strlen($string);
|
||||
|
||||
while($i + 1 < $len){
|
||||
$c = ((0xff&ord($string[$i])) << 8)|(0xff&ord($string[$i + 1]));
|
||||
$c = ((0xff&\ord($string[$i])) << 8)|(0xff&\ord($string[$i + 1]));
|
||||
|
||||
if(!($c >= 0x8140 && $c <= 0x9FFC) && !($c >= 0xE040 && $c <= 0xEBBF)){
|
||||
return false;
|
||||
|
||||
+11
-11
@@ -249,7 +249,7 @@ trait QROptionsTrait{
|
||||
*/
|
||||
public function __set(string $property, $value):void{
|
||||
|
||||
if(in_array($property, ['eccLevel', 'maskPattern', 'imageTransparencyBG', 'version'], true)){
|
||||
if(\in_array($property, ['eccLevel', 'maskPattern', 'imageTransparencyBG', 'version'], true)){
|
||||
$this->{'set_'.$property}($value);
|
||||
|
||||
return;
|
||||
@@ -277,11 +277,11 @@ trait QROptionsTrait{
|
||||
* @return void
|
||||
*/
|
||||
protected function setMinMaxVersion(int $versionMin, int $versionMax):void{
|
||||
$min = max(1, min(40, $versionMin));
|
||||
$max = max(1, min(40, $versionMax));
|
||||
$min = \max(1, \min(40, $versionMin));
|
||||
$max = \max(1, \min(40, $versionMax));
|
||||
|
||||
$this->versionMin = min($min, $max);
|
||||
$this->versionMax = max($min, $max);
|
||||
$this->versionMin = \min($min, $max);
|
||||
$this->versionMax = \max($min, $max);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,7 +307,7 @@ trait QROptionsTrait{
|
||||
protected function set_maskPattern(int $maskPattern):void{
|
||||
|
||||
if($maskPattern !== QRCode::MASK_PATTERN_AUTO){
|
||||
$this->maskPattern = max(0, min(7, $maskPattern));
|
||||
$this->maskPattern = \max(0, \min(7, $maskPattern));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -321,7 +321,7 @@ trait QROptionsTrait{
|
||||
protected function set_imageTransparencyBG($imageTransparencyBG):void{
|
||||
|
||||
// invalid value - set to white as default
|
||||
if(!is_array($imageTransparencyBG) || count($imageTransparencyBG) < 3){
|
||||
if(!\is_array($imageTransparencyBG) || \count($imageTransparencyBG) < 3){
|
||||
$this->imageTransparencyBG = [255, 255, 255];
|
||||
|
||||
return;
|
||||
@@ -329,16 +329,16 @@ trait QROptionsTrait{
|
||||
|
||||
foreach($imageTransparencyBG as $k => $v){
|
||||
|
||||
if(!is_numeric($v)){
|
||||
if(!\is_numeric($v)){
|
||||
throw new QRCodeException('Invalid RGB value.');
|
||||
}
|
||||
|
||||
// clamp the values
|
||||
$this->imageTransparencyBG[$k] = max(0, min(255, (int)$v));
|
||||
$this->imageTransparencyBG[$k] = \max(0, \min(255, (int)$v));
|
||||
}
|
||||
|
||||
// use the array values to not run into errors with the spread operator (...$arr)
|
||||
$this->imageTransparencyBG = array_values($this->imageTransparencyBG);
|
||||
$this->imageTransparencyBG = \array_values($this->imageTransparencyBG);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -349,7 +349,7 @@ trait QROptionsTrait{
|
||||
protected function set_version(int $version):void{
|
||||
|
||||
if($version !== QRCode::VERSION_AUTO){
|
||||
$this->version = max(1, min(40, $version));
|
||||
$this->version = \max(1, \min(40, $version));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user