diff options
| author | Greg Roach <greg@subaqua.co.uk> | 2021-09-09 22:15:46 +0100 |
|---|---|---|
| committer | Greg Roach <greg@subaqua.co.uk> | 2021-09-14 16:02:08 +0100 |
| commit | 77bab46164e79833b0e2cc2442328cb5f47dd5e6 (patch) | |
| tree | ce2aa539e03a7904dfb81555a4448f711b829b00 /app/Report | |
| parent | a3148b03cff68ac7a179d4636354b8e1c00044ca (diff) | |
| download | webtrees-77bab46164e79833b0e2cc2442328cb5f47dd5e6.tar.gz webtrees-77bab46164e79833b0e2cc2442328cb5f47dd5e6.tar.bz2 webtrees-77bab46164e79833b0e2cc2442328cb5f47dd5e6.zip | |
Reports PHPdoc
Diffstat (limited to 'app/Report')
26 files changed, 263 insertions, 466 deletions
diff --git a/app/Report/AbstractRenderer.php b/app/Report/AbstractRenderer.php index ee8304f0c6..5256bed366 100644 --- a/app/Report/AbstractRenderer.php +++ b/app/Report/AbstractRenderer.php @@ -112,7 +112,7 @@ abstract class AbstractRenderer public array $headerElements = []; /** @var array<ReportBaseElement|string> */ - public $footerElements = []; + public array $footerElements = []; /** @var array<ReportBaseElement|string> */ public array $bodyElements = []; @@ -183,9 +183,9 @@ abstract class AbstractRenderer /** * Create a new Cell object. * - * @param int $width cell width (expressed in points) - * @param int $height cell height (expressed in points) - * @param mixed $border Border style + * @param float $width cell width (expressed in points) + * @param float $height cell height (expressed in points) + * @param string $border Border style * @param string $align Text alignement * @param string $bgcolor Background color code * @param string $style The name of the text style @@ -201,9 +201,9 @@ abstract class AbstractRenderer * @return ReportBaseCell */ abstract public function createCell( - int $width, - int $height, - $border, + float $width, + float $height, + string $border, string $align, string $bgcolor, string $style, diff --git a/app/Report/HtmlRenderer.php b/app/Report/HtmlRenderer.php index 650cf5406a..5fb8a646ba 100644 --- a/app/Report/HtmlRenderer.php +++ b/app/Report/HtmlRenderer.php @@ -112,7 +112,7 @@ class HtmlRenderer extends AbstractRenderer if ($this->show_generated_by) { // The default style name for Generated by.... is 'genby' - $element = new ReportHtmlCell(0, 10, 0, 'C', '', 'genby', 1, ReportBaseElement::CURRENT_POSITION, ReportBaseElement::CURRENT_POSITION, 0, 0, '', '', true); + $element = new ReportHtmlCell(0.0, 10.0, '', 'C', '', 'genby', 1, ReportBaseElement::CURRENT_POSITION, ReportBaseElement::CURRENT_POSITION, 0, 0, '', '', true); $element->addText($this->generated_by); $element->setUrl(Webtrees::URL); $this->footerElements[] = $element; @@ -220,9 +220,9 @@ class HtmlRenderer extends AbstractRenderer /** * Create a new Cell object. * - * @param int $width cell width (expressed in points) - * @param int $height cell height (expressed in points) - * @param mixed $border Border style + * @param float $width cell width (expressed in points) + * @param float $height cell height (expressed in points) + * @param string $border Border style * @param string $align Text alignement * @param string $bgcolor Background color code * @param string $style The name of the text style @@ -237,7 +237,7 @@ class HtmlRenderer extends AbstractRenderer * * @return ReportBaseCell */ - public function createCell(int $width, int $height, $border, string $align, string $bgcolor, string $style, int $ln, $top, $left, int $fill, int $stretch, string $bocolor, string $tcolor, bool $reseth): ReportBaseCell + public function createCell(float $width, float $height, string $border, string $align, string $bgcolor, string $style, int $ln, $top, $left, int $fill, int $stretch, string $bocolor, string $tcolor, bool $reseth): ReportBaseCell { return new ReportHtmlCell($width, $height, $border, $align, $bgcolor, $style, $ln, $top, $left, $fill, $stretch, $bocolor, $tcolor, $reseth); } @@ -401,7 +401,7 @@ class HtmlRenderer extends AbstractRenderer * * @return void */ - public function addMaxY($y): void + public function addMaxY(float $y): void { if ($this->maxY < $y) { $this->maxY = $y; @@ -445,7 +445,7 @@ class HtmlRenderer extends AbstractRenderer * * @return int Number of lines. 0 if empty line */ - public function countLines($str): int + public function countLines(string $str): int { if ($str === '') { return 0; diff --git a/app/Report/PdfRenderer.php b/app/Report/PdfRenderer.php index 3db5ee68c7..a483458908 100644 --- a/app/Report/PdfRenderer.php +++ b/app/Report/PdfRenderer.php @@ -95,7 +95,7 @@ class PdfRenderer extends AbstractRenderer { $this->tcpdf->AddPage(); - foreach ($this->bodyElements as $key => $element) { + foreach ($this->bodyElements as $element) { if ($element instanceof ReportBaseElement) { $element->render($this); } elseif ($element === 'footnotetexts') { @@ -107,7 +107,7 @@ class PdfRenderer extends AbstractRenderer } /** - * PDF Footnotes -PDF + * Generate footnotes * * @return void */ @@ -169,18 +169,6 @@ class PdfRenderer extends AbstractRenderer } /** - * Remove the footer. - * - * @param int $index - * - * @return void - */ - public function removeFooter(int $index): void - { - unset($this->footerElements[$index]); - } - - /** * Clear the Header -PDF * * @return void @@ -312,7 +300,7 @@ class PdfRenderer extends AbstractRenderer $val = $footnote->getValue(); $i = 0; while ($i < $ct) { - if ($this->printedfootnotes[$i]->getValue() == $val) { + if ($this->printedfootnotes[$i]->getValue() === $val) { // If this footnote already exist then set up the numbers for this object $footnote->setNum($i + 1); $footnote->setAddlink((string) ($i + 1)); @@ -399,7 +387,7 @@ class PdfRenderer extends AbstractRenderer if ($this->show_generated_by) { // The default style name for Generated by.... is 'genby' - $element = new ReportPdfCell(0, 10, 0, 'C', '', 'genby', 1, ReportBaseElement::CURRENT_POSITION, ReportBaseElement::CURRENT_POSITION, 0, 0, '', '', true); + $element = new ReportPdfCell(0.0, 10.0, '', 'C', '', 'genby', 1, ReportBaseElement::CURRENT_POSITION, ReportBaseElement::CURRENT_POSITION, 0, 0, '', '', true); $element->addText($this->generated_by); $element->setUrl(Webtrees::URL); $this->addElementToFooter($element); @@ -420,10 +408,10 @@ class PdfRenderer extends AbstractRenderer /** * Create a new Cell object. * - * @param int $width cell width (expressed in points) - * @param int $height cell height (expressed in points) - * @param mixed $border Border style - * @param string $align Text alignement + * @param float $width cell width (expressed in points) + * @param float $height cell height (expressed in points) + * @param string $border Border style + * @param string $align Text alignment * @param string $bgcolor Background color code * @param string $style The name of the text style * @param int $ln Indicates where the current position should go after the call @@ -437,7 +425,7 @@ class PdfRenderer extends AbstractRenderer * * @return ReportBaseCell */ - public function createCell(int $width, int $height, $border, string $align, string $bgcolor, string $style, int $ln, $top, $left, int $fill, int $stretch, string $bocolor, string $tcolor, bool $reseth): ReportBaseCell + public function createCell(float $width, float $height, string $border, string $align, string $bgcolor, string $style, int $ln, $top, $left, int $fill, int $stretch, string $bocolor, string $tcolor, bool $reseth): ReportBaseCell { return new ReportPdfCell($width, $height, $border, $align, $bgcolor, $style, $ln, $top, $left, $fill, $stretch, $bocolor, $tcolor, $reseth); } diff --git a/app/Report/ReportBaseCell.php b/app/Report/ReportBaseCell.php index 589934ab16..f9faba5ea9 100644 --- a/app/Report/ReportBaseCell.php +++ b/app/Report/ReportBaseCell.php @@ -32,45 +32,28 @@ class ReportBaseCell extends ReportBaseElement public string $align = ''; // Whether a border should be printed around this box. - // 0 = no border (default) - // 1 = border + // '' = no border (default) + // '1' = border // a string containing some or all of the following characters (in any order): // L: left // T: top // R: right // B: bottom - /** @var int|string */ - public $border; + public string $border; - /** - * Border color in HTML code - * - * @var string - */ + // Border color in HTML code + public string $bocolor; - public $bocolor; - /** - * The HTML color code to fill the background of this cell. - * - * @var string - */ + // The HTML color code to fill the background of this cell. + public string $bgcolor; - public $bgcolor; - /** - * Indicates if the cell background must be painted (1) or transparent (0). Default value: 1. - * If no background color is set then it will not be painted - * - * @var int - */ + // Indicates if the cell background must be painted (1) or transparent (0). Default value: 1. + // If no background color is set then it will not be painted + public int $fill; - public $fill; - /** - * Cell height DEFAULT 0 (expressed in points) - * The starting height of this cell. If the text wraps the height will automatically be adjusted. - * - * @var float - */ - public $height; + // Cell height DEFAULT 0 (expressed in points) + // The starting height of this cell. If the text wraps the height will automatically be adjusted. + public float $height; /** * Left position in user units (X-position). Default is the current position @@ -79,34 +62,27 @@ class ReportBaseCell extends ReportBaseElement */ public $left; - /** - * Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right [DEFAULT]</li><li>1: to the beginning of the next line</li><li>2: below</li></ul> - * - * @var int - */ - public $newline; - /** - * The name of the Style that should be used to render the text. - * - * @var string - */ + // Indicates where the current position should go after the call. Possible values are: + // 0: to the right [DEFAULT] + // 1: to the beginning of the next line + // 2: below + public int $newline; - public $styleName; - /** - * Stretch carachter mode: <ul><li>0 = disabled (default)</li><li>1 = horizontal scaling only if necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if necessary</li><li>4 = forced character spacing</li></ul> - * - * @var int - */ + // The name of the Style that should be used to render the text. + public string $styleName; - public $stretch; - /** - * Text color in HTML code - * - * @var string - */ + // Stretch character mode: + // 0 = disabled (default) + // 1 = horizontal scaling only if necessary + // 2 = forced horizontal scaling + // 3 = character spacing only if necessary + // 4 = forced character spacing + public int $stretch; + + // Text color in HTML code + public string $tcolor; - public $tcolor; /** * Top position in user units (Y-position). Default is the current position * @@ -114,47 +90,38 @@ class ReportBaseCell extends ReportBaseElement */ public $top; - /** - * URL address - * - * @var string - */ - public $url; - /** - * Cell width DEFAULT 0 (expressed in points) - * Setting the width to 0 will make it the width from the current location to the right margin. - * - * @var float - */ + // URL address + public string $url = ''; - public $width; + // Cell width DEFAULT 0 (expressed in points) + // Setting the width to 0 will make it the width from the current location to the right margin. + public float $width; - /** @var bool */ - public $reseth; + public bool $reseth; /** * CELL - Element * - * @param int $width cell width (expressed in points) - * @param int $height cell height (expressed in points) - * @param mixed $border Border style - * @param string $align Text alignement + * @param float $width cell width (expressed in points) + * @param float $height cell height (expressed in points) + * @param string $border Border style + * @param string $align Text alignment * @param string $bgcolor Background color code * @param string $style The name of the text style * @param int $ln Indicates where the current position should go after the call * @param mixed $top Y-position * @param mixed $left X-position - * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0. + * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). * @param int $stretch Stretch carachter mode * @param string $bocolor Border color * @param string $tcolor Text color * @param bool $reseth */ public function __construct( - int $width, - int $height, - $border, + float $width, + float $height, + string $border, string $align, string $bgcolor, string $style, @@ -176,10 +143,8 @@ class ReportBaseCell extends ReportBaseElement $this->left = $left; $this->newline = $ln; $this->styleName = $style; - $this->text = ''; $this->tcolor = $tcolor; $this->top = $top; - $this->url = ''; $this->stretch = $stretch; $this->width = $width; $this->reseth = $reseth; @@ -204,7 +169,7 @@ class ReportBaseCell extends ReportBaseElement * * @return void */ - public function setUrl($url): void + public function setUrl(string $url): void { $this->url = $url; } @@ -214,7 +179,7 @@ class ReportBaseCell extends ReportBaseElement * * @param HtmlRenderer|PdfRenderer $renderer * - * @return array{0:float,1:int,2:float|int} + * @return array{0:float,1:int,2:float} */ public function getWidth($renderer): array { diff --git a/app/Report/ReportBaseElement.php b/app/Report/ReportBaseElement.php index 5efa47d1d9..820fd99e07 100644 --- a/app/Report/ReportBaseElement.php +++ b/app/Report/ReportBaseElement.php @@ -31,8 +31,7 @@ class ReportBaseElement // Special value for X or Y position, to indicate the current position. public const CURRENT_POSITION = -1.0; - /** @var string Text */ - public $text = ''; + public string $text = ''; /** * Element renderer @@ -41,7 +40,7 @@ class ReportBaseElement * * @return void */ - public function render($renderer) + public function render($renderer): void { //-- to be implemented in inherited classes } @@ -63,7 +62,7 @@ class ReportBaseElement * * @param HtmlRenderer|PdfRenderer $renderer * - * @return array{0:float,1:int,2:float|int} + * @return array{0:float,1:int,2:float} */ public function getWidth($renderer): array { diff --git a/app/Report/ReportBaseFootnote.php b/app/Report/ReportBaseFootnote.php index 38493e4928..1e42361440 100644 --- a/app/Report/ReportBaseFootnote.php +++ b/app/Report/ReportBaseFootnote.php @@ -26,53 +26,33 @@ use function str_contains; */ class ReportBaseFootnote extends ReportBaseElement { - /** - * The name of the style for this element - * - * @var string - */ - public $styleName = ''; + // The name of the style for this element + public string $styleName = ''; - /** - * Numbers for the links - * - * @var int - */ - public $num; + // Numbers for the links + public int $num; - /** - * The text that will be printed with the number - * - * @var string - */ - public $numText = ''; + // The text that will be printed with the number + public string $numText = ''; - /** - * Remaining width of a cell - * - * @var float User unit (points) - */ - public $wrapWidthRemaining; + // Remaining width of a cell + public float $wrapWidthRemaining; - /** - * Original width of a cell - * - * @var float User unit (points) - */ - public $wrapWidthCell; + // Original width of a cell (points) + public float $wrapWidthCell; - /** @var string A link */ - public $addlink; + // A link + public string $addlink; /** - * Createa an element. + * Create an element. * * @param string $style */ - public function __construct($style = '') + public function __construct(string $style = '') { $this->text = ''; - if (!empty($style)) { + if ($style !== '') { $this->styleName = $style; } else { $this->styleName = 'footnote'; @@ -119,7 +99,7 @@ class ReportBaseFootnote extends ReportBaseElement * * @return void */ - public function setAddlink(string $a) + public function setAddlink(string $a): void { $this->addlink = $a; } diff --git a/app/Report/ReportBaseImage.php b/app/Report/ReportBaseImage.php index fbc86884e1..1dd51c8042 100644 --- a/app/Report/ReportBaseImage.php +++ b/app/Report/ReportBaseImage.php @@ -24,26 +24,26 @@ namespace Fisharebest\Webtrees\Report; */ class ReportBaseImage extends ReportBaseElement { - /** @var string Filename of the image */ - public $file; + // Filename of the image + public string $file; - /** @var float Height of the image */ - public $height; + // Height of the image + public float $height; - /** @var float Width of the image */ - public $width; + // Width of the image + public float $width; - /** @var float X-position (left) of the image */ - public $x; + // X-position (left) of the image + public float $x; - /** @var float Y-position (top) of the image */ - public $y; + // Y-position (top) of the image + public float $y; - /** @var string Placement fo the image. L: left, C:center, R:right (or empty for x/y) */ - public $align; + // Placement of the image. L: left, C:center, R:right (or empty for x/y) + public string $align; - /** @var string T:same line, N:next line */ - public $line; + // T:same line, N:next line + public string $line; /** * Image class function - Base @@ -84,7 +84,7 @@ class ReportBaseImage extends ReportBaseElement * * @param HtmlRenderer|PdfRenderer $renderer * - * @return array{0:float,1:int,2:float|int} + * @return array{0:float,1:int,2:float} */ public function getWidth($renderer): array { diff --git a/app/Report/ReportBaseLine.php b/app/Report/ReportBaseLine.php index cbb0f171ad..322f61e9ed 100644 --- a/app/Report/ReportBaseLine.php +++ b/app/Report/ReportBaseLine.php @@ -26,40 +26,27 @@ use function abs; */ class ReportBaseLine extends ReportBaseElement { - /** - * Start horizontal position, current position (default) - * - * @var float - */ - public $x1 = ReportBaseElement::CURRENT_POSITION; - /** - * Start vertical position, current position (default) - * - * @var float - */ - public $y1 = ReportBaseElement::CURRENT_POSITION; - /** - * End horizontal position, maximum width (default) - * - * @var float - */ - public $x2 = ReportBaseElement::CURRENT_POSITION; - /** - * End vertical position - * - * @var float - */ - public $y2 = ReportBaseElement::CURRENT_POSITION; + // Start horizontal position, current position (default) + public float $x1 = ReportBaseElement::CURRENT_POSITION; + + // Start vertical position, current position (default) + public float $y1 = ReportBaseElement::CURRENT_POSITION; + + // End horizontal position, maximum width (default) + public float $x2 = ReportBaseElement::CURRENT_POSITION; + + // End vertical position + public float $y2 = ReportBaseElement::CURRENT_POSITION; /** * Create a line class - Base * - * @param mixed $x1 - * @param mixed $y1 - * @param mixed $x2 - * @param mixed $y2 + * @param float $x1 + * @param float $y1 + * @param float $x2 + * @param float $y2 */ - public function __construct($x1, $y1, $x2, $y2) + public function __construct(float $x1, float $y1, float $x2, float $y2) { $this->x1 = $x1; $this->y1 = $y1; @@ -84,7 +71,7 @@ class ReportBaseLine extends ReportBaseElement * * @param HtmlRenderer|PdfRenderer $renderer * - * @return array{0:float,1:int,2:float|int} + * @return array{0:float,1:int,2:float} */ public function getWidth($renderer): array { diff --git a/app/Report/ReportBaseText.php b/app/Report/ReportBaseText.php index cd197d702e..38288cf4ea 100644 --- a/app/Report/ReportBaseText.php +++ b/app/Report/ReportBaseText.php @@ -26,30 +26,17 @@ use function str_contains; */ class ReportBaseText extends ReportBaseElement { - /** - * Text color in HTML code - * - * @var string - */ - public $color; - /** - * Style name - * - * @var string - */ - public $styleName; - /** - * Remaining width of a cel - * - * @var float User unit (points) - */ - public $wrapWidthRemaining; - /** - * Original width of a cell - * - * @var float User unit (points) - */ - public $wrapWidthCell; + // Text color in HTML code + public string $color; + + // Style name + public string $styleName; + + // Remaining width of a cell (points) + public float $wrapWidthRemaining; + + // Original width of a cell (points) + public float $wrapWidthCell; /** * Create a Text class - Base @@ -61,7 +48,7 @@ class ReportBaseText extends ReportBaseElement { $this->text = ''; $this->color = $color; - $this->wrapWidthRemaining = 0; + $this->wrapWidthRemaining = 0.0; $this->styleName = $style; } diff --git a/app/Report/ReportBaseTextbox.php b/app/Report/ReportBaseTextbox.php index d146b36ed6..7d12f9669e 100644 --- a/app/Report/ReportBaseTextbox.php +++ b/app/Report/ReportBaseTextbox.php @@ -27,87 +27,49 @@ class ReportBaseTextbox extends ReportBaseElement /** * Array of elements in the TextBox * - * @var ReportBaseElement[]|string[] + * @var array<ReportBaseElement|string> */ - public $elements = []; + public array $elements = []; - /** - * Background color in HTML code - * - * @var string - */ - public $bgcolor; - /** - * Whether or not paint the background - * - * @var bool - */ - public $fill; + // Background color in HTML code + public string $bgcolor; - /** - * Position the left corner of this box on the page(expressed in points). The default is the current position. - * - * @var float - */ - public $left; - /** - * Position the top corner of this box on the page(expressed in points). the default is the current position - * - * @var float - */ - public $top; - /** - * After this box is finished rendering, should the next section of text start immediately after the this box or should it start on a new line under this box. 0 = no new line, 1 = force new line. Default is 0 - * - * @var bool - */ - public $newline; + // Whether to paint the background + public bool $fill; - /** @var bool Unused? */ - public $pagecheck; + // Position the left corner of this box on the page(expressed in points). The default is the current position. + public float $left; - /** @var bool Whether to print a border */ - public $border; + // Position the top corner of this box on the page(expressed in points). the default is the current position + public float $top; - /** - * Style of rendering - * - * <ul> - * <li>D or empty string: Draw (default).</li> - * <li>F: Fill.</li> - * <li>DF or FD: Draw and fill.</li> - * <li>CNZ: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path).</li> - *<li>CEO: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path).</li> - * </ul> - * - * @var string - */ - public $style; + // After this box is finished rendering, should the next section of text start immediately after + // this box or should it start on a new line under this box. 0 = no new line, 1 = force new line. + public bool $newline; - /** - * The starting height of this cell. If the text wraps the height will automatically be adjusted - * - * @var float - */ - public $height; - /** - * Setting the width to 0 will make it the width from the current location to the right margin - * - * @var float - */ - public $width; - /** - * Use cell padding or not - * - * @var bool - */ - public $padding; - /** - * Resets this box last height after it’s done - * - * @var bool - */ - public $reseth; + public bool $pagecheck; + + public bool $border; + + // Style of rendering + // D or empty string: Draw (default). + // F: Fill. + // DF or FD: Draw and fill. + // CEO: Clipping mode (using the even-odd rule to determine which regions lie inside the clipping path). + // CNZ: Clipping mode (using the nonzero winding number rule to determine which regions lie inside the clipping path). + public string $style; + + // The starting height of this cell. If the text wraps the height will automatically be adjusted + public float $height; + + // Setting the width to 0 will make it the width from the current location to the right margin + public float $width; + + // Use cell padding or not + public bool $padding; + + // Resets this box last height after it’s done + public bool $reseth; /** * TextBox - Element - Base diff --git a/app/Report/ReportExpressionLanguageProvider.php b/app/Report/ReportExpressionLanguageProvider.php index d126d4767e..d25889f9e0 100644 --- a/app/Report/ReportExpressionLanguageProvider.php +++ b/app/Report/ReportExpressionLanguageProvider.php @@ -28,7 +28,7 @@ use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; class ReportExpressionLanguageProvider implements ExpressionFunctionProviderInterface { /** - * @return ExpressionFunction[] + * @return array<ExpressionFunction> */ public function getFunctions(): array { diff --git a/app/Report/ReportHtmlCell.php b/app/Report/ReportHtmlCell.php index 12b5834c89..48e89f3cd4 100644 --- a/app/Report/ReportHtmlCell.php +++ b/app/Report/ReportHtmlCell.php @@ -35,7 +35,7 @@ class ReportHtmlCell extends ReportBaseCell * * @return void */ - public function render($renderer) + public function render($renderer): void { if (str_contains($this->text, '{{:ptp:}}')) { return; @@ -88,65 +88,35 @@ class ReportHtmlCell extends ReportBaseCell $bpixY = 0; if (!empty($this->border)) { // Border all around - if ($this->border == 1) { - echo ' border:solid '; - if (!empty($this->bocolor)) { - echo $this->bocolor; - } else { - echo 'black'; - } - echo ' 1pt;'; + if ($this->border === '1') { + echo ' border:solid ', $this->bocolor ?: 'black', ' 1pt;'; $bpixX = 1; $bpixY = 1; } else { - if (stripos($this->border, 'T') !== false) { - echo ' border-top:solid '; - if (!empty($this->bocolor)) { - echo $this->bocolor; - } else { - echo 'black'; - } - echo ' 1pt;'; + if (str_contains($this->border, 'T')) { + echo ' border-top:solid ', $this->bocolor ?: 'black', ' 1pt;'; $bpixY = 1; } - if (stripos($this->border, 'B') !== false) { - echo ' border-bottom:solid '; - if (!empty($this->bocolor)) { - echo $this->bocolor; - } else { - echo 'black'; - } - echo ' 1pt;'; + if (str_contains($this->border, 'B')) { + echo ' border-bottom:solid ', $this->bocolor ?: 'black', ' 1pt;'; $bpixY = 1; } - if (stripos($this->border, 'R') !== false) { - echo ' border-right:solid '; - if (!empty($this->bocolor)) { - echo $this->bocolor; - } else { - echo 'black'; - } - echo ' 1pt;'; + if (str_contains($this->border, 'R')) { + echo ' border-right:solid ', $this->bocolor ?: 'black', ' 1pt;'; $bpixX = 1; } - if (stripos($this->border, 'L') !== false) { - echo ' border-left:solid '; - if (!empty($this->bocolor)) { - echo $this->bocolor; - } else { - echo 'black'; - } - echo ' 1pt;'; + if (str_contains($this->border, 'L')) { + echo ' border-left:solid ', $this->bocolor ?: 'black', ' 1pt;'; $bpixX = 1; } } } // Check the width if set to page wide OR set by xml to larger then page wide - if ($this->width == 0 || $this->width > $renderer->getRemainingWidth()) { + if ($this->width === 0.0 || $this->width > $renderer->getRemainingWidth()) { $this->width = $renderer->getRemainingWidth(); } // We have to calculate a different width for the padding, counting on both side - $cW = $this->width - $cP * 2; + $cW = $this->width - $cP * 2.0; // If there is any text if (!empty($temptext)) { diff --git a/app/Report/ReportHtmlFootnote.php b/app/Report/ReportHtmlFootnote.php index e57d96f845..5309436f0c 100644 --- a/app/Report/ReportHtmlFootnote.php +++ b/app/Report/ReportHtmlFootnote.php @@ -36,7 +36,7 @@ class ReportHtmlFootnote extends ReportBaseFootnote * * @return void */ - public function render($renderer) + public function render($renderer): void { $renderer->setCurrentStyle('footnotenum'); echo '<a href="#footnote', $this->num, '"><sup>'; @@ -77,26 +77,26 @@ class ReportHtmlFootnote extends ReportBaseFootnote /** * Calculates the Footnotes height * - * @param HtmlRenderer $html + * @param HtmlRenderer $renderer * @param float $cellWidth The width of the cell to use it for text wraping * * @return float Footnote height in points */ - public function getFootnoteHeight($html, float $cellWidth = 0): float + public function getFootnoteHeight(HtmlRenderer $renderer, float $cellWidth = 0): float { - if ($html->getCurrentStyle() !== $this->styleName) { - $html->setCurrentStyle($this->styleName); + if ($renderer->getCurrentStyle() !== $this->styleName) { + $renderer->setCurrentStyle($this->styleName); } if ($cellWidth > 0) { - $this->text = $html->textWrap($this->text, $cellWidth); + $this->text = $renderer->textWrap($this->text, $cellWidth); } $this->text .= "\n\n"; $ct = substr_count($this->text, "\n"); - $fsize = $html->getCurrentStyleHeight(); + $fsize = $renderer->getCurrentStyleHeight(); - return $fsize * $ct * $html->cellHeightRatio; + return $fsize * $ct * $renderer->cellHeightRatio; } /** @@ -105,7 +105,7 @@ class ReportHtmlFootnote extends ReportBaseFootnote * * @param HtmlRenderer $renderer * - * @return array{0:float,1:int,2:float|int} + * @return array{0:float,1:int,2:float} */ public function getWidth($renderer): array { diff --git a/app/Report/ReportHtmlImage.php b/app/Report/ReportHtmlImage.php index e57bb01b3b..39163166a7 100644 --- a/app/Report/ReportHtmlImage.php +++ b/app/Report/ReportHtmlImage.php @@ -31,7 +31,7 @@ class ReportHtmlImage extends ReportBaseImage * * @return void */ - public function render($renderer) + public function render($renderer): void { static $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright; diff --git a/app/Report/ReportHtmlLine.php b/app/Report/ReportHtmlLine.php index 05de0a7399..edc2aef6db 100644 --- a/app/Report/ReportHtmlLine.php +++ b/app/Report/ReportHtmlLine.php @@ -31,7 +31,7 @@ class ReportHtmlLine extends ReportBaseLine * * @return void */ - public function render($renderer) + public function render($renderer): void { if ($this->x1 === ReportBaseElement::CURRENT_POSITION) { $this->x1 = $renderer->getX(); @@ -46,11 +46,11 @@ class ReportHtmlLine extends ReportBaseLine $this->y2 = $renderer->getY(); } // Vertical line - if ($this->x1 == $this->x2) { + if ($this->x1 === $this->x2) { echo '<div style="position:absolute;overflow:hidden;border-', $renderer->alignRTL, ':solid black 1pt;', $renderer->alignRTL, ':', $this->x1, 'pt;top:', $this->y1 + 1, 'pt;width:1pt;height:', $this->y2 - $this->y1, "pt;\"> </div>\n"; } // Horizontal line - if ($this->y1 == $this->y2) { + if ($this->y1 === $this->y2) { echo '<div style="position:absolute;overflow:hidden;border-top:solid black 1pt;', $renderer->alignRTL, ':', $this->x1, 'pt;top:', $this->y1 + 1, 'pt;width:', $this->x2 - $this->x1, "pt;height:1pt;\"> </div>\n"; } // Keep max Y updated diff --git a/app/Report/ReportHtmlText.php b/app/Report/ReportHtmlText.php index bee02a14ed..65e6e3bef3 100644 --- a/app/Report/ReportHtmlText.php +++ b/app/Report/ReportHtmlText.php @@ -37,7 +37,7 @@ class ReportHtmlText extends ReportBaseText * * @return void */ - public function render($renderer, bool $attrib = true) + public function render($renderer, bool $attrib = true): void { // Set up the style if ($renderer->getCurrentStyle() !== $this->styleName) { @@ -111,7 +111,7 @@ class ReportHtmlText extends ReportBaseText * * @param HtmlRenderer $renderer * - * @return array{0:float,1:int,2:float|int} + * @return array{0:float,1:int,2:float} */ public function getWidth($renderer): array { diff --git a/app/Report/ReportHtmlTextbox.php b/app/Report/ReportHtmlTextbox.php index 0b518dab28..34a523201a 100644 --- a/app/Report/ReportHtmlTextbox.php +++ b/app/Report/ReportHtmlTextbox.php @@ -38,7 +38,7 @@ class ReportHtmlTextbox extends ReportBaseTextbox * * @return void */ - public function render($renderer) + public function render($renderer): void { // checkFootnote $newelements = []; @@ -141,7 +141,7 @@ class ReportHtmlTextbox extends ReportBaseTextbox } // Check the width if set to page wide OR set by xml to larger then page width (margin) - if ($this->width == 0 || $this->width > $renderer->getRemainingWidth()) { + if ($this->width === 0.0 || $this->width > $renderer->getRemainingWidth()) { $this->width = $renderer->getRemainingWidth(); } // Setup the CellPadding @@ -150,13 +150,13 @@ class ReportHtmlTextbox extends ReportBaseTextbox } // For padding, we have to use less wrap width - $cW = $this->width - $cP * 2; + $cW = $this->width - $cP * 2.0; //-- calculate the text box height // Number of lines, will be converted to height $cHT = 0; - // Element height (exept text) - $eH = 0; + // Element height (except text) + $eH = 0.0; // Footnote height (in points) $fH = 0; $w = 0; @@ -170,7 +170,7 @@ class ReportHtmlTextbox extends ReportBaseTextbox for ($i = 0; $i < $cE; $i++) { if (is_object($this->elements[$i])) { $ew = $this->elements[$i]->setWrapWidth($cW - $w - 2, $cW); - if ($ew == $cW) { + if ($ew === $cW) { $w = 0; } $lw = $this->elements[$i]->getWidth($renderer); @@ -198,7 +198,7 @@ class ReportHtmlTextbox extends ReportBaseTextbox // If any element exist if ($cE > 0) { // Check if this is text or some other element, like images - if ($eH == 0) { + if ($eH === 0.0) { // Number of LF but at least one line $cHT = ($cHT + 1) * $renderer->cellHeightRatio; // Calculate the cell hight with the largest font size used diff --git a/app/Report/ReportParserBase.php b/app/Report/ReportParserBase.php index 480a939c24..7d1cad5b61 100644 --- a/app/Report/ReportParserBase.php +++ b/app/Report/ReportParserBase.php @@ -51,7 +51,7 @@ class ReportParserBase protected $xml_parser; /** @var string Text contents of tags */ - protected $text = ''; + protected string $text = ''; /** * Create a parser for a report diff --git a/app/Report/ReportParserGenerate.php b/app/Report/ReportParserGenerate.php index fc1016fcd8..2a9dc526b9 100644 --- a/app/Report/ReportParserGenerate.php +++ b/app/Report/ReportParserGenerate.php @@ -462,85 +462,52 @@ class ReportParserGenerate extends ReportParserBase /** * Handle <cell> * - * @param string[] $attrs + * @param array<string,string> $attrs * * @return void */ protected function cellStartHandler(array $attrs): void { // string The text alignment of the text in this box. - $align = ''; - if (!empty($attrs['align'])) { - $align = $attrs['align']; - // RTL supported left/right alignment - if ($align === 'rightrtl') { - if ($this->wt_report->rtl) { - $align = 'left'; - } else { - $align = 'right'; - } - } elseif ($align === 'leftrtl') { - if ($this->wt_report->rtl) { - $align = 'right'; - } else { - $align = 'left'; - } + $align = $attrs['align'] ?? ''; + // RTL supported left/right alignment + if ($align === 'rightrtl') { + if ($this->wt_report->rtl) { + $align = 'left'; + } else { + $align = 'right'; + } + } elseif ($align === 'leftrtl') { + if ($this->wt_report->rtl) { + $align = 'right'; + } else { + $align = 'left'; } } - // string The color to fill the background of this cell - $bgcolor = ''; - if (!empty($attrs['bgcolor'])) { - $bgcolor = $attrs['bgcolor']; - } + // The color to fill the background of this cell + $bgcolor = $attrs['bgcolor'] ?? ''; - // int Whether or not the background should be painted - $fill = 1; - if (isset($attrs['fill'])) { - if ($attrs['fill'] === '0') { - $fill = 0; - } elseif ($attrs['fill'] === '1') { - $fill = 1; - } - } + // Whether the background should be painted + $fill = (int) ($attrs['fill'] ?? '0'); - $reseth = true; - // boolean if true reset the last cell height (default true) - if (isset($attrs['reseth'])) { - if ($attrs['reseth'] === '0') { - $reseth = false; - } elseif ($attrs['reseth'] === '1') { - $reseth = true; - } - } + // If true reset the last cell height + $reseth = (bool) ($attrs['reseth'] ?? '1'); + + // Whether a border should be printed around this box + $border = $attrs['border'] ?? ''; - // mixed Whether or not a border should be printed around this box - $border = 0; - if (!empty($attrs['border'])) { - $border = $attrs['border']; - } // string Border color in HTML code - $bocolor = ''; - if (!empty($attrs['bocolor'])) { - $bocolor = $attrs['bocolor']; - } + $bocolor = $attrs['bocolor'] ?? ''; + + // Cell height (expressed in points) The starting height of this cell. If the text wraps the height will automatically be adjusted. + $height = (int) ($attrs['height'] ?? '0'); - // int Cell height (expressed in points) The starting height of this cell. If the text wraps the height will automatically be adjusted. - $height = 0; - if (!empty($attrs['height'])) { - $height = $attrs['height']; - } // int Cell width (expressed in points) Setting the width to 0 will make it the width from the current location to the right margin. - $width = 0; - if (!empty($attrs['width'])) { - $width = $attrs['width']; - } + $width = (int) ($attrs['width'] ?? '0'); - // int Stretch carachter mode - $stretch = 0; - if (!empty($attrs['stretch'])) { - $stretch = (int) $attrs['stretch']; - } + // Stretch character mode + $stretch = (int) ($attrs['stretch'] ?? '0'); // mixed Position the left corner of this box on the page. The default is the current position. $left = ReportBaseElement::CURRENT_POSITION; @@ -565,17 +532,11 @@ class ReportParserGenerate extends ReportParserBase } } - // string The name of the Style that should be used to render the text. - $style = ''; - if (!empty($attrs['style'])) { - $style = $attrs['style']; - } + // The name of the Style that should be used to render the text. + $style = $attrs['style'] ?? ''; // string Text color in html code - $tcolor = ''; - if (!empty($attrs['tcolor'])) { - $tcolor = $attrs['tcolor']; - } + $tcolor = $attrs['tcolor'] ?? ''; // int Indicates where the current position should go after the call. $ln = 0; diff --git a/app/Report/ReportParserSetup.php b/app/Report/ReportParserSetup.php index 35002d2ef1..66b77b7549 100644 --- a/app/Report/ReportParserSetup.php +++ b/app/Report/ReportParserSetup.php @@ -31,10 +31,10 @@ use function strtoupper; class ReportParserSetup extends ReportParserBase { /** @var array An array of report options/parameters */ - private $data = []; + private array $data = []; - /** @var string[] An array of input attributes */ - private $input; + /** @var array<string> An array of input attributes */ + private array $input; /** * Return the parsed data. diff --git a/app/Report/ReportPdfCell.php b/app/Report/ReportPdfCell.php index 7b2385778c..67330b9ddd 100644 --- a/app/Report/ReportPdfCell.php +++ b/app/Report/ReportPdfCell.php @@ -38,7 +38,7 @@ class ReportPdfCell extends ReportBaseCell * * @return void */ - public function render($renderer) + public function render($renderer): void { $temptext = str_replace('#PAGENUM#', (string) $renderer->tcpdf->PageNo(), $this->text); // underline «title» part of Source item @@ -101,7 +101,7 @@ class ReportPdfCell extends ReportBaseCell } // Check the width if set to page wide OR set by xml to larger then page wide - if ($this->width == 0 || $this->width > $renderer->getRemainingWidthPDF()) { + if ($this->width === 0.0 || $this->width > $renderer->getRemainingWidthPDF()) { $this->width = $renderer->getRemainingWidthPDF(); } // For current position diff --git a/app/Report/ReportPdfFootnote.php b/app/Report/ReportPdfFootnote.php index 7dd06370c1..44a0d7cdbf 100644 --- a/app/Report/ReportPdfFootnote.php +++ b/app/Report/ReportPdfFootnote.php @@ -37,7 +37,7 @@ class ReportPdfFootnote extends ReportBaseFootnote * * @return void */ - public function render($renderer) + public function render($renderer): void { $renderer->setCurrentStyle('footnotenum'); $renderer->tcpdf->Write($renderer->getCurrentStyleHeight(), $this->numText, $this->addlink); //source link numbers after name @@ -84,7 +84,7 @@ class ReportPdfFootnote extends ReportBaseFootnote * * @return float $h */ - public function getFootnoteHeight($renderer): float + public function getFootnoteHeight(PdfRenderer $renderer): float { return 0; } @@ -95,7 +95,7 @@ class ReportPdfFootnote extends ReportBaseFootnote * * @param PdfRenderer $renderer * - * @return array{0:float,1:int,2:float|int} + * @return array{0:float,1:int,2:float} */ public function getWidth($renderer): array { diff --git a/app/Report/ReportPdfImage.php b/app/Report/ReportPdfImage.php index 21a58ae23f..fd8afb4c71 100644 --- a/app/Report/ReportPdfImage.php +++ b/app/Report/ReportPdfImage.php @@ -31,7 +31,7 @@ class ReportPdfImage extends ReportBaseImage * * @return void */ - public function render($renderer) + public function render($renderer): void { static $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright; diff --git a/app/Report/ReportPdfLine.php b/app/Report/ReportPdfLine.php index 2ce844692f..30031acab9 100644 --- a/app/Report/ReportPdfLine.php +++ b/app/Report/ReportPdfLine.php @@ -31,7 +31,7 @@ class ReportPdfLine extends ReportBaseLine * * @return void */ - public function render($renderer) + public function render($renderer): void { if ($this->x1 === ReportBaseElement::CURRENT_POSITION) { $this->x1 = $renderer->tcpdf->GetX(); diff --git a/app/Report/ReportPdfText.php b/app/Report/ReportPdfText.php index 3a9718a1c3..40b28306d2 100644 --- a/app/Report/ReportPdfText.php +++ b/app/Report/ReportPdfText.php @@ -40,7 +40,7 @@ class ReportPdfText extends ReportBaseText * * @return void */ - public function render($renderer) + public function render($renderer): void { // Set up the style if ($renderer->getCurrentStyle() !== $this->styleName) { @@ -112,7 +112,7 @@ class ReportPdfText extends ReportBaseText * * @param PdfRenderer $renderer * - * @return array{0:float,1:int,2:float|int} + * @return array{0:float,1:int,2:float} */ public function getWidth($renderer): array { diff --git a/app/Report/ReportPdfTextBox.php b/app/Report/ReportPdfTextBox.php index 315fdc2dd7..cb1153becb 100644 --- a/app/Report/ReportPdfTextBox.php +++ b/app/Report/ReportPdfTextBox.php @@ -40,7 +40,7 @@ class ReportPdfTextBox extends ReportBaseTextbox * * @return void */ - public function render($renderer) + public function render($renderer): void { $newelements = []; $lastelement = ''; @@ -52,18 +52,16 @@ class ReportPdfTextBox extends ReportBaseTextbox $element = $this->elements[$i]; if ($element instanceof ReportBaseElement) { if ($element instanceof ReportBaseText) { - if (!empty($footnote_element)) { - ksort($footnote_element); - foreach ($footnote_element as $links) { - $newelements[] = $links; - } - $footnote_element = []; + ksort($footnote_element); + foreach ($footnote_element as $links) { + $newelements[] = $links; } + $footnote_element = []; if (empty($lastelement)) { $lastelement = $element; } else { // Checking if the Text has the same style - if ($element->getStyleName() == $lastelement->getStyleName()) { + if ($element->getStyleName() === $lastelement->getStyleName()) { $lastelement->addText(str_replace("\n", '<br>', $element->getValue())); } elseif (!empty($lastelement)) { $newelements[] = $lastelement; @@ -80,7 +78,7 @@ class ReportPdfTextBox extends ReportBaseTextbox } // Save the Footnote with it’s link number as key for sorting later $footnote_element[$element->num] = $element; - } elseif (!$element instanceof ReportPdfFootnote || trim($element->getValue()) != '') { + } elseif (!$element instanceof ReportPdfFootnote || trim($element->getValue()) !== '') { // Do not keep empty footnotes if (!empty($footnote_element)) { ksort($footnote_element); @@ -142,7 +140,7 @@ class ReportPdfTextBox extends ReportBaseTextbox } // Check the width if set to page wide OR set by xml to larger then page width (margin) - if ($this->width == 0 || $this->width > $renderer->getRemainingWidthPDF()) { + if ($this->width === 0.0 || $this->width > $renderer->getRemainingWidthPDF()) { $cW = $renderer->getRemainingWidthPDF(); } else { $cW = $this->width; @@ -157,8 +155,8 @@ class ReportPdfTextBox extends ReportBaseTextbox } else { $cWT = $cW - $cM['cell'] * 2; } - // Element height (exept text) - $eH = 0; + // Element height (except text) + $eH = 0.0; $w = 0; // Temp Height $cHT = 0; @@ -173,7 +171,7 @@ class ReportPdfTextBox extends ReportBaseTextbox for ($i = 0; $i < $cE; $i++) { if (is_object($this->elements[$i])) { $ew = $this->elements[$i]->setWrapWidth($cWT - $w, $cWT); - if ($ew == $cWT) { + if ($ew === $cWT) { $w = 0; } $lw = $this->elements[$i]->getWidth($renderer); @@ -201,7 +199,7 @@ class ReportPdfTextBox extends ReportBaseTextbox // If any element exist if ($cE > 0) { // Check if this is text or some other element, like images - if ($eH == 0) { + if ($eH === 0.0) { // This is text elements. Number of LF but at least one line $cHT = ($cHT + 1) * $renderer->tcpdf->getCellHeightRatio(); // Calculate the cell hight with the largest font size used within this Box @@ -319,7 +317,7 @@ class ReportPdfTextBox extends ReportBaseTextbox if ($this->reseth) { $cH = 0; // This can only happen with multiple images and with pagebreak - if ($cPN != $renderer->tcpdf->getPage()) { + if ($cPN !== $renderer->tcpdf->getPage()) { $renderer->tcpdf->setPage($cPN); } } |
