diff --git a/app/Report/AbstractRenderer.php b/app/Report/AbstractRenderer.php index 239ed195f7..0ff2758905 100644 --- a/app/Report/AbstractRenderer.php +++ b/app/Report/AbstractRenderer.php @@ -51,68 +51,73 @@ abstract class AbstractRenderer 'US-Tabloid' => [11.0 * self::INCH_TO_POINTS, 17.0 * self::INCH_TO_POINTS], ]; - /** @var float Left Margin */ - public $left_margin = 18.0 * self::MM_TO_POINTS; + public float $left_margin = 18.0 * self::MM_TO_POINTS; - /** @var float Right Margin */ - public $right_margin = 9.9 * self::MM_TO_POINTS; + public float $right_margin = 9.9 * self::MM_TO_POINTS; - /** @var float Top Margin */ - public $top_margin = 26.8 * self::MM_TO_POINTS; + public float $top_margin = 26.8 * self::MM_TO_POINTS; - /** @var float Bottom Margin */ - public $bottom_margin = 21.6 * self::MM_TO_POINTS; + public float $bottom_margin = 21.6 * self::MM_TO_POINTS; - /** @var float Header Margin */ - public $header_margin = 4.9 * self::MM_TO_POINTS; + public float $header_margin = 4.9 * self::MM_TO_POINTS; - /** @var float Footer Margin */ - public $footer_margin = 9.9 * self::MM_TO_POINTS; + public float $footer_margin = 9.9 * self::MM_TO_POINTS; /** @var string Page orientation (portrait, landscape) */ - public $orientation = 'portrait'; + public string $orientation = 'portrait'; /** @var string Page format name */ - public $page_format = 'A4'; + public string $page_format = 'A4'; /** @var float Height of page format in points */ - public $page_height = 0.0; + public float $page_height = 0.0; /** @var float Width of page format in points */ - public $page_width = 0.0; + public float $page_width = 0.0; - /** @var string[][] An array of the Styles elements found in the document */ - public $styles = []; + /** @var array> An array of the Styles elements found in the document */ + public array $styles = []; /** @var string The default Report font name */ - public $default_font = 'dejavusans'; + public string $default_font = 'dejavusans'; /** @var float The default Report font size */ - public $default_font_size = 12.0; + public float $default_font_size = 12.0; /** @var string Header (H), Body (B) or Footer (F) */ - public $processing = 'H'; + public string $processing = 'H'; /** @var bool RTL Language (false=LTR, true=RTL) */ - public $rtl = false; + public bool $rtl = false; /** @var bool Show the Generated by... (true=show the text) */ public $show_generated_by = true; /** @var string Generated By... text */ - public $generated_by = ''; + public string $generated_by = ''; /** @var string The report title */ - public $title = ''; + public string $title = ''; /** @var string Author of the report, the users full name */ - public $rauthor = Webtrees::NAME . ' ' . Webtrees::VERSION; + public string $rauthor = Webtrees::NAME . ' ' . Webtrees::VERSION; /** @var string Keywords */ - public $rkeywords = ''; + public string $rkeywords = ''; /** @var string Report Description / Subject */ - public $rsubject = ''; + public string $rsubject = ''; + + /** @var array */ + public array $headerElements = []; + + /** @var array */ + public $footerElements = []; + + /** @var array */ + public array $bodyElements = []; + + public string $currentStyle = ''; /** * Clear the Header. @@ -121,14 +126,52 @@ abstract class AbstractRenderer */ abstract public function clearHeader(): void; + + /** + * @param ReportBaseElement|string $element + * + * @return void + */ + public function addElement($element): void + { + if ($this->processing === 'B') { + $this->addElementToBody($element); + } elseif ($this->processing === 'H') { + $this->addElementToHeader($element); + } elseif ($this->processing === 'F') { + $this->addElementToFooter($element); + } + } + + /** + * @param ReportBaseElement|string $element + * + * @return void + */ + public function addElementToHeader($element): void + { + $this->headerElements[] = $element; + } + /** - * Add an element. + * @param ReportBaseElement|string $element * + * @return void + */ + public function addElementToBody($element): void + { + $this->bodyElements[] = $element; + } + + /** * @param ReportBaseElement|string $element * * @return void */ - abstract public function addElement($element): void; + public function addElementToFooter($element): void + { + $this->footerElements[] = $element; + } /** * Run the report. diff --git a/app/Report/HtmlRenderer.php b/app/Report/HtmlRenderer.php index 99552ec729..62430b0e08 100644 --- a/app/Report/HtmlRenderer.php +++ b/app/Report/HtmlRenderer.php @@ -69,13 +69,6 @@ class HtmlRenderer extends AbstractRenderer */ public $Y = 0.0; - /** - * Currently used style name - * - * @var string - */ - public $currentStyle = ''; - /** * Page number counter * @@ -133,15 +126,6 @@ class HtmlRenderer extends AbstractRenderer */ public $maxY = 0; - /** @var ReportBaseElement[] Array of elements in the header */ - public $headerElements = []; - - /** @var ReportBaseElement[] Array of elements in the footer */ - public $footerElements = []; - - /** @var ReportBaseElement[] Array of elements in the body */ - public $bodyElements = []; - /** @var ReportHtmlFootnote[] Array of elements in the footer notes */ public $printedfootnotes = []; @@ -179,24 +163,6 @@ public function setup(): void } } - /** - * Add an element. - * - * @param ReportBaseElement|string $element - * - * @return void - */ - public function addElement($element): void - { - if ($this->processing === 'B') { - $this->bodyElements[] = $element; - } elseif ($this->processing === 'H') { - $this->headerElements[] = $element; - } elseif ($this->processing === 'F') { - $this->footerElements[] = $element; - } - } - /** * Generate footnotes * diff --git a/app/Report/PdfRenderer.php b/app/Report/PdfRenderer.php index 510facf54e..ab7081cc28 100644 --- a/app/Report/PdfRenderer.php +++ b/app/Report/PdfRenderer.php @@ -51,42 +51,22 @@ class PdfRenderer extends AbstractRenderer */ private const UNICODE = true; - /** - * false means that the full font is embedded, true means only the used chars - * in TCPDF v5.9 font subsetting is a very slow process, this leads to larger files - * - * @var bool const - */ + // Font sub-setting in TCPDF is slow. private const SUBSETTING = false; - /** - * @var TcpdfWrapper - */ - public $tcpdf; - - /** @var ReportBaseElement[] Array of elements in the header */ - public $headerElements = []; + public TcpdfWrapper $tcpdf; - /** @var ReportBaseElement[] Array of elements in the footer */ - public $footerElements = []; - - /** @var ReportBaseElement[] Array of elements in the body */ - public $bodyElements = []; - - /** @var ReportPdfFootnote[] Array of elements in the footer notes */ - public $printedfootnotes = []; - - /** @var string Currently used style name */ - public $currentStyle = ''; + /** @var array Array of elements in the footer notes */ + public array $printedfootnotes = []; /** @var float The last cell height */ - public $lastCellHeight = 0; + public float $lastCellHeight = 0.0; /** @var float The largest font size within a TextBox to calculate the height */ - public $largestFontHeight = 0; + public float $largestFontHeight = 0.0; /** @var int The last pictures page number */ - public $lastpicpage = 0; + public int $lastpicpage = 0; /** @var PdfRenderer The current report. */ public $wt_report; @@ -167,42 +147,6 @@ public function footer(): void } } - /** - * Add an element to the Header -PDF - * - * @param ReportBaseElement|string $element - * - * @return void - */ - public function addHeader($element): void - { - $this->headerElements[] = $element; - } - - /** - * Add an element to the Body -PDF - * - * @param ReportBaseElement|string $element - * - * @return void - */ - public function addBody($element): void - { - $this->bodyElements[] = $element; - } - - /** - * Add an element to the Footer -PDF - * - * @param ReportBaseElement|string $element - * - * @return void - */ - public function addFooter($element): void - { - $this->footerElements[] = $element; - } - /** * Remove the header. * @@ -444,25 +388,22 @@ public function setup(): void { parent::setup(); - // Setup the PDF class with custom size pages because WT supports more page sizes. If WT sends an unknown size name then the default would be A4 - $this->tcpdf = new TcpdfWrapper($this->orientation, parent::UNITS, [ - $this->page_width, - $this->page_height, - ], self::UNICODE, 'UTF-8', self::DISK_CACHE); + $this->tcpdf = new TcpdfWrapper( + $this->orientation, + self::UNITS, + [$this->page_width, $this->page_height], + self::UNICODE, + 'UTF-8', + self::DISK_CACHE + ); - // Setup the PDF margins $this->tcpdf->SetMargins($this->left_margin, $this->top_margin, $this->right_margin); $this->tcpdf->setHeaderMargin($this->header_margin); $this->tcpdf->setFooterMargin($this->footer_margin); - //Set auto page breaks $this->tcpdf->SetAutoPageBreak(true, $this->bottom_margin); - // Set font subsetting $this->tcpdf->setFontSubsetting(self::SUBSETTING); - // Setup PDF compression $this->tcpdf->SetCompression(self::COMPRESSION); - // Setup RTL support $this->tcpdf->setRTL($this->rtl); - // Set the document information $this->tcpdf->SetCreator(Webtrees::NAME . ' ' . Webtrees::VERSION); $this->tcpdf->SetAuthor($this->rauthor); $this->tcpdf->SetTitle($this->title); @@ -478,35 +419,7 @@ public function setup(): void $element = new ReportPdfCell(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->addFooter($element); - } - } - - /** - * Add an element. - * - * @param ReportBaseElement|string $element - * - * @return void - */ - public function addElement($element): void - { - if ($this->processing === 'B') { - $this->addBody($element); - - return; - } - - if ($this->processing === 'H') { - $this->addHeader($element); - - return; - } - - if ($this->processing === 'F') { - $this->addFooter($element); - - return; + $this->addElementToFooter($element); } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 81e6d9d4e6..99ebc7ea7c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1155,52 +1155,22 @@ parameters: path: app/Report/AbstractRenderer.php - - message: "#^Method Fisharebest\\\\Webtrees\\\\Report\\\\AbstractRenderer\\:\\:getStyle\\(\\) should return array but returns array\\\\|false\\.$#" + message: "#^Method Fisharebest\\\\Webtrees\\\\Report\\\\AbstractRenderer\\:\\:getStyle\\(\\) should return array but returns array\\\\|false\\.$#" count: 1 path: app/Report/AbstractRenderer.php - - message: "#^Array \\(array\\\\) does not accept Fisharebest\\\\Webtrees\\\\Report\\\\ReportBaseElement\\|string\\.$#" - count: 3 - path: app/Report/HtmlRenderer.php - - - - message: "#^Elseif branch is unreachable because previous condition is always true\\.$#" - count: 6 - path: app/Report/HtmlRenderer.php - - - - message: "#^Strict comparison using \\=\\=\\= between \\*NEVER\\* and 'addpage' will always evaluate to false\\.$#" - count: 3 - path: app/Report/HtmlRenderer.php - - - - message: "#^Strict comparison using \\=\\=\\= between \\*NEVER\\* and 'footnotetexts' will always evaluate to false\\.$#" - count: 3 - path: app/Report/HtmlRenderer.php - - - - message: "#^Array \\(array\\\\) does not accept Fisharebest\\\\Webtrees\\\\Report\\\\ReportBaseElement\\|string\\.$#" - count: 3 - path: app/Report/PdfRenderer.php - - - - message: "#^Array \\(array\\\\>\\) does not accept string\\.$#" + message: "#^Array \\(array\\\\>\\) does not accept string\\.$#" count: 1 path: app/Report/PdfRenderer.php - - - message: "#^Elseif branch is unreachable because previous condition is always true\\.$#" - count: 6 - path: app/Report/PdfRenderer.php - - message: "#^Method Fisharebest\\\\Webtrees\\\\Report\\\\PdfRenderer\\:\\:getStyle\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: app/Report/PdfRenderer.php - - message: "#^Method Fisharebest\\\\Webtrees\\\\Report\\\\PdfRenderer\\:\\:getStyle\\(\\) should return array but returns array\\\\|string\\.$#" + message: "#^Method Fisharebest\\\\Webtrees\\\\Report\\\\PdfRenderer\\:\\:getStyle\\(\\) should return array but returns array\\\\|string\\.$#" count: 1 path: app/Report/PdfRenderer.php @@ -1224,16 +1194,6 @@ parameters: count: 1 path: app/Report/PdfRenderer.php - - - message: "#^Strict comparison using \\=\\=\\= between \\*NEVER\\* and 'addpage' will always evaluate to false\\.$#" - count: 3 - path: app/Report/PdfRenderer.php - - - - message: "#^Strict comparison using \\=\\=\\= between \\*NEVER\\* and 'footnotetexts' will always evaluate to false\\.$#" - count: 3 - path: app/Report/PdfRenderer.php - - message: "#^Parameter \\#1 \\$callback of function call_user_func expects callable\\(\\)\\: mixed, array\\(\\$this\\(Fisharebest\\\\Webtrees\\\\Report\\\\ReportParserBase\\), non\\-empty\\-string\\) given\\.$#" count: 2