Skip to content

Commit

Permalink
Add phpstan check and fix level 0 issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaasuni committed Oct 10, 2023
1 parent a8b0cfc commit f5e9566
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 195 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,22 @@ jobs:
with:
flags: php-${{ matrix.php-version }}-${{ matrix.os }}
name: php-${{ matrix.php-version }}-${{ matrix.os }}

static-analysis:
name: Static Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use php 8.2
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
- name: Cache module
uses: actions/cache@v3
with:
path: ~/.composer/cache/
key: composer-cache
- name: Install phpstan
run: composer require --dev phpstan/phpstan
- name: Analyse files
run: ./vendor/bin/phpstan analyse src test
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.1
3.2.3
2 changes: 1 addition & 1 deletion resources/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ Vcs-Git: https://github.com/~#VENDOR#~/~#PROJECT#~.git
Package: ~#PKGNAME#~
Provides: php-~#PROJECT#~
Architecture: all
Depends: php (>= 5.4.0), php-date, php-zip, php-tecnickcom-tc-lib-color (<< 2.0.0), php-tecnickcom-tc-lib-color (>= 1.14.29), php-tecnickcom-tc-lib-pdf-encrypt (<< 2.0.0), php-tecnickcom-tc-lib-pdf-encrypt (>= 1.6.25), ${misc:Depends}
Depends: php (>= 5.4.0), php-date, php-zip, php-tecnickcom-tc-lib-color (<< 2.0.0), php-tecnickcom-tc-lib-color (>= 1.14.31), php-tecnickcom-tc-lib-pdf-encrypt (<< 2.0.0), php-tecnickcom-tc-lib-pdf-encrypt (>= 1.6.27), ${misc:Depends}
Description: PHP PDF Page Library
PHP library containing PDF page formats and definitions.
4 changes: 2 additions & 2 deletions resources/rpm/rpm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Requires: php(language) >= 5.4.0
Requires: php-date
Requires: php-zlib
Requires: php-composer(%{c_vendor}/tc-lib-color) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-color) >= 1.14.29
Requires: php-composer(%{c_vendor}/tc-lib-color) >= 1.14.31
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) >= 1.6.25
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) >= 1.6.27

Provides: php-composer(%{c_vendor}/%{gh_project}) = %{version}
Provides: php-%{gh_project} = %{version}
Expand Down
14 changes: 14 additions & 0 deletions src/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@
*/
abstract class Box extends \Com\Tecnick\Pdf\Page\Mode
{
/**
* Unit of measure conversion ratio.
*
* @var float
*/
protected $kunit = 1.0;

/**
* Color object.
*
* @var Color
*/
protected $col;

/**
* Array of page box names.
*
Expand Down
188 changes: 0 additions & 188 deletions src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,97 +35,6 @@
*/
class Page extends \Com\Tecnick\Pdf\Page\Region
{
/**
* Alias for total number of pages in a group.
*
* @var string
*/
const PAGE_TOT = '~#PT';

/**
* Alias for page number.
*
* @var string
*/
const PAGE_NUM = '~#PN';

/**
* Array of pages (stack).
*
* @var array
*/
protected $page = array();

/**
* Current page ID.
*
* @var int
*/
protected $pid = -1;

/**
* Maximum page ID.
*
* @var int
*/
protected $pmaxid = -1;

/**
* Count pages in each group.
*
* @var array
*/
protected $group = array(0 => 0);

/**
* Unit of measure conversion ratio.
*
* @var float
*/
protected $kunit = 1.0;

/**
* Color object.
*
* @var Color
*/
protected $col;

/**
* Encrypt object.
*
* @var Encrypt
*/
protected $enc;

/**
* True if we are in PDF/A mode.
*
* @var bool
*/
protected $pdfa = false;

/**
* Enable stream compression.
*
* @var int
*/
protected $compress = true;

/**
* True if the signature approval is enabled (for incremental updates).
*
* @var bool
*/
protected $sigapp = false;

/**
* Reserved Object ID for the resource dictionary.
*
* @var int
*/
protected $rdoid = 1;

/**
* Initialize page data.
*
Expand Down Expand Up @@ -173,78 +82,6 @@ public function enableSignatureApproval($sigapp)
return $this;
}

/**
* Add a new page.
*
* @param array $data Page data:
* time : UTC page modification time in seconds;
* group : page group number;
* num : if set overwrites the page number;
* content : string containing the raw page content;
* annotrefs : array containing the annotation object references;
* format : page format name, or alternatively you can set width and height as below;
* width : page width;
* height : page height;
* orientation : page orientation ('P' or 'L');
* rotation : the number of degrees by which the page shall be rotated clockwise when displayed or printed;
* box : array containing page box boundaries and settings (@see setBox);
* transition : array containing page transition data (@see getPageTransition);
* zoom : preferred zoom (magnification) factor;
* margin : page margins:
* PL : page left margin measured from the left page edge
* PR : page right margin measured from the right page edge
* PT : page top or header top measured distance from the top page edge
* HB : header bottom measured from the top page edge
* CT : content top measured from the top page edge
* CB : content bottom (page breaking point) measured from the top page edge
* FT : footer top measured from the bottom page edge
* PB : page bottom (footer bottom) measured from the bottom page edge
* columns : number of equal vertical columns, if set it will automatically populate the region array
* region : array containing the ordered list of rectangular areas where it is allowed to write,
* each region is defined by:
* RX : horizontal coordinate of top-left corner
* RY : vertical coordinate of top-left corner
* RW : region width
* RH : region height
* autobreak : true to automatically add a page when the content reaches the breaking point.
*
* NOTE: if $data is empty, then the last page format will be cloned.
*
* @return array Page data with additional Page ID property 'pid'.
*/
public function add(array $data = array())
{
if (empty($data) && ($this->pmaxid >= 0)) {
// clone last page data
$data = $this->page[$this->pmaxid];
unset($data['time'], $data['content'], $data['annotrefs'], $data['pagenum']);
} else {
$this->sanitizeGroup($data);
$this->sanitizeRotation($data);
$this->sanitizeZoom($data);
$this->sanitizePageFormat($data);
$this->sanitizeBoxData($data);
$this->sanitizeTransitions($data);
$this->sanitizeMargins($data);
$this->sanitizeRegions($data);
}
$this->sanitizeTime($data);
$this->sanitizeContent($data);
$this->sanitizeAnnotRefs($data);
$this->sanitizePageNumber($data);
$data['content_mark'] = array(0);
$data['currentRegion'] = 0;
$data['pid'] = ++$this->pmaxid;
$this->pid = $data['pid'];
$this->page[$this->pid] = $data;
if (isset($this->group[$data['group']])) {
$this->group[$data['group']] += 1;
} else {
$this->group[$data['group']] = 1;
}
return $this->page[$this->pid];
}

/**
* Remove the specified page.
*
Expand Down Expand Up @@ -304,31 +141,6 @@ public function getPages()
return $this->page;
}

/**
* Set the current page number (move to the specified page).
*
* @param int $pid page index. Omit or set it to -1 for the current page ID.
*/
public function setCurrentPage($pid = -1)
{
$pid = $this->sanitizePageID($pid);
$this->pid = $pid;
return $this->page[$this->pid];
}

/**
* Returns the specified page data.
*
* @param int $pid page index. Omit or set it to -1 for the current page ID.
*
* return array
*/
public function getPage($pid = -1)
{
$pid = $this->sanitizePageID($pid);
return $this->page[$pid];
}

/**
* Add Annotation references.
*
Expand Down
97 changes: 97 additions & 0 deletions src/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,103 @@
*/
abstract class Region extends \Com\Tecnick\Pdf\Page\Settings
{
/**
* Add a new page.
*
* @param array $data Page data:
* time : UTC page modification time in seconds;
* group : page group number;
* num : if set overwrites the page number;
* content : string containing the raw page content;
* annotrefs : array containing the annotation object references;
* format : page format name, or alternatively you can set width and height as below;
* width : page width;
* height : page height;
* orientation : page orientation ('P' or 'L');
* rotation : the number of degrees by which the page shall be rotated clockwise when displayed or printed;
* box : array containing page box boundaries and settings (@see setBox);
* transition : array containing page transition data (@see getPageTransition);
* zoom : preferred zoom (magnification) factor;
* margin : page margins:
* PL : page left margin measured from the left page edge
* PR : page right margin measured from the right page edge
* PT : page top or header top measured distance from the top page edge
* HB : header bottom measured from the top page edge
* CT : content top measured from the top page edge
* CB : content bottom (page breaking point) measured from the top page edge
* FT : footer top measured from the bottom page edge
* PB : page bottom (footer bottom) measured from the bottom page edge
* columns : number of equal vertical columns, if set it will automatically populate the region array
* region : array containing the ordered list of rectangular areas where it is allowed to write,
* each region is defined by:
* RX : horizontal coordinate of top-left corner
* RY : vertical coordinate of top-left corner
* RW : region width
* RH : region height
* autobreak : true to automatically add a page when the content reaches the breaking point.
*
* NOTE: if $data is empty, then the last page format will be cloned.
*
* @return array Page data with additional Page ID property 'pid'.
*/
public function add(array $data = array())
{
if (empty($data) && ($this->pmaxid >= 0)) {
// clone last page data
$data = $this->page[$this->pmaxid];
unset($data['time'], $data['content'], $data['annotrefs'], $data['pagenum']);
} else {
$this->sanitizeGroup($data);
$this->sanitizeRotation($data);
$this->sanitizeZoom($data);
$this->sanitizePageFormat($data);
$this->sanitizeBoxData($data);
$this->sanitizeTransitions($data);
$this->sanitizeMargins($data);
$this->sanitizeRegions($data);
}
$this->sanitizeTime($data);
$this->sanitizeContent($data);
$this->sanitizeAnnotRefs($data);
$this->sanitizePageNumber($data);
$data['content_mark'] = array(0);
$data['currentRegion'] = 0;
$data['pid'] = ++$this->pmaxid;
$this->pid = $data['pid'];
$this->page[$this->pid] = $data;
if (isset($this->group[$data['group']])) {
$this->group[$data['group']] += 1;
} else {
$this->group[$data['group']] = 1;
}
return $this->page[$this->pid];
}

/**
* Set the current page number (move to the specified page).
*
* @param int $pid page index. Omit or set it to -1 for the current page ID.
*/
public function setCurrentPage($pid = -1)
{
$pid = $this->sanitizePageID($pid);
$this->pid = $pid;
return $this->page[$this->pid];
}

/**
* Returns the specified page data.
*
* @param int $pid page index. Omit or set it to -1 for the current page ID.
*
* return array
*/
public function getPage($pid = -1)
{
$pid = $this->sanitizePageID($pid);
return $this->page[$pid];
}

/**
* Check if the specified page ID exist.
*
Expand Down
Loading

0 comments on commit f5e9566

Please sign in to comment.