mirror of
https://github.com/tecnickcom/TCPDF.git
synced 2025-01-16 13:50:01 +01:00
Add PHPStan and fix level 1 errors (#307)
* Add PHPStan level 1 Co-authored-by: Nicola Asuni <nicolaasuni@users.noreply.github.com>
This commit is contained in:
parent
154bba45ff
commit
37aa6eeb73
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -3,3 +3,4 @@
|
||||
/.gitattributes export-ignore
|
||||
/tests export-ignore
|
||||
/scripts export-ignore
|
||||
/phpstan.neon.dist export-ignore
|
||||
|
20
.github/workflows/tests.yml
vendored
20
.github/workflows/tests.yml
vendored
@ -54,3 +54,23 @@ jobs:
|
||||
with:
|
||||
flags: php-${{ matrix.php-version }}-${{ matrix.os }}
|
||||
name: php-${{ matrix.php-version }}-${{ matrix.os }}
|
||||
|
||||
analyse-php:
|
||||
name: Static Analysis
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use php 8.0
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 8.0
|
||||
tools: composer:v2
|
||||
- name: Cache module
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.composer/cache/
|
||||
key: composer-cache
|
||||
- name: Install phpstan
|
||||
run: composer require --dev phpstan/phpstan
|
||||
- name: Analyse files
|
||||
run: ./vendor/bin/phpstan --memory-limit=2G
|
||||
|
@ -778,7 +778,7 @@ class Datamatrix {
|
||||
if (isset($this->chset['SH1'][$chr])) {
|
||||
$temp_cw[] = 0; // shift 1
|
||||
$shiftset = $this->chset['SH1'];
|
||||
} elseif (isset($chr, $this->chset['SH2'][$chr])) {
|
||||
} elseif (isset($this->chset['SH2'][$chr])) {
|
||||
$temp_cw[] = 1; // shift 2
|
||||
$shiftset = $this->chset['SH2'];
|
||||
} elseif (($enc == ENC_C40) AND isset($this->chset['S3C'][$chr])) {
|
||||
|
@ -1062,7 +1062,7 @@ class QRcode {
|
||||
protected function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly=false) {
|
||||
$b = 0;
|
||||
$bitMask = array();
|
||||
$bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
|
||||
$bitMask = $this->generateMaskNo($maskNo, $width, $s);
|
||||
if ($maskGenOnly) {
|
||||
return;
|
||||
}
|
||||
@ -1460,7 +1460,7 @@ class QRcode {
|
||||
$stringLen = strlen($this->dataStr);
|
||||
$p = 0;
|
||||
while ($p < $stringLen) {
|
||||
$mode = $this->identifyMode(substr($this->dataStr, $p), $this->hint);
|
||||
$mode = $this->identifyMode(substr($this->dataStr, $p));
|
||||
if ($mode == QR_MODE_KJ) {
|
||||
$p += 2;
|
||||
} else {
|
||||
@ -1692,7 +1692,7 @@ class QRcode {
|
||||
return -1;
|
||||
}
|
||||
$buf = array($size, $index, $parity);
|
||||
$entry = $this->newInputItem(QR_MODE_ST, 3, buf);
|
||||
$entry = $this->newInputItem(QR_MODE_ST, 3, $buf);
|
||||
array_unshift($items, $entry);
|
||||
return $items;
|
||||
}
|
||||
|
@ -128,39 +128,6 @@ class TCPDF_STATIC {
|
||||
return "\x54\x43\x50\x44\x46\x20".self::getTCPDFVersion()."\x20\x28\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist)
|
||||
* @param boolean $mqr FALSE for off, TRUE for on.
|
||||
* @since 4.6.025 (2009-08-17)
|
||||
* @public static
|
||||
*/
|
||||
public static function set_mqr($mqr) {
|
||||
if (!defined('PHP_VERSION_ID')) {
|
||||
$version = PHP_VERSION;
|
||||
define('PHP_VERSION_ID', (($version[0] * 10000) + ($version[2] * 100) + $version[4]));
|
||||
}
|
||||
if (PHP_VERSION_ID < 50300) {
|
||||
@set_magic_quotes_runtime($mqr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist)
|
||||
* @return int Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise.
|
||||
* @since 4.6.025 (2009-08-17)
|
||||
* @public static
|
||||
*/
|
||||
public static function get_mqr() {
|
||||
if (!defined('PHP_VERSION_ID')) {
|
||||
$version = PHP_VERSION;
|
||||
define('PHP_VERSION_ID', (($version[0] * 10000) + ($version[2] * 100) + $version[4]));
|
||||
}
|
||||
if (PHP_VERSION_ID < 50300) {
|
||||
return @get_magic_quotes_runtime();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the URL exist.
|
||||
* @param string $url URL to check.
|
||||
@ -852,9 +819,7 @@ class TCPDF_STATIC {
|
||||
if (isset($prop['charLimit'])) {
|
||||
$opt['maxlen'] = intval($prop['charLimit']);
|
||||
}
|
||||
if (!isset($ff)) {
|
||||
$ff = 0; // default value
|
||||
}
|
||||
$ff = 0;
|
||||
// readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
|
||||
if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
|
||||
$ff += 1 << 0;
|
||||
|
32
phpstan.neon.dist
Normal file
32
phpstan.neon.dist
Normal file
@ -0,0 +1,32 @@
|
||||
parameters:
|
||||
level: 1
|
||||
paths:
|
||||
- ./
|
||||
excludePaths:
|
||||
- vendor/
|
||||
# remove once https://github.com/phpstan/phpstan/issues/7955 is fixed
|
||||
- fonts/
|
||||
|
||||
scanFiles:
|
||||
- tcpdf_autoconfig.php
|
||||
|
||||
ignoreErrors:
|
||||
- '~^Constant (PDF_HEADER_LOGO|K_PATH_CACHE|K_PATH_FONTS|K_PATH_IMAGES|K_PATH_URL) not found\.$~'
|
||||
- '~^Constructor of class TCPDF has an unused parameter \$diskcache\.$~'
|
||||
- '~^Variable \$\w+ might not be defined\.$~'
|
||||
- '~^Method TCPDF(_FILTERS)?::\w+\(\) should return .+ but return statement is missing\.$~'
|
||||
|
||||
# mcrypt does not support PHP 7.2 or later
|
||||
-
|
||||
message: '~^(Constant MCRYPT_RIJNDAEL_128 not found\.|Function mcrypt_get_cipher_name not found\.)$~'
|
||||
path: tcpdf.php
|
||||
count: 2
|
||||
-
|
||||
message: '~^(Constant (MCRYPT_ARCFOUR|MCRYPT_MODE_CBC|MCRYPT_MODE_STREAM|MCRYPT_RAND|MCRYPT_RIJNDAEL_128) not found\.|Function (mcrypt_create_iv|mcrypt_encrypt|mcrypt_get_iv_size) not found\.)$~'
|
||||
path: include/tcpdf_static.php
|
||||
count: 16
|
||||
|
||||
-
|
||||
message: '~^(Call to static method create\(\) on an unknown class Symfony\\Component\\Finder\\Finder\.|Instantiated class Doctum\\(Doctum|RemoteRepository\\GitHubRemoteRepository) not found\.)$~'
|
||||
path: scripts/doctum.php
|
||||
count: 3
|
55
tcpdf.php
55
tcpdf.php
@ -4347,6 +4347,22 @@ class TCPDF {
|
||||
}
|
||||
// include font file
|
||||
if (!TCPDF_STATIC::empty_string($fontfile) AND (@TCPDF_STATIC::file_exists($fontfile))) {
|
||||
$type=null;
|
||||
$name=null;
|
||||
$desc=null;
|
||||
$up=-null;
|
||||
$ut=null;
|
||||
$cw=null;
|
||||
$cbbox=null;
|
||||
$dw=null;
|
||||
$enc=null;
|
||||
$cidinfo=null;
|
||||
$file=null;
|
||||
$ctg=null;
|
||||
$diff=null;
|
||||
$originalsize=null;
|
||||
$size1=null;
|
||||
$size2=null;
|
||||
include($fontfile);
|
||||
} else {
|
||||
$this->Error('Could not include font definition file: '.$family.'');
|
||||
@ -5524,12 +5540,12 @@ class TCPDF {
|
||||
$xdk = $xdx * $k;
|
||||
// print text
|
||||
$s .= sprintf('BT %F %F Td [(%s)] TJ ET', $xdk, (($this->h - $basefonty) * $k), $txt2);
|
||||
if (isset($uniblock)) {
|
||||
if (isset($uniblock)) { // @phpstan-ignore-line
|
||||
// print overlapping characters as separate string
|
||||
$xshift = 0; // horizontal shift
|
||||
$ty = (($this->h - $basefonty + (0.2 * $this->FontSize)) * $k);
|
||||
$spw = (($w - $txwidth - $this->cell_padding['L'] - $this->cell_padding['R']) / ($ns?$ns:1));
|
||||
foreach ($uniblock as $uk => $uniarr) {
|
||||
foreach ($uniblock as $uk => $uniarr) { // @phpstan-ignore-line
|
||||
if (($uk % 2) == 0) {
|
||||
// x space to skip
|
||||
if ($spacewidth != 0) {
|
||||
@ -7101,8 +7117,6 @@ class TCPDF {
|
||||
} elseif ($type == 'jpg') {
|
||||
$type = 'jpeg';
|
||||
}
|
||||
$mqr = TCPDF_STATIC::get_mqr();
|
||||
TCPDF_STATIC::set_mqr(false);
|
||||
// Specific image handlers (defined on TCPDF_IMAGES CLASS)
|
||||
$mtd = '_parse'.$type;
|
||||
// GD image handler function
|
||||
@ -7204,7 +7218,6 @@ class TCPDF {
|
||||
// unable to process image
|
||||
return false;
|
||||
}
|
||||
TCPDF_STATIC::set_mqr($mqr);
|
||||
if ($ismask) {
|
||||
// force grayscale
|
||||
$info['cs'] = 'DeviceGray';
|
||||
@ -8868,8 +8881,6 @@ class TCPDF {
|
||||
$this->_newobj();
|
||||
$this->_out('<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.'] >>'."\n".'endobj');
|
||||
}
|
||||
$mqr = TCPDF_STATIC::get_mqr();
|
||||
TCPDF_STATIC::set_mqr(false);
|
||||
foreach ($this->FontFiles as $file => $info) {
|
||||
// search and get font file to embedd
|
||||
$fontfile = TCPDF_FONTS::getFontFullPath($file, $info['fontdir']);
|
||||
@ -8923,7 +8934,6 @@ class TCPDF {
|
||||
$this->_out($out);
|
||||
}
|
||||
}
|
||||
TCPDF_STATIC::set_mqr($mqr);
|
||||
foreach ($this->fontkeys as $k) {
|
||||
//Font objects
|
||||
$font = $this->getFontBuffer($k);
|
||||
@ -9192,6 +9202,7 @@ class TCPDF {
|
||||
foreach ($this->imagekeys as $file) {
|
||||
$info = $this->getImageBuffer($file);
|
||||
// set object for alternate images array
|
||||
$altoid = null;
|
||||
if ((!$this->pdfa_mode) AND isset($info['altimgs']) AND !empty($info['altimgs'])) {
|
||||
$altoid = $this->_newobj();
|
||||
$out = '[';
|
||||
@ -9239,7 +9250,7 @@ class TCPDF {
|
||||
$out .= ' /Decode [1 0 1 0 1 0 1 0]';
|
||||
}
|
||||
$out .= ' /BitsPerComponent '.$info['bpc'];
|
||||
if (isset($altoid) AND ($altoid > 0)) {
|
||||
if ($altoid > 0) {
|
||||
// reference to alternate images dictionary
|
||||
$out .= ' /Alternates '.$altoid.' 0 R';
|
||||
}
|
||||
@ -11699,7 +11710,7 @@ class TCPDF {
|
||||
if ($this->state != 2) {
|
||||
return;
|
||||
}
|
||||
if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
|
||||
if (!(false === strpos($style, 'F')) AND is_array($fill_color)) {
|
||||
$this->setFillColorArray($fill_color);
|
||||
}
|
||||
$op = TCPDF_STATIC::getPathPaintOperator($style);
|
||||
@ -11729,7 +11740,7 @@ class TCPDF {
|
||||
if ($this->state != 2) {
|
||||
return;
|
||||
}
|
||||
if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
|
||||
if (!(false === strpos($style, 'F')) AND is_array($fill_color)) {
|
||||
$this->setFillColorArray($fill_color);
|
||||
}
|
||||
$op = TCPDF_STATIC::getPathPaintOperator($style);
|
||||
@ -11772,7 +11783,7 @@ class TCPDF {
|
||||
if (TCPDF_STATIC::empty_string($ry) OR ($ry == 0)) {
|
||||
$ry = $rx;
|
||||
}
|
||||
if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
|
||||
if (!(false === strpos($style, 'F')) AND is_array($fill_color)) {
|
||||
$this->setFillColorArray($fill_color);
|
||||
}
|
||||
$op = TCPDF_STATIC::getPathPaintOperator($style);
|
||||
@ -11991,7 +12002,7 @@ class TCPDF {
|
||||
}
|
||||
$nc += 4;
|
||||
}
|
||||
if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
|
||||
if (!(false === strpos($style, 'F')) AND is_array($fill_color)) {
|
||||
$this->setFillColorArray($fill_color);
|
||||
}
|
||||
$op = TCPDF_STATIC::getPathPaintOperator($style);
|
||||
@ -12194,7 +12205,7 @@ class TCPDF {
|
||||
return;
|
||||
}
|
||||
// Rounded
|
||||
if (!(false === strpos($style, 'F')) AND isset($fill_color)) {
|
||||
if (!(false === strpos($style, 'F')) AND is_array($fill_color)) {
|
||||
$this->setFillColorArray($fill_color);
|
||||
}
|
||||
$op = TCPDF_STATIC::getPathPaintOperator($style);
|
||||
@ -15073,9 +15084,7 @@ class TCPDF {
|
||||
// translate
|
||||
$this->_out(sprintf('%F %F %F %F %F %F cm', 1, 0, 0, 1, $dx, $dy + ($this->hPt - (2 * $y * $k) - ($y2 - $y1))));
|
||||
// scale
|
||||
if (isset($scale_x)) {
|
||||
$this->_out(sprintf('%F %F %F %F %F %F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
|
||||
}
|
||||
$this->_out(sprintf('%F %F %F %F %F %F cm', $scale_x, 0, 0, $scale_y, $x1 * (1 - $scale_x), $y2 * (1 - $scale_y)));
|
||||
// handle pc/unix/mac line endings
|
||||
$lines = preg_split('/[\r\n]+/si', $data, -1, PREG_SPLIT_NO_EMPTY);
|
||||
$u=0;
|
||||
@ -17741,7 +17750,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value:
|
||||
$pend = '';
|
||||
}
|
||||
}
|
||||
if ((isset($plalign) AND ((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
|
||||
if ((((($plalign == 'C') OR ($plalign == 'J') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
|
||||
// calculate shifting amount
|
||||
$tw = $w;
|
||||
if (($plalign == 'J') AND $this->isRTLTextDir() AND ($this->num_columns > 1)) {
|
||||
@ -18347,7 +18356,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value:
|
||||
$dom[$trid]['cellpos'][($cellid - 1)]['bgcolor'] = $dom[$parentid]['bgcolor'];
|
||||
}
|
||||
// store border info
|
||||
if (isset($tdborder) AND !empty($tdborder)) {
|
||||
if (!empty($tdborder)) {
|
||||
$dom[$trid]['cellpos'][($cellid - 1)]['border'] = $tdborder;
|
||||
}
|
||||
$prevLastH = $this->lasth;
|
||||
@ -18583,7 +18592,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value:
|
||||
$strrest = $this->Write($this->lasth, $dom[$key]['value'], '', $wfill, '', false, 0, true, $firstblock, 0, $wadj);
|
||||
// restore default direction
|
||||
if ($reverse_dir AND ($wadj == 0)) {
|
||||
$this->x = $xws;
|
||||
$this->x = $xws; // @phpstan-ignore-line
|
||||
$this->rtl = !$this->rtl;
|
||||
$reverse_dir = false;
|
||||
}
|
||||
@ -18692,7 +18701,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value:
|
||||
$pend = '';
|
||||
}
|
||||
}
|
||||
if ((isset($plalign) AND ((($plalign == 'C') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
|
||||
if ((((($plalign == 'C') OR (($plalign == 'R') AND (!$this->rtl)) OR (($plalign == 'L') AND ($this->rtl)))))) {
|
||||
// calculate shifting amount
|
||||
$tw = $w;
|
||||
if ($this->lMargin != $prevlMargin) {
|
||||
@ -23895,9 +23904,7 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value:
|
||||
}
|
||||
$firstcmd = false;
|
||||
} // end foreach
|
||||
if (!empty($op)) {
|
||||
$this->_out($op);
|
||||
}
|
||||
$this->_out($op);
|
||||
return array($xmin, $ymin, ($xmax - $xmin), ($ymax - $ymin));
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ class TCPDF_IMPORT extends TCPDF {
|
||||
/**
|
||||
* Import an existing PDF document
|
||||
* @param string $filename Filename of the PDF document to import.
|
||||
* @return true in case of success, false otherwise
|
||||
* @return void
|
||||
* @public
|
||||
* @since 1.0.000 (2011-05-24)
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user