-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set phpstam max level and fix errors
- Loading branch information
1 parent
2565c40
commit f95252b
Showing
16 changed files
with
3,006 additions
and
1,652 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
parameters: | ||
level: 5 | ||
level: max | ||
paths: | ||
- src | ||
- test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,13 @@ | |
/** | ||
* Box.php | ||
* | ||
* @since 2011-05-23 | ||
* @category Library | ||
* @package PdfPage | ||
* @author Nicola Asuni <[email protected]> | ||
* @copyright 2011-2023 Nicola Asuni - Tecnick.com LTD | ||
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) | ||
* @link https://github.com/tecnickcom/tc-lib-pdf-page | ||
* @since 2011-05-23 | ||
* @category Library | ||
* @package PdfPage | ||
* @author Nicola Asuni <[email protected]> | ||
* @copyright 2011-2023 Nicola Asuni - Tecnick.com LTD | ||
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) | ||
* @link https://github.com/tecnickcom/tc-lib-pdf-page | ||
* | ||
* This file is part of tc-lib-pdf-page software library. | ||
*/ | ||
|
@@ -22,54 +22,71 @@ | |
/** | ||
* Com\Tecnick\Pdf\Page\Box | ||
* | ||
* @since 2011-05-23 | ||
* @category Library | ||
* @package PdfPage | ||
* @author Nicola Asuni <[email protected]> | ||
* @copyright 2011-2023 Nicola Asuni - Tecnick.com LTD | ||
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) | ||
* @link https://github.com/tecnickcom/tc-lib-pdf-page | ||
* @since 2011-05-23 | ||
* @category Library | ||
* @package PdfPage | ||
* @author Nicola Asuni <[email protected]> | ||
* @copyright 2011-2023 Nicola Asuni - Tecnick.com LTD | ||
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) | ||
* @link https://github.com/tecnickcom/tc-lib-pdf-page | ||
*/ | ||
abstract class Box extends \Com\Tecnick\Pdf\Page\Mode | ||
{ | ||
/** | ||
* Unit of measure conversion ratio. | ||
* | ||
* @var float | ||
*/ | ||
protected $kunit = 1.0; | ||
protected float $kunit = 1.0; | ||
|
||
/** | ||
* Color object. | ||
* | ||
* @var Color | ||
*/ | ||
protected $col; | ||
protected Color $col; | ||
|
||
/** | ||
* Array of page box names. | ||
* Page box names. | ||
* | ||
* @var array | ||
* @var array<string> | ||
*/ | ||
public static $box = array( | ||
public const BOX = [ | ||
'MediaBox', | ||
'CropBox', | ||
'BleedBox', | ||
'TrimBox', | ||
'ArtBox' | ||
); | ||
'ArtBox', | ||
]; | ||
|
||
/** | ||
* Swap X and Y coordinates of page boxes (change page boxes orientation). | ||
* | ||
* @param array $dims Array of page dimensions. | ||
* | ||
* @return array Page dimensions. | ||
* @param array<string, array{ | ||
* 'llx': float, | ||
* 'lly': float, | ||
* 'urx': float, | ||
* 'ury': float, | ||
* 'bci'?: array{ | ||
* 'color': string, | ||
* 'width': float, | ||
* 'style': string, | ||
* 'dash': array<int>, | ||
* }, | ||
* }> $dims Array of page dimensions. | ||
* | ||
* @return array<string, array{ | ||
* 'llx': float, | ||
* 'lly': float, | ||
* 'urx': float, | ||
* 'ury': float, | ||
* 'bci'?: array{ | ||
* 'color': string, | ||
* 'width': float, | ||
* 'style': string, | ||
* 'dash': array<int>, | ||
* }, | ||
* }> Page dimensions. | ||
*/ | ||
public function swapCoordinates(array $dims) | ||
public function swapCoordinates(array $dims): array | ||
{ | ||
foreach (self::$box as $type) { | ||
foreach (self::BOX as $type) { | ||
// swap X and Y coordinates | ||
if (isset($dims[$type])) { | ||
$tmp = $dims[$type]['llx']; | ||
|
@@ -80,45 +97,83 @@ public function swapCoordinates(array $dims) | |
$dims[$type]['ury'] = $tmp; | ||
} | ||
} | ||
|
||
return $dims; | ||
} | ||
|
||
/** | ||
* Set page boundaries. | ||
* | ||
* @param array $dims Array of page dimensions to modify. | ||
* @param string $type Box type: MediaBox, CropBox, BleedBox, TrimBox, ArtBox. | ||
* @param float $llx Lower-left x coordinate in user units. | ||
* @param float $lly Lower-left y coordinate in user units. | ||
* @param float $urx Upper-right x coordinate in user units. | ||
* @param float $ury Upper-right y coordinate in user units. | ||
* @param array $bci BoxColorInfo: guideline style (color, width, style, dash). | ||
* @param array<string, array{ | ||
* 'llx': float, | ||
* 'lly': float, | ||
* 'urx': float, | ||
* 'ury': float, | ||
* 'bci'?: array{ | ||
* 'color': string, | ||
* 'width': float, | ||
* 'style': string, | ||
* 'dash': array<int>, | ||
* }, | ||
* }> $dims Array of page dimensions to modify. | ||
* @param string $type Box type: MediaBox, CropBox, BleedBox, TrimBox, ArtBox. | ||
* @param float $llx Lower-left x coordinate in user units. | ||
* @param float $lly Lower-left y coordinate in user units. | ||
* @param float $urx Upper-right x coordinate in user units. | ||
* @param float $ury Upper-right y coordinate in user units. | ||
* @param array{ | ||
* 'color': string, | ||
* 'width': float, | ||
* 'style': string, | ||
* 'dash': array<int>, | ||
* } $bci BoxColorInfo: guideline style (color, width, style, dash). | ||
* | ||
* @return array Page dimensions. | ||
* @return array<string, array{ | ||
* 'llx': float, | ||
* 'lly': float, | ||
* 'urx': float, | ||
* 'ury': float, | ||
* 'bci': array{ | ||
* 'color': string, | ||
* 'width': float, | ||
* 'style': string, | ||
* 'dash': array<int>, | ||
* }, | ||
* }> Page dimensions. | ||
*/ | ||
public function setBox($dims, $type, $llx, $lly, $urx, $ury, array $bci = array()) | ||
{ | ||
if (empty($dims)) { | ||
public function setBox( | ||
array $dims, | ||
string $type, | ||
float $llx, | ||
float $lly, | ||
float $urx, | ||
float $ury, | ||
?array $bci = null, | ||
): array { | ||
if ($dims === []) { | ||
// initialize array | ||
$dims = array(); | ||
$dims = []; | ||
} | ||
if (!in_array($type, self::$box)) { | ||
|
||
if (! in_array($type, self::BOX)) { | ||
throw new PageException('unknown page box type: ' . $type); | ||
} | ||
|
||
$dims[$type]['llx'] = $llx; | ||
$dims[$type]['lly'] = $lly; | ||
$dims[$type]['urx'] = $urx; | ||
$dims[$type]['ury'] = $ury; | ||
|
||
if (empty($bci)) { | ||
if ($bci === null) { | ||
// set default values | ||
$bci = array( | ||
$bci = [ | ||
'color' => '#000000', | ||
'width' => (1.0 / $this->kunit), | ||
'style' => 'S', // S = solid; D = dash | ||
'dash' => array(3) | ||
); | ||
'dash' => [3], | ||
]; | ||
} | ||
|
||
$dims[$type]['bci'] = $bci; | ||
|
||
return $dims; | ||
|
@@ -130,33 +185,49 @@ public function setBox($dims, $type, $llx, $lly, $urx, $ury, array $bci = array( | |
* @param float $width Page width in points. | ||
* @param float $height Page height in points. | ||
* | ||
* @return array Page boxes. | ||
* @return array<string, array{ | ||
* 'llx': float, | ||
* 'lly': float, | ||
* 'urx': float, | ||
* 'ury': float, | ||
* 'bci'?: array{ | ||
* 'color': string, | ||
* 'width': float, | ||
* 'style': string, | ||
* 'dash': array<int>, | ||
* }, | ||
* }> Page boxes. | ||
*/ | ||
public function setPageBoxes($width, $height) | ||
public function setPageBoxes(float $width, float $height): array | ||
{ | ||
$dims = array(); | ||
foreach (self::$box as $type) { | ||
$dims = []; | ||
foreach (self::BOX as $type) { | ||
$dims = $this->setBox($dims, $type, 0, 0, $width, $height); | ||
} | ||
|
||
return $dims; | ||
} | ||
|
||
/** | ||
* Returns the PDF command to output the specified page boxes. | ||
* | ||
* @param array $dims Array of page dimensions. | ||
* | ||
* @return string | ||
* @param array<string, array{ | ||
* 'llx': float, | ||
* 'lly': float, | ||
* 'urx': float, | ||
* 'ury': float, | ||
* }> $dims Array of page dimensions. | ||
*/ | ||
protected function getBox(array $dims) | ||
protected function getBox(array $dims): string | ||
{ | ||
$out = ''; | ||
foreach (self::$box as $box) { | ||
foreach (self::BOX as $box) { | ||
if (empty($dims[$box])) { | ||
// @codeCoverageIgnoreStart | ||
continue; | ||
// @codeCoverageIgnoreEnd | ||
} | ||
|
||
$out .= '/' . $box . ' [' . sprintf( | ||
'%F %F %F %F', | ||
$dims[$box]['llx'], | ||
|
@@ -165,49 +236,62 @@ protected function getBox(array $dims) | |
$dims[$box]['ury'] | ||
) . ']' . "\n"; | ||
} | ||
|
||
return $out; | ||
} | ||
|
||
/** | ||
* Returns the PDF command to output the specified page BoxColorInfo. | ||
* | ||
* @param array $dims Array of page dimensions. | ||
* @param array<string, array{ | ||
* 'bci': array{ | ||
* 'color': string, | ||
* 'width': float, | ||
* 'style': string, | ||
* 'dash': array<int>, | ||
* }, | ||
* }> $dims Array of page dimensions. | ||
* | ||
* @return string | ||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||
*/ | ||
protected function getBoxColorInfo(array $dims) | ||
protected function getBoxColorInfo(array $dims): string | ||
{ | ||
$out = '/BoxColorInfo <<' . "\n"; | ||
foreach (self::$box as $box) { | ||
foreach (self::BOX as $box) { | ||
if (empty($dims[$box])) { | ||
// @codeCoverageIgnoreStart | ||
continue; | ||
// @codeCoverageIgnoreEnd | ||
} | ||
|
||
$out .= '/' . $box . ' <<' . "\n"; | ||
if (!empty($dims[$box]['bci']['color'])) { | ||
if (! empty($dims[$box]['bci']['color'])) { | ||
$out .= '/C [' . $this->col->getPdfRgbComponents($dims[$box]['bci']['color']) . ']' . "\n"; | ||
} | ||
if (!empty($dims[$box]['bci']['width'])) { | ||
|
||
if (! empty($dims[$box]['bci']['width'])) { | ||
$out .= '/W ' . sprintf('%F', ($dims[$box]['bci']['width'] * $this->kunit)) . "\n"; | ||
} | ||
if (!empty($dims[$box]['bci']['style'])) { | ||
|
||
if (! empty($dims[$box]['bci']['style'])) { | ||
$mode = strtoupper($dims[$box]['bci']['style'][0]); | ||
if ($mode !== 'D') { | ||
$mode = 'S'; | ||
} | ||
|
||
$out .= '/S /' . $mode . "\n"; | ||
} | ||
if (!empty($dims[$box]['bci']['dash'])) { | ||
|
||
if (! empty($dims[$box]['bci']['dash'])) { | ||
$out .= '/D ['; | ||
foreach ($dims[$box]['bci']['dash'] as $dash) { | ||
$out .= sprintf(' %F', ((float) $dash * $this->kunit)); | ||
} | ||
|
||
$out .= ' ]' . "\n"; | ||
} | ||
|
||
$out .= '>>' . "\n"; | ||
} | ||
$out .= '>>' . "\n"; | ||
return $out; | ||
|
||
return $out . ('>>' . "\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,13 @@ | |
/** | ||
* Exception.php | ||
* | ||
* @since 2011-05-23 | ||
* @category Library | ||
* @package PdfPage | ||
* @author Nicola Asuni <[email protected]> | ||
* @copyright 2011-2023 Nicola Asuni - Tecnick.com LTD | ||
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) | ||
* @link https://github.com/tecnickcom/tc-lib-pdf-page | ||
* @since 2011-05-23 | ||
* @category Library | ||
* @package PdfPage | ||
* @author Nicola Asuni <[email protected]> | ||
* @copyright 2011-2023 Nicola Asuni - Tecnick.com LTD | ||
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) | ||
* @link https://github.com/tecnickcom/tc-lib-pdf-page | ||
* | ||
* This file is part of tc-lib-pdf-page software library. | ||
*/ | ||
|
@@ -21,13 +21,13 @@ | |
* | ||
* Custom Exception class. | ||
* | ||
* @since 2011-05-23 | ||
* @category Library | ||
* @package PdfPage | ||
* @author Nicola Asuni <[email protected]> | ||
* @copyright 2011-2023 Nicola Asuni - Tecnick.com LTD | ||
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) | ||
* @link https://github.com/tecnickcom/tc-lib-pdf-page | ||
* @since 2011-05-23 | ||
* @category Library | ||
* @package PdfPage | ||
* @author Nicola Asuni <[email protected]> | ||
* @copyright 2011-2023 Nicola Asuni - Tecnick.com LTD | ||
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) | ||
* @link https://github.com/tecnickcom/tc-lib-pdf-page | ||
*/ | ||
class Exception extends \Exception | ||
{ | ||
|
Oops, something went wrong.