diff --git a/autoload.php b/autoload.php index 91952c8..10d31ec 100644 --- a/autoload.php +++ b/autoload.php @@ -1,5 +1,5 @@ setStyle('h4', 11, null, null, null, 'h'); $multicell->setStyle('super', 8, null, [255, 102, 153]); -$s = <<The following is Subscript and Superscript

@@ -55,7 +54,7 @@ $pdf->ln(10); -$s = <<Typography:

Heading 1

@@ -68,9 +67,9 @@ $pdf->ln(10); -$multicell->multiCell(0, 10, "Table of Content:"); +$multicell->multiCell(0, 10, 'Table of Content:'); -$s = <<

- Paragraph 1

- Paragraph 2

- Paragraph 2.1

@@ -80,9 +79,9 @@ $multicell->multiCell(0, 5, $s); $pdf->ln(10); -$multicell->multiCell(0, 10, "Tag width and alignment:"); +$multicell->multiCell(0, 10, 'Tag width and alignment:'); -$s = << Align Left

Align Center

Align Right

@@ -90,7 +89,7 @@ $multicell->multiCell(100, 5, $s, 1, '', 1); $pdf->AddPage(); -$multicell->multiCell(0, 10, "No wrap: text will not break on normal separators"); +$multicell->multiCell(0, 10, 'No wrap: text will not break on normal separators'); $s = "The price is USD 5.344,23"; foreach ([40, 45, 50] as $width) { diff --git a/dev/dev-multicell-shrinking.php b/dev/dev-multicell-shrinking.php index 5d679f6..3dce0e0 100644 --- a/dev/dev-multicell-shrinking.php +++ b/dev/dev-multicell-shrinking.php @@ -3,14 +3,13 @@ /** * Pdf Advanced Multicell - Example */ - $factory = new DevFactory(); // Create the Advanced Multicell Object and inject the PDF object $multicell = $factory->multicell(); $pdf = $multicell->getPdfObject(); -$txt = <<TCPDF addon allows creation of an Advanced Multicell which uses as input a TAG based formatted string instead of a simple string. The use of tags allows to change the font, the style (bold, italic, underline), the size, and the color of characters and many other features.

Features:

@@ -50,7 +49,7 @@ // //$pdf->AddPage(); -$txt = <<maxHeight(100)->shrinkToFit(); $multicell->multiCell(0, 5, $txt, 1, 'J', 1, 3, 3, 3, 3); //$multicell->maxLines(3)->shrinkToFit(); -$txt = <<TCPDF addon allows creation of an Advanced Multicell which uses as input a TAG based formatted string instead of a simple string. The use of tags allows to change the font, the style (bold, italic, underline), the size, and the color of characters and many other features. EOL; diff --git a/dev/dev-multicell-shrinking4.php b/dev/dev-multicell-shrinking4.php index 90d13aa..cd37377 100644 --- a/dev/dev-multicell-shrinking4.php +++ b/dev/dev-multicell-shrinking4.php @@ -21,7 +21,7 @@ //$multicell->maxLines(3)->shrinkToFit(); -$txt = <<TCPDF addon allows creation of an Advanced Multicell which uses as input a TAG based formatted string instead of a simple string. The use of tags allows to change the font, the style (bold, italic, underline), the size, and the color of characters and many other features.

Features:

diff --git a/dev/dev-multicell-style-inheritance.php b/dev/dev-multicell-style-inheritance.php index 54a8913..274d4fa 100644 --- a/dev/dev-multicell-style-inheritance.php +++ b/dev/dev-multicell-style-inheritance.php @@ -3,7 +3,6 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/../autoload.php'; use EvoSys21\PdfLib\Fpdf\Pdf; @@ -24,7 +23,6 @@ // add a page $pdf->AddPage(); - // Create the Advanced Multicell Object and inject the PDF object $multicell = new Multicell($pdf); diff --git a/dev/dev-multicell-style-inheritance1.php b/dev/dev-multicell-style-inheritance1.php index 21fbab3..a744fe8 100644 --- a/dev/dev-multicell-style-inheritance1.php +++ b/dev/dev-multicell-style-inheritance1.php @@ -3,7 +3,6 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/../autoload.php'; use EvoSys21\PdfLib\Fpdf\Pdf; @@ -24,7 +23,6 @@ // add a page $pdf->AddPage(); - // Create the Advanced Multicell Object and inject the PDF object $multicell = new Multicell($pdf); diff --git a/dev/dev-multicell-style.php b/dev/dev-multicell-style.php index ab7086b..903ce83 100644 --- a/dev/dev-multicell-style.php +++ b/dev/dev-multicell-style.php @@ -12,7 +12,7 @@ $multicell = $factory->multicell(); $pdf = $multicell->getPdfObject(); -$txt = << <?php
/**
 * Pdf Advanced Multicell - Example
diff --git a/dev/dev-multicell-style1.php b/dev/dev-multicell-style1.php index 3cefc56..17a6228 100644 --- a/dev/dev-multicell-style1.php +++ b/dev/dev-multicell-style1.php @@ -12,7 +12,7 @@ $multicell = $factory->multicell(); $pdf = $multicell->getPdfObject(); -$txt = << <?php
/**
 * Pdf Advanced Multicell - Example
diff --git a/dev/example-multicell-dev.php b/dev/example-multicell-dev.php index 4be84be..e852174 100644 --- a/dev/example-multicell-dev.php +++ b/dev/example-multicell-dev.php @@ -3,7 +3,6 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/../autoload.php'; use EvoSys21\PdfLib\Fpdf\Pdf; @@ -24,7 +23,6 @@ // add a page $pdf->AddPage(); - // Create the Advanced Multicell Object and inject the PDF object $multicell = new Multicell($pdf); @@ -67,7 +65,7 @@ //$pdf->ln(10); $s = "The price is USD 5.344,23"; -$s1 = "The price is USD 5.344,23"; +$s1 = 'The price is USD 5.344,23'; foreach ([40, 45, 50] as $width) { $multicell->multiCell($width, 5, $s, 0, 'L'); $multicell->multiCell($width, 5, $s1, 0, 'L'); @@ -91,6 +89,5 @@ //

xxx

- Paragraph 2"; //$multicell->multiCell(0, 5, $s); - // output the pdf $pdf->Output(); diff --git a/dev/example-table-dev.php b/dev/example-table-dev.php index 389c65b..fbbc8ba 100644 --- a/dev/example-table-dev.php +++ b/dev/example-table-dev.php @@ -3,7 +3,6 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/../autoload.php'; use EvoSys21\PdfLib\Fpdf\Pdf; @@ -52,7 +51,7 @@ 'I am cell 2', [ 'TEXT' => 'I am cell 3', - 'TEXT_ALIGN' => 'R' + 'TEXT_ALIGN' => 'R', ], ]; @@ -64,7 +63,7 @@ 'I am cell 2', [ 'TEXT' => 'I am cell 3', - 'TEXT_ALIGN' => 'R' + 'TEXT_ALIGN' => 'R', ], ]; @@ -74,7 +73,7 @@ $row = [ new Image($pdf, CONTENT_PATH . '/images/blog.jpg', 10), "

Images are supported\n

", - new Image($pdf, CONTENT_PATH . '/images/telescope.jpg', 35, 35) + new Image($pdf, CONTENT_PATH . '/images/telescope.jpg', 35, 35), ]; //add the row to the table @@ -88,7 +87,7 @@ 'FILE' => CONTENT_PATH . '/images/telescope.jpg', 'WIDTH' => 35, 'HEIGHT' => 35, - ] + ], ]; //add the data row @@ -98,8 +97,8 @@ 'TEXT' => 'some text', 'PADDING_TOP' => 0, 'PADDING_BOTTOM' => 0, - 'LINE_SIZE' => 42.3 -],[ + 'LINE_SIZE' => 42.3, +], [ 'PADDING_TOP' => 0, 'PADDING_BOTTOM' => 0, 'TEXT' => '

Second Column

', @@ -110,12 +109,11 @@ $row = [[ 'TEXT' => 'some text', 'PADDING_TOP' => 0, - 'LINE_SIZE' => 20 + 'LINE_SIZE' => 20, ]]; //add the data row $table->addRow($row); - $table->close(); $pdf->output(); diff --git a/dev/example-table-dev1.php b/dev/example-table-dev1.php index 2ea24c4..80ed169 100644 --- a/dev/example-table-dev1.php +++ b/dev/example-table-dev1.php @@ -3,7 +3,6 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/../autoload.php'; use EvoSys21\PdfLib\Fpdf\Pdf; @@ -51,7 +50,7 @@ 'I am cell 2', [ 'TEXT' => 'I am cell 3', - 'TEXT_ALIGN' => 'R' + 'TEXT_ALIGN' => 'R', ], ]; @@ -69,7 +68,7 @@ //$table->addPageBreak(); -$row = [[ 'TEXT' => "Cell\nCell\nCell\nCell\nCell\nCell\nCell\nCell\nCell\nCell\n", 'HEIGHT' => 60, 'PADDING_TOP' => 20]]; +$row = [['TEXT' => "Cell\nCell\nCell\nCell\nCell\nCell\nCell\nCell\nCell\nCell\n", 'HEIGHT' => 60, 'PADDING_TOP' => 20]]; $table->addRow($row); diff --git a/dev/samples/sample-test-code.php b/dev/samples/sample-test-code.php index 0354679..af7898a 100644 --- a/dev/samples/sample-test-code.php +++ b/dev/samples/sample-test-code.php @@ -3,7 +3,6 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/../autoload.php'; //get the PDF object diff --git a/dev/table/disable-page-break.php b/dev/table/disable-page-break.php index e70d5e1..395fcca 100644 --- a/dev/table/disable-page-break.php +++ b/dev/table/disable-page-break.php @@ -2,7 +2,7 @@ use EvoSys21\PdfLib\Table; -if (!isset($splitMode)) { +if (! isset($splitMode)) { $splitMode = true; } @@ -33,7 +33,7 @@ //Table Header for ($i = 0; $i < $columns; $i++) { - $header[$i]['TEXT'] = "Header #" . ($i + 1); + $header[$i]['TEXT'] = 'Header #' . ($i + 1); } $header1 = $header; @@ -47,10 +47,10 @@ $table->addHeader($header); $table->addHeader($header1); -$sDefaultText = "Lorem ipsum;, dolor sit amet"; +$sDefaultText = 'Lorem ipsum;, dolor sit amet'; $sDefaultText2 = "

Some Line

\nSome text"; -$sDefaultLongText = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; -$sDefaultLongText2 = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur"; +$sDefaultLongText = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'; +$sDefaultLongText2 = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur'; $aDefaultRow = []; for ($i = 0; $i < $columns; $i++) { diff --git a/dev/table/draw-table-model1.php b/dev/table/draw-table-model1.php index 5f73cdb..e4392e2 100644 --- a/dev/table/draw-table-model1.php +++ b/dev/table/draw-table-model1.php @@ -4,7 +4,7 @@ global $pdf; -if (!isset($splitMode)) { +if (! isset($splitMode)) { $splitMode = true; } @@ -35,7 +35,7 @@ //Table Header for ($i = 0; $i < $columns; $i++) { - $header[$i]['TEXT'] = "Header #" . ($i + 1); + $header[$i]['TEXT'] = 'Header #' . ($i + 1); } $header1 = $header; @@ -49,10 +49,10 @@ $table->addHeader($header); $table->addHeader($header1); -$sDefaultText = "Lorem ipsum;, dolor sit amet"; +$sDefaultText = 'Lorem ipsum;, dolor sit amet'; $sDefaultText2 = "

Some Line

\nSome text"; -$sDefaultLongText = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; -$sDefaultLongText2 = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur"; +$sDefaultLongText = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'; +$sDefaultLongText2 = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur'; $aDefaultRow = []; for ($i = 0; $i < $columns; $i++) { diff --git a/dev/table/draw-table-model2.php b/dev/table/draw-table-model2.php index 35044d8..e904a2b 100644 --- a/dev/table/draw-table-model2.php +++ b/dev/table/draw-table-model2.php @@ -2,7 +2,7 @@ use EvoSys21\PdfLib\Table; -if (!isset($splitMode)) { +if (! isset($splitMode)) { $splitMode = true; } @@ -33,7 +33,7 @@ //Table Header for ($i = 0; $i < $columns; $i++) { - $header[$i]['TEXT'] = "Header #" . ($i + 1); + $header[$i]['TEXT'] = 'Header #' . ($i + 1); } $header1 = $header; @@ -47,10 +47,10 @@ $table->addHeader($header); $table->addHeader($header1); -$sDefaultText = "Lorem ipsum;, dolor sit amet"; +$sDefaultText = 'Lorem ipsum;, dolor sit amet'; $sDefaultText2 = "

Some Line

\nSome text"; -$sDefaultLongText = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; -$sDefaultLongText2 = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur"; +$sDefaultLongText = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'; +$sDefaultLongText2 = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur'; $aDefaultRow = []; for ($i = 0; $i < $columns; $i++) { diff --git a/dev/test-multicell-align.php b/dev/test-multicell-align.php index 4f4e7e2..118d8b7 100644 --- a/dev/test-multicell-align.php +++ b/dev/test-multicell-align.php @@ -9,9 +9,9 @@ $multicell = $factory->multicell(); $pdf = $multicell->getPdfObject(); -$short = "Lorem ipsum dolor sit amet"; +$short = 'Lorem ipsum dolor sit amet'; -$txt = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; +$txt = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'; foreach (range(5, 0) as $key => $padding) { if ($key) { diff --git a/dev/test-multicell-disable-pagebreak.php b/dev/test-multicell-disable-pagebreak.php index 1038d5e..85cd86b 100644 --- a/dev/test-multicell-disable-pagebreak.php +++ b/dev/test-multicell-disable-pagebreak.php @@ -9,7 +9,7 @@ $multicell = $factory->multicell(); $pdf = $multicell->getPdfObject(); -$txt = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; +$txt = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'; $pdf->AutoPageBreak = false; $multicell->disablePageBreak(); diff --git a/dev/test-multicell-min-height.php b/dev/test-multicell-min-height.php index 82451fa..e9b9c88 100644 --- a/dev/test-multicell-min-height.php +++ b/dev/test-multicell-min-height.php @@ -9,7 +9,7 @@ $multicell = $factory->multicell(); $pdf = $multicell->getPdfObject(); -$txt = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; +$txt = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'; $multicell->multiCell(100, 5, $txt, 1, 'J', 1, 3, 3, 3, 3, 50); diff --git a/dev/test-multicell-shrinking.php b/dev/test-multicell-shrinking.php index 28bcf6b..8dc3324 100644 --- a/dev/test-multicell-shrinking.php +++ b/dev/test-multicell-shrinking.php @@ -9,8 +9,7 @@ $multicell = $factory->multicell(); $pdf = $multicell->getPdfObject(); - -$txt = <<TCPDF addon allows creation of an Advanced Multicell which uses as input a TAG based formatted string instead of a simple string. The use of tags allows to change the font, the style (bold, italic, underline), the size, and the color of characters and many other features.

Features:

@@ -50,7 +49,7 @@ $pdf->AddPage(); -$txt = <<multicell(); $pdf = $multicell->getPdfObject(); - -$txt = <<TCPDF addon allows creation of an Advanced Multicell which uses as input a TAG based formatted string instead of a simple string. The use of tags allows to change the font, the style (bold, italic, underline), the size, and the color of characters and many other features.

Features:

diff --git a/dev/test-multicell-style.php b/dev/test-multicell-style.php index 4b4a94d..a55757a 100644 --- a/dev/test-multicell-style.php +++ b/dev/test-multicell-style.php @@ -10,8 +10,7 @@ $multicell = $factory->multicell(); $pdf = $multicell->getPdfObject(); - -$txt = <<More text Initial text More text EOL; diff --git a/examples/Fpdf/MyPdf.php b/examples/Fpdf/MyPdf.php index 2a62803..71b9be5 100644 --- a/examples/Fpdf/MyPdf.php +++ b/examples/Fpdf/MyPdf.php @@ -26,7 +26,7 @@ class MyPdf extends Pdf */ public function Header() { - if (!$this->showHeader) { + if (! $this->showHeader) { return; } @@ -58,7 +58,6 @@ public function Header() $this->SetY($this->tMargin); } - /** * Custom Footer * @@ -68,7 +67,7 @@ public function Footer() { $this->drawMargins && $this->drawMarginLines(); - if (!$this->showFooter) { + if (! $this->showFooter) { return; } @@ -80,8 +79,6 @@ public function Footer() /** * Returns the default Font to be used - * - * @return string */ public function getDefaultFont(): string { @@ -106,7 +103,6 @@ public function drawMarginLines(): void $this->Line($this->w - $this->rMargin, 0, $this->w - $this->rMargin, $this->h); } - /** * Disable the Producer and CreationDate. It breaks the functional unit-testing(date always changes) * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore @@ -126,16 +122,16 @@ public function _putinfo() protected static function isTesting(): bool { - return (getenv('APP_ENV') === 'testing'); + return getenv('APP_ENV') === 'testing'; } /** - * @param string $headerSource * @return $this */ public function setHeaderSource(string $headerSource): self { $this->headerSource = $headerSource; + return $this; } } diff --git a/examples/Fpdf/PdfFactory.php b/examples/Fpdf/PdfFactory.php index cf9200c..0cb62e4 100644 --- a/examples/Fpdf/PdfFactory.php +++ b/examples/Fpdf/PdfFactory.php @@ -15,10 +15,8 @@ class PdfFactory /** * Creates a new PDF Object and Initializes it * - * @param string $type * @param bool $header Show the header * @param bool $footer Show the footer - * @return MyPdf */ public static function newPdf(string $type, bool $header = true, bool $footer = true): MyPdf { @@ -43,9 +41,6 @@ public static function newPdf(string $type, bool $header = true, bool $footer = * Initializes the pdf object. * Set the margins, adds a page, adds default fonts etc... * - * @param Pdf $pdf - * @param bool $header - * @param bool $footer * @return Pdf $pdf */ public static function initPdf(Pdf $pdf, bool $header = true, bool $footer = true): Pdf diff --git a/examples/Fpdf/PdfSettings.php b/examples/Fpdf/PdfSettings.php index a7750aa..f449995 100644 --- a/examples/Fpdf/PdfSettings.php +++ b/examples/Fpdf/PdfSettings.php @@ -7,7 +7,7 @@ use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Table; -if (!defined('__DIR__')) { +if (! defined('__DIR__')) { define('__DIR__', __DIR__ . '/../../..'); } @@ -20,10 +20,9 @@ class PdfSettings [86, 155, 225], [207, 247, 239], [246, 211, 207], - [216, 243, 228] + [216, 243, 228], ]; - //top, right, bottom, left public static $paddings = [ [0, 0, 0, 0], @@ -43,28 +42,26 @@ class PdfSettings [5, 5, 5, 0], [0, 5, 5, 5], [5, 0, 5, 5], - [5, 5, 0, 5] + [5, 5, 0, 5], ]; - public static $alignments = ['TL', 'TC', 'TR', 'ML', 'MC', 'MR', 'BL', 'BC', 'BR']; - - public static $textShort = "Hello world!"; - public static $text = "Lorem ipsum dolor sit amet..."; + public static $textShort = 'Hello world!'; + public static $text = 'Lorem ipsum dolor sit amet...'; public static $text2 = "

Simple text\nBold text

"; - public static $textLong = "

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

"; - public static $textExtraLong = "

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur

"; + public static $textLong = '

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

'; + public static $textExtraLong = '

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur

'; public static $textSubSuperscript = "Subscript or Superscript"; public static $columns = 5; //prepare some default row settings - public static array $imageCell = array( + public static array $imageCell = [ 'TYPE' => 'IMAGE', 'FILE' => CONTENT_PATH . '/images/dice.jpg', - 'WIDTH' => 10 - ); + 'WIDTH' => 10, + ]; public static function headerRow(): array { @@ -72,6 +69,7 @@ public static function headerRow(): array for ($i = 0; $i < static::$columns; $i++) { $headerRow[$i]['TEXT'] = "Header #$i"; } + return $headerRow; } @@ -79,12 +77,12 @@ public static function dataRow(): array { $dataRow = []; for ($i = 0; $i < static::$columns; $i++) { - $dataRow[$i]['TEXT'] = "Cool cell"; + $dataRow[$i]['TEXT'] = 'Cool cell'; } + return $dataRow; } - /** * Set the styles for the advanced multicell * @@ -111,11 +109,8 @@ public static function setMulticellStyles(Multicell $multicell) $multicell->setStyle('code', 9, '', null, 'courier'); } - /** * Set the styles for the advanced table - * - * @param Table $table */ public static function setTableStyles(Table $table) { diff --git a/examples/Fpdf/example-multicell-1-overview.php b/examples/Fpdf/example-multicell-1-overview.php index c6ce62c..259bca1 100644 --- a/examples/Fpdf/example-multicell-1-overview.php +++ b/examples/Fpdf/example-multicell-1-overview.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Fpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Fpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); diff --git a/examples/Fpdf/example-multicell-2-overview-page-break.php b/examples/Fpdf/example-multicell-2-overview-page-break.php index 0e4258f..a98bae9 100644 --- a/examples/Fpdf/example-multicell-2-overview-page-break.php +++ b/examples/Fpdf/example-multicell-2-overview-page-break.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Fpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Fpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); @@ -27,7 +26,6 @@ $pdf->Ln(10); //line break - //read TAG formatted text from file $txt = file_get_contents(CONTENT_PATH . '/multicell.txt'); $s = $txt . "\n\n\n\nRepeat the text to trigger a page break \n\n\n" . $txt; diff --git a/examples/Fpdf/example-multicell-3-line-breaking.php b/examples/Fpdf/example-multicell-3-line-breaking.php index 8b9ee23..8befb31 100644 --- a/examples/Fpdf/example-multicell-3-line-breaking.php +++ b/examples/Fpdf/example-multicell-3-line-breaking.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Fpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Fpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); @@ -26,20 +25,17 @@ $multicell->multiCell(100, 5, $txt, 1, 'R', 0, 0, 1); $pdf->Ln(10); //new line - //create an advanced multicell $multicell->multiCell(0, 5, 'Setting > as line breaking character'); $multicell->setLineBreakingCharacters('>'); $multicell->multiCell(100, 5, $txt, 1); $pdf->Ln(10); //new line - //create an advanced multicell $multicell->multiCell(0, 5, 'Reseting the line breaking characters'); $multicell->resetLineBreakingCharacters(); $multicell->multiCell(100, 5, $txt, 1); $pdf->Ln(10); //new line - //send the pdf to the browser $pdf->Output(); diff --git a/examples/Fpdf/example-multicell-4-page-break.php b/examples/Fpdf/example-multicell-4-page-break.php index 29b4629..e035dae 100644 --- a/examples/Fpdf/example-multicell-4-page-break.php +++ b/examples/Fpdf/example-multicell-4-page-break.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Fpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Fpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); diff --git a/examples/Fpdf/example-multicell-5-max-lines.php b/examples/Fpdf/example-multicell-5-max-lines.php index e3afdc5..6c1313c 100644 --- a/examples/Fpdf/example-multicell-5-max-lines.php +++ b/examples/Fpdf/example-multicell-5-max-lines.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Fpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Fpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); diff --git a/examples/Fpdf/example-multicell-6-shrinking.php b/examples/Fpdf/example-multicell-6-shrinking.php index ded65b3..87065d1 100644 --- a/examples/Fpdf/example-multicell-6-shrinking.php +++ b/examples/Fpdf/example-multicell-6-shrinking.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Fpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Fpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); @@ -20,10 +19,10 @@ PdfSettings::setMulticellStyles($multicell); $pdf->Ln(5); //line break -$multicell->multiCell(120, 5, "

Multicell text shrinking feature

"); +$multicell->multiCell(120, 5, '

Multicell text shrinking feature

'); $pdf->Ln(10); //line break -$txt = <<TCPDF addon allows creation of an Advanced Multicell which uses as input a TAG based formatted string instead of a simple string. The use of tags allows to change the font, the style (bold, italic, underline), the size, and the color of characters and many other features.

Features:

@@ -52,7 +51,7 @@ $pdf->AddPage(); -$txt = <<setStyle('h4', 11, null, null, null, 'h'); $multicell->setStyle('super', 8, null, [255, 102, 153]); -$s = <<This line is a paragraph line

@@ -68,7 +67,7 @@ $pdf->ln(10); -$s = <<Typography:

Heading 1

@@ -81,9 +80,9 @@ $pdf->ln(10); -$multicell->multiCell(0, 10, "Table of Content:"); +$multicell->multiCell(0, 10, 'Table of Content:'); -$s = <<

- Paragraph 1

- Paragraph 2

- Paragraph 2.1

@@ -93,9 +92,9 @@ $multicell->multiCell(0, 5, $s); $pdf->ln(10); -$multicell->multiCell(0, 10, "Tag width and alignment:"); +$multicell->multiCell(0, 10, 'Tag width and alignment:'); -$s = << Align Left

Align Center

Align Right

@@ -103,7 +102,7 @@ $multicell->multiCell(100, 5, $s, 1, '', 1); $pdf->AddPage(); -$multicell->multiCell(0, 10, "No wrap: text will not break on normal separators"); +$multicell->multiCell(0, 10, 'No wrap: text will not break on normal separators'); $s = "The price is USD 5.344,23"; foreach ([40, 45, 50] as $width) { diff --git a/examples/Fpdf/example-table-1-overview.php b/examples/Fpdf/example-table-1-overview.php index d319f58..0d7c734 100644 --- a/examples/Fpdf/example-table-1-overview.php +++ b/examples/Fpdf/example-table-1-overview.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Fpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Fpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('table'); @@ -21,28 +20,27 @@ //simple table $multicell->multiCell(0, 5, "

~~~Simple table:

"); -require(__DIR__ . '/table/code-example1.php'); +require __DIR__ . '/table/code-example1.php'; //cells can be multicells and images $pdf->Ln(10); $multicell->multiCell(0, 5, "

~~~Cells can be advanced multicells and images:

"); -require(__DIR__ . '/table/code-example2.php'); +require __DIR__ . '/table/code-example2.php'; //example - Multiple header rows, rowspans, colspans $pdf->Ln(10); $multicell->multiCell(0, 5, "

~~~Multiple header rows, rowspans, colspans:

"); -require(__DIR__ . '/table/code-example3.php'); +require __DIR__ . '/table/code-example3.php'; //example - Transparent background $pdf->Ln(10); $multicell->multiCell(0, 5, "

~~~ Transparent Background:

"); -require(__DIR__ . '/table/code-example-transparent.php'); - +require __DIR__ . '/table/code-example-transparent.php'; //example - all parameters can be overwritten $pdf->Ln(10); $multicell->multiCell(0, 5, "

~~~Different alignments:

"); -require(__DIR__ . '/table/code-example-alignments.php'); +require __DIR__ . '/table/code-example-alignments.php'; //send the pdf to the browser $pdf->Output(); diff --git a/examples/Fpdf/example-table-2-overview.php b/examples/Fpdf/example-table-2-overview.php index f0ab384..a371b93 100644 --- a/examples/Fpdf/example-table-2-overview.php +++ b/examples/Fpdf/example-table-2-overview.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Table; use EvoSys21\PdfLib\Examples\Fpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Fpdf\PdfSettings; +use EvoSys21\PdfLib\Table; //get the PDF object $pdf = PdfFactory::newPdf('table'); @@ -32,7 +31,7 @@ //Initialize the table, 5 columns with the specified widths $table->initialize([35, 30, 40, 40, 25], [ - 'TABLE' => ['TABLE_LEFT_MARGIN' => 0] + 'TABLE' => ['TABLE_LEFT_MARGIN' => 0], ]); $header = [ @@ -40,7 +39,7 @@ ['TEXT' => 'Header 2'], ['TEXT' => 'Header 3'], ['TEXT' => 'Header 4'], - ['TEXT' => 'Header 5'] + ['TEXT' => 'Header 5'], ]; //add the header line @@ -73,7 +72,7 @@ $row[1]['TEXT'] = "Test Text Column 1- $j"; $row[1]['TEXT_SIZE'] = 13 - $fsize; $row[2]['TEXT'] = "Test Text Column 2- $j"; - $row[3]['TEXT'] = "Longer text, this will split sometimes..."; + $row[3]['TEXT'] = 'Longer text, this will split sometimes...'; $row[3]['TEXT_SIZE'] = 15 - $fsize; $row[4]['TEXT'] = "Short 4- $j"; $row[4]['TEXT_SIZE'] = 7; @@ -84,31 +83,31 @@ $row[1]['ALIGN'] = 'C'; $row[1]['LINE_SIZE'] = 5; } elseif ($j == 1) { - $row[0]['TEXT'] = "Top Right Align

Align Top

Right Right Align"; + $row[0]['TEXT'] = 'Top Right Align

Align Top

Right Right Align'; $row[0]['ALIGN'] = 'RT'; - $row[1]['TEXT'] = "Middle Center Align Bold Italic"; + $row[1]['TEXT'] = 'Middle Center Align Bold Italic'; $row[1]['TEXT_TYPE'] = 'BI'; $row[1]['ALIGN'] = 'MC'; $row[2]['TEXT'] = "\n\n\n\n\nBottom Left Align"; $row[2]['ALIGN'] = 'BL'; - $row[3]['TEXT'] = "Middle Justified Align Longer text"; + $row[3]['TEXT'] = 'Middle Justified Align Longer text'; $row[3]['ALIGN'] = 'MJ'; - $row[4]['TEXT'] = "TOP RIGHT Align with top padding(5)"; + $row[4]['TEXT'] = 'TOP RIGHT Align with top padding(5)'; $row[4]['ALIGN'] = 'TR'; $row[4]['PADDING_TOP'] = 5; } if ($j == 2) { - $row[1]['TEXT'] = "Cells can be images -->>>"; - $row[2] = array( + $row[1]['TEXT'] = 'Cells can be images -->>>'; + $row[2] = [ 'TYPE' => 'IMAGE', 'FILE' => CONTENT_PATH . '/images/dice.jpg', - 'WIDTH' => 15 - ); + 'WIDTH' => 15, + ]; } if ($j > 0) { @@ -117,7 +116,7 @@ } if ($j > 3 and $j < 7) { - $row[1]['TEXT'] = "Colspan Example - Center Align"; + $row[1]['TEXT'] = 'Colspan Example - Center Align'; $row[1]['COLSPAN'] = $colspan; $row[1]['BACKGROUND_COLOR'] = [$rgb_b, 50, 50]; $row[1]['TEXT_COLOR'] = [255, 255, $rgb_g]; @@ -129,19 +128,19 @@ } if ($j == 7) { - $row[3]['TEXT'] = "Rowspan Example"; + $row[3]['TEXT'] = 'Rowspan Example'; $row[3]['BACKGROUND_COLOR'] = [$rgb_b, $rgb_b, 250]; $row[3]['ROWSPAN'] = 4; } if ($j == 8) { - $row[1]['TEXT'] = "Rowspan Example"; + $row[1]['TEXT'] = 'Rowspan Example'; $row[1]['BACKGROUND_COLOR'] = [$rgb_b, 50, 50]; $row[1]['ROWSPAN'] = 6; } if ($j == 9) { - $row[2]['TEXT'] = "Rowspan Example"; + $row[2]['TEXT'] = 'Rowspan Example'; $row[2]['BACKGROUND_COLOR'] = [$rgb_r, $rgb_r, $rgb_r]; $row[2]['ROWSPAN'] = 3; } diff --git a/examples/Fpdf/example-table-3-detailed.php b/examples/Fpdf/example-table-3-detailed.php index 88f938f..54c6cd9 100644 --- a/examples/Fpdf/example-table-3-detailed.php +++ b/examples/Fpdf/example-table-3-detailed.php @@ -3,13 +3,12 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; -use EvoSys21\PdfLib\Table; use EvoSys21\PdfLib\Examples\Fpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Fpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; +use EvoSys21\PdfLib\Table; //get the PDF object $pdf = PdfFactory::newPdf('table'); @@ -34,7 +33,6 @@ // Set the styles for the advanced table PdfSettings::setTableStyles($table); - //default text color $pdf->SetTextColor(118, 0, 3); @@ -43,10 +41,10 @@ $multicell->setStyle('s1', 8, '', '118,0,3', 'helvetica'); $multicell->setStyle('s2', 6, '', '0,49,159', 'helvetica'); -$multicell->multiCell(100, 4, "Example 1 - Very Simple Table"); +$multicell->multiCell(100, 4, 'Example 1 - Very Simple Table'); $pdf->Ln(1); -require('table_example1.php'); +require 'table_example1.php'; $pdf->Ln(10); @@ -55,7 +53,7 @@ $pdf->SetX(60); $multicell->multiCell(100, 2.5, $txt); $pdf->Ln(1); -require('table_example2.php'); +require 'table_example2.php'; $pdf->Ln(10); @@ -65,7 +63,7 @@ $multicell->multiCell(100, 2.5, $txt); $pdf->Ln(1); $tableSplitMode = true; -require('table_example2.php'); +require 'table_example2.php'; $pdf->Ln(10); @@ -75,7 +73,7 @@ $multicell->multiCell(100, 2.5, $txt); $pdf->Ln(1); $tableSplitMode = false; -require('table_example2.php'); +require 'table_example2.php'; //send the pdf to the browser $pdf->Output(); diff --git a/examples/Fpdf/example-table-4-override.php b/examples/Fpdf/example-table-4-override.php index 118593a..ba774cc 100644 --- a/examples/Fpdf/example-table-4-override.php +++ b/examples/Fpdf/example-table-4-override.php @@ -3,13 +3,12 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; -use EvoSys21\PdfLib\Table; use EvoSys21\PdfLib\Examples\Fpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Fpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; +use EvoSys21\PdfLib\Table; //get the PDF object $pdf = PdfFactory::newPdf('table'); @@ -31,18 +30,18 @@ $multicell = Multicell::getInstance($pdf); PdfSettings::setMulticellStyles($multicell); -$multicell->multiCell(100, 4, "Example - Override Default Configuration Values"); +$multicell->multiCell(100, 4, 'Example - Override Default Configuration Values'); $columns = 3; -$config = array( - 'TABLE' => array( +$config = [ + 'TABLE' => [ 'TABLE_ALIGN' => 'L', //left align 'BORDER_COLOR' => [0, 0, 0], //border color 'BORDER_SIZE' => '0.5', //border size - ), + ], - 'HEADER' => array( + 'HEADER' => [ 'TEXT_COLOR' => [25, 60, 170], //text color 'TEXT_SIZE' => 9, //font size 'LINE_SIZE' => 6, //line size for one row @@ -50,15 +49,15 @@ 'BORDER_SIZE' => 0.5, //border size 'BORDER_TYPE' => 'B', //border type, can be: 0, 1 or a combination of: 'LRTB' 'BORDER_COLOR' => [0, 0, 0], //border color - ), + ], - 'ROW' => array( + 'ROW' => [ 'TEXT_COLOR' => [225, 20, 0], //text color 'TEXT_SIZE' => 6, //font size 'BACKGROUND_COLOR' => [232, 255, 209], //background color 'BORDER_COLOR' => [150, 255, 56], //border color - ), -); + ], +]; //Initialize the table, 3 columns $table->initialize([40, 50, 30], $config); @@ -67,7 +66,7 @@ //Table Header for ($i = 0; $i < $columns; $i++) { - $header[$i]['TEXT'] = "Header #" . ($i + 1); + $header[$i]['TEXT'] = 'Header #' . ($i + 1); } //add the header @@ -79,11 +78,10 @@ $row[1]['TEXT'] = "Line $j Text 2"; //text for column 1 $row[2]['TEXT'] = "Line $j Text 3"; //text for column 2 - //override some settings for row 2 if (2 == $j) { $row[1]['TEXT_ALIGN'] = 'L'; - $row[1]['TEXT'] = "

This is a Multicell

"; + $row[1]['TEXT'] = '

This is a Multicell

'; } //add the row diff --git a/examples/Fpdf/example-table-5-row-height.php b/examples/Fpdf/example-table-5-row-height.php index 89be4b2..1f37e19 100644 --- a/examples/Fpdf/example-table-5-row-height.php +++ b/examples/Fpdf/example-table-5-row-height.php @@ -3,13 +3,12 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; -use EvoSys21\PdfLib\Table; use EvoSys21\PdfLib\Examples\Fpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Fpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; +use EvoSys21\PdfLib\Table; //get the PDF object $pdf = PdfFactory::newPdf('table'); @@ -31,18 +30,18 @@ $multicell = Multicell::getInstance($pdf); PdfSettings::setMulticellStyles($multicell); -$multicell->multiCell(100, 4, "Example - Override Default Configuration Values"); +$multicell->multiCell(100, 4, 'Example - Override Default Configuration Values'); $columns = 3; -$config = array( - 'TABLE' => array( +$config = [ + 'TABLE' => [ 'TABLE_ALIGN' => 'L', //left align 'BORDER_COLOR' => [0, 0, 0], //border color 'BORDER_SIZE' => '0.5', //border size - ), + ], - 'HEADER' => array( + 'HEADER' => [ 'TEXT_COLOR' => [25, 60, 170], //text color 'TEXT_SIZE' => 9, //font size 'LINE_SIZE' => 6, //line size for one row @@ -50,15 +49,15 @@ 'BORDER_SIZE' => 0.5, //border size 'BORDER_TYPE' => 'B', //border type, can be: 0, 1 or a combination of: 'LRTB' 'BORDER_COLOR' => [0, 0, 0], //border color - ), + ], - 'ROW' => array( + 'ROW' => [ 'TEXT_COLOR' => [225, 20, 0], //text color 'TEXT_SIZE' => 6, //font size 'BACKGROUND_COLOR' => [232, 255, 209], //background color 'BORDER_COLOR' => [150, 255, 56], //border color - ), -); + ], +]; //Initialize the table, 3 columns $table->initialize([40, 50, 30], $config); @@ -67,7 +66,7 @@ //Table Header for ($i = 0; $i < $columns; $i++) { - $header[$i]['TEXT'] = "Header #" . ($i + 1); + $header[$i]['TEXT'] = 'Header #' . ($i + 1); } //add the header @@ -79,7 +78,6 @@ $row[1]['TEXT'] = "Line $j Text 2"; //text for column 1 $row[2]['TEXT'] = "Line $j Text 3"; //text for column 2 - //override some settings for row 2 if (2 == $j) { $row[1]['TEXT_ALIGN'] = 'L'; diff --git a/examples/Fpdf/table/code-example-alignments.php b/examples/Fpdf/table/code-example-alignments.php index 90ee505..0fad97a 100644 --- a/examples/Fpdf/table/code-example-alignments.php +++ b/examples/Fpdf/table/code-example-alignments.php @@ -1,11 +1,11 @@ initialize([20, 30, 40, 50]); $table->addHeader(PdfSettings::headerRow()); @@ -53,7 +52,6 @@ $row[3]['ALIGN'] = Tools::getNextValue(PdfSettings::$alignments, $k); } - $table->addRow($row); } diff --git a/examples/Fpdf/table/code-example-transparent.php b/examples/Fpdf/table/code-example-transparent.php index 4547e4a..a70e17a 100644 --- a/examples/Fpdf/table/code-example-transparent.php +++ b/examples/Fpdf/table/code-example-transparent.php @@ -1,18 +1,18 @@ GetY(); $pdf->SetX(50); -$pdf->Image(CONTENT_PATH . "/images/sample-pdf.jpg"); +$pdf->Image(CONTENT_PATH . '/images/sample-pdf.jpg'); $pdf->SetY($y); @@ -27,31 +27,29 @@ /** * Set the tag styles */ - $table->initialize([20, 30, 80]); -$table->setRowConfig(array( - 'BACKGROUND_COLOR' => false -)); - - -$header = array( - array( - 'TEXT' => 'Header #1' - ), - array( - 'TEXT' => 'Header #2' - ), - array( - 'TEXT' => 'Header #3' - ) -); +$table->setRowConfig([ + 'BACKGROUND_COLOR' => false, +]); + +$header = [ + [ + 'TEXT' => 'Header #1', + ], + [ + 'TEXT' => 'Header #2', + ], + [ + 'TEXT' => 'Header #3', + ], +]; //add the header row $table->addHeader($header); //row 1 - add data as Array $row = []; -$row[0]['TEXT'] = "Line 1"; +$row[0]['TEXT'] = 'Line 1'; $row[1] = PdfSettings::$imageCell; @@ -66,7 +64,7 @@ //alternatively you can create directly the cell object $row[0] = new Image($pdf, CONTENT_PATH . '/images/blog.jpg', 10); -$row[1] = new Multicell($pdf, "

This is another Multicell

"); +$row[1] = new Multicell($pdf, '

This is another Multicell

'); $row[2]['TEXT'] = "

All table cells are fully functional Advanced Multicells\nDetails on https://github.com/evosys21/pdflib

"; $row[2]['BACKGROUND_COLOR'] = PdfSettings::$colors[1]; diff --git a/examples/Fpdf/table/code-example1.php b/examples/Fpdf/table/code-example1.php index 1acc788..947e42e 100644 --- a/examples/Fpdf/table/code-example1.php +++ b/examples/Fpdf/table/code-example1.php @@ -1,12 +1,12 @@ initialize([20, 30, 50]); -$header = array( +$header = [ ['TEXT' => 'Header #1'], ['TEXT' => 'Header #2'], ['TEXT' => 'Header #3'], -); +]; //add the header row $table->addHeader($header); @@ -32,7 +32,7 @@ for ($j = 1; $j < 3; $j++) { $row = []; $row[0]['TEXT'] = "Line $j"; - $row[1]['TEXT'] = "Lorem ipsum dolor sit amet..."; + $row[1]['TEXT'] = 'Lorem ipsum dolor sit amet...'; $row[2]['TEXT'] = "

Simple text\nBold text

"; //add the data row diff --git a/examples/Fpdf/table/code-example2.php b/examples/Fpdf/table/code-example2.php index 8cbd925..deca996 100644 --- a/examples/Fpdf/table/code-example2.php +++ b/examples/Fpdf/table/code-example2.php @@ -1,11 +1,11 @@ initialize([20, 30, 80]); $header = [ ['TEXT' => 'Header #1'], ['TEXT' => 'Header #2'], - ['TEXT' => 'Header #3'] + ['TEXT' => 'Header #3'], ]; //add the header row @@ -36,7 +35,7 @@ //row 1 - add data as Array $row = []; -$row[0]['TEXT'] = "Line 1"; +$row[0]['TEXT'] = 'Line 1'; $row[1] = PdfSettings::$imageCell; @@ -51,13 +50,13 @@ //alternatively you can create directly the cell object $row[0] = new Image($pdf, CONTENT_PATH . '/images/blog.jpg', 10); -$row[1] = array( - 'TEXT' => "

This is another Multicell

", - 'BACKGROUND_COLOR' => PdfSettings::$colors[0] -); +$row[1] = [ + 'TEXT' => '

This is another Multicell

', + 'BACKGROUND_COLOR' => PdfSettings::$colors[0], +]; $row[2] = new Image($pdf, CONTENT_PATH . '/images/pencil.jpg', 10); -$row[2]->setAlign("R"); +$row[2]->setAlign('R'); //add the data row $table->addRow($row); diff --git a/examples/Fpdf/table/code-example3.php b/examples/Fpdf/table/code-example3.php index 2def850..2c8620e 100644 --- a/examples/Fpdf/table/code-example3.php +++ b/examples/Fpdf/table/code-example3.php @@ -1,10 +1,10 @@ initialize([20, 30, 40, 50]); $header1 = PdfSettings::headerRow(); @@ -31,7 +30,7 @@ $header2 = PdfSettings::headerRow(); $header3 = PdfSettings::headerRow(); -$header2[1]['TEXT'] = "Colspan/Rowspan in Header"; +$header2[1]['TEXT'] = 'Colspan/Rowspan in Header'; $header2[1]['COLSPAN'] = 2; $header2[1]['ROWSPAN'] = 2; @@ -39,7 +38,6 @@ $table->addHeader($header2); $table->addHeader($header3); - for ($i = 0; $i < 8; $i++) { $row = PdfSettings::dataRow(); @@ -68,7 +66,6 @@ $row[1]['ROWSPAN'] = 2; } - $table->addRow($row); } diff --git a/examples/Fpdf/table_example1.php b/examples/Fpdf/table_example1.php index 4ab6ea3..64b9cd8 100644 --- a/examples/Fpdf/table_example1.php +++ b/examples/Fpdf/table_example1.php @@ -9,7 +9,7 @@ //Table Header for ($i = 0; $i < $columns; $i++) { - $header[$i]['TEXT'] = "Header #" . ($i + 1); + $header[$i]['TEXT'] = 'Header #' . ($i + 1); } //add the header @@ -24,7 +24,6 @@ $row[2]['TEXT'] = "Line $j Text 3"; //text for column 2 $row[2]['TEXT_ALIGN'] = 'R'; //text align - //add the row $table->addRow($row); //break; diff --git a/examples/Fpdf/table_example2.php b/examples/Fpdf/table_example2.php index 78fbae4..db84276 100644 --- a/examples/Fpdf/table_example2.php +++ b/examples/Fpdf/table_example2.php @@ -9,7 +9,7 @@ //Table Header for ($i = 0; $i < $columns; $i++) { - $header[$i]['TEXT'] = "Header #" . ($i + 1); + $header[$i]['TEXT'] = 'Header #' . ($i + 1); } $table->addHeader($header); @@ -56,21 +56,21 @@ } if ($j == 7) { - $row[1]['TEXT'] = "Top Left Align"; + $row[1]['TEXT'] = 'Top Left Align'; $row[1]['VERTICAL_ALIGN'] = 'T'; $row[1]['TEXT_ALIGN'] = 'L'; - $row[2]['TEXT'] = "Bottom Right Align"; + $row[2]['TEXT'] = 'Bottom Right Align'; $row[2]['VERTICAL_ALIGN'] = 'B'; $row[2]['TEXT_ALIGN'] = 'R'; } if ($j == 8) { - $row[1]['TEXT'] = "Top Center Align"; + $row[1]['TEXT'] = 'Top Center Align'; $row[1]['VERTICAL_ALIGN'] = 'T'; $row[1]['TEXT_ALIGN'] = 'C'; - $row[2]['TEXT'] = "Bottom Center Align"; + $row[2]['TEXT'] = 'Bottom Center Align'; $row[2]['VERTICAL_ALIGN'] = 'B'; $row[2]['TEXT_ALIGN'] = 'C'; } @@ -94,7 +94,7 @@ } if ($j == 14) { - $row[1]['TEXT'] = "Cell Properties Overwriting Example"; + $row[1]['TEXT'] = 'Cell Properties Overwriting Example'; $row[1]['TEXT_FONT'] = 'Times'; $row[1]['TEXT_SIZE'] = 7; $row[1]['TEXT_TYPE'] = 'B'; diff --git a/examples/Tcpdf/MyPdf.php b/examples/Tcpdf/MyPdf.php index 78b38a5..0449604 100644 --- a/examples/Tcpdf/MyPdf.php +++ b/examples/Tcpdf/MyPdf.php @@ -4,11 +4,12 @@ namespace EvoSys21\PdfLib\Examples\Tcpdf; -use EvoSys21\PdfLib\Tcpdf\Pdf; use EvoSys21\PdfLib\Multicell; +use EvoSys21\PdfLib\Tcpdf\Pdf; /** * Custom PDF class extension for Header and Footer Definitions + * * @SuppressWarnings(PHPMD.CamelCaseMethodName) * @SuppressWarnings(PHPMD.Superglobals) * phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps @@ -25,7 +26,7 @@ class MyPdf extends Pdf */ public function Header() { - if (!$this->showHeader) { + if (! $this->showHeader) { return; } @@ -57,7 +58,6 @@ public function Header() $this->SetY($this->tMargin); } - /** * Custom Footer * @@ -67,7 +67,7 @@ public function Footer() { $this->drawMargins && $this->drawMarginLines(); - if (!$this->showFooter) { + if (! $this->showFooter) { return; } @@ -79,8 +79,6 @@ public function Footer() /** * Returns the default Font to be used - * - * @return string */ public function getDefaultFont(): string { @@ -105,7 +103,6 @@ public function drawMarginLines(): void $this->Line($this->w - $this->rMargin, 0, $this->w - $this->rMargin, $this->h); } - /** * Disable the Producer and CreationDate. It breaks the functional unit-testing(date always changes) * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore @@ -116,35 +113,36 @@ public function _putinfo() $this->file_id = '1234567890'; $this->tcpdf_version = 'x.x.x'; - if (!empty($this->title)) { + if (! empty($this->title)) { $this->_out('/Title ' . $this->_textstring($this->title)); } - if (!empty($this->subject)) { + if (! empty($this->subject)) { $this->_out('/Subject ' . $this->_textstring($this->subject)); } - if (!empty($this->author)) { + if (! empty($this->author)) { $this->_out('/Author ' . $this->_textstring($this->author)); } - if (!empty($this->keywords)) { + if (! empty($this->keywords)) { $this->_out('/Keywords ' . $this->_textstring($this->keywords)); } - if (!empty($this->creator)) { + if (! empty($this->creator)) { $this->_out('/Creator ' . $this->_textstring($this->creator)); } } + return parent::_putinfo(); } protected function _textstring($s, $n = 0) { $s = static::_testReplace($s); + return parent::_textstring($s, $n); } /** * Static function to replace the TCPDF version in the unit-testing. * - * @param $s * @return string|string[]|null */ protected static function _testReplace($s) @@ -152,11 +150,11 @@ protected static function _testReplace($s) if (static::isTesting()) { $s = preg_replace("/TCPDF \d+\.\d+\.\d+ /", 'TCPDF x.x.x ', $s); } + return $s; } /** - * @param $s * @return void */ public function _out($s) @@ -169,16 +167,16 @@ public function _out($s) protected static function isTesting(): bool { - return (getenv('APP_ENV') === 'testing'); + return getenv('APP_ENV') === 'testing'; } /** - * @param string $headerSource * @return $this */ public function setHeaderSource(string $headerSource): self { $this->headerSource = $headerSource; + return $this; } } diff --git a/examples/Tcpdf/PdfFactory.php b/examples/Tcpdf/PdfFactory.php index 5cb3ee5..66a2caa 100644 --- a/examples/Tcpdf/PdfFactory.php +++ b/examples/Tcpdf/PdfFactory.php @@ -15,10 +15,8 @@ class PdfFactory /** * Creates a new PDF Object and Initializes it * - * @param string $type * @param bool $header Show the header * @param bool $footer Show the footer - * @return MyPdf */ public static function newPdf(string $type, bool $header = true, bool $footer = true): MyPdf { @@ -43,9 +41,6 @@ public static function newPdf(string $type, bool $header = true, bool $footer = * Initializes the pdf object. * Set the margins, adds a page, adds default fonts etc... * - * @param Pdf $pdf - * @param bool $header - * @param bool $footer * @return Pdf $pdf */ public static function initPdf(Pdf $pdf, bool $header = true, bool $footer = true): Pdf diff --git a/examples/Tcpdf/PdfSettings.php b/examples/Tcpdf/PdfSettings.php index 42f07c9..265b655 100644 --- a/examples/Tcpdf/PdfSettings.php +++ b/examples/Tcpdf/PdfSettings.php @@ -7,7 +7,7 @@ use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Table; -if (!defined('__DIR__')) { +if (! defined('__DIR__')) { define('__DIR__', __DIR__ . '/../../..'); } @@ -20,10 +20,9 @@ class PdfSettings [86, 155, 225], [207, 247, 239], [246, 211, 207], - [216, 243, 228] + [216, 243, 228], ]; - //top, right, bottom, left public static $paddings = [ [0, 0, 0, 0], @@ -43,28 +42,26 @@ class PdfSettings [5, 5, 5, 0], [0, 5, 5, 5], [5, 0, 5, 5], - [5, 5, 0, 5] + [5, 5, 0, 5], ]; - public static $alignments = ['TL', 'TC', 'TR', 'ML', 'MC', 'MR', 'BL', 'BC', 'BR']; - - public static $textShort = "Hello world!"; - public static $text = "Lorem ipsum dolor sit amet..."; + public static $textShort = 'Hello world!'; + public static $text = 'Lorem ipsum dolor sit amet...'; public static $text2 = "

Simple text\nBold text

"; - public static $textLong = "

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

"; - public static $textExtraLong = "

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur

"; + public static $textLong = '

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

'; + public static $textExtraLong = '

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur

'; public static $textSubSuperscript = "Subscript or Superscript"; public static $columns = 5; //prepare some default row settings - public static array $imageCell = array( + public static array $imageCell = [ 'TYPE' => 'IMAGE', 'FILE' => CONTENT_PATH . '/images/dice.jpg', - 'WIDTH' => 10 - ); + 'WIDTH' => 10, + ]; public static function headerRow(): array { @@ -72,6 +69,7 @@ public static function headerRow(): array for ($i = 0; $i < static::$columns; $i++) { $headerRow[$i]['TEXT'] = "Header #$i"; } + return $headerRow; } @@ -79,12 +77,12 @@ public static function dataRow(): array { $dataRow = []; for ($i = 0; $i < static::$columns; $i++) { - $dataRow[$i]['TEXT'] = "Cool cell"; + $dataRow[$i]['TEXT'] = 'Cool cell'; } + return $dataRow; } - /** * Set the styles for the advanced multicell * @@ -115,11 +113,8 @@ public static function setMulticellStyles(Multicell $multicell) $multicell->setStyle('u8b', null, 'B', null, null, 'u8'); } - /** * Set the styles for the advanced table - * - * @param Table $table */ public static function setTableStyles(Table $table) { diff --git a/examples/Tcpdf/example-multicell-1-overview.php b/examples/Tcpdf/example-multicell-1-overview.php index 624e86d..8ce9c94 100644 --- a/examples/Tcpdf/example-multicell-1-overview.php +++ b/examples/Tcpdf/example-multicell-1-overview.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Tcpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tcpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); diff --git a/examples/Tcpdf/example-multicell-2-overview-page-break.php b/examples/Tcpdf/example-multicell-2-overview-page-break.php index f811f52..aea3052 100644 --- a/examples/Tcpdf/example-multicell-2-overview-page-break.php +++ b/examples/Tcpdf/example-multicell-2-overview-page-break.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Tcpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tcpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); @@ -27,7 +26,6 @@ $pdf->Ln(10); //line break - //read TAG formatted text from file $txt = file_get_contents(CONTENT_PATH . '/multicell.txt'); $s = $txt . "\n\n\n\nRepeat the text to trigger a page break \n\n\n" . $txt; diff --git a/examples/Tcpdf/example-multicell-3-line-breaking.php b/examples/Tcpdf/example-multicell-3-line-breaking.php index 1996ddb..0051e3c 100644 --- a/examples/Tcpdf/example-multicell-3-line-breaking.php +++ b/examples/Tcpdf/example-multicell-3-line-breaking.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Tcpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tcpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); @@ -26,20 +25,17 @@ $multicell->multiCell(100, 5, $txt, 1, 'R', 0, 0, 1); $pdf->Ln(10); //new line - //create an advanced multicell $multicell->multiCell(0, 5, 'Setting > as line breaking character'); $multicell->setLineBreakingCharacters('>'); $multicell->multiCell(100, 5, $txt, 1); $pdf->Ln(10); //new line - //create an advanced multicell $multicell->multiCell(0, 5, 'Reseting the line breaking characters'); $multicell->resetLineBreakingCharacters(); $multicell->multiCell(100, 5, $txt, 1); $pdf->Ln(10); //new line - //send the pdf to the browser $pdf->Output(); diff --git a/examples/Tcpdf/example-multicell-4-page-break.php b/examples/Tcpdf/example-multicell-4-page-break.php index 5fda260..25ff28a 100644 --- a/examples/Tcpdf/example-multicell-4-page-break.php +++ b/examples/Tcpdf/example-multicell-4-page-break.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Tcpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tcpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); diff --git a/examples/Tcpdf/example-multicell-5-max-lines.php b/examples/Tcpdf/example-multicell-5-max-lines.php index 5288c89..5281be7 100644 --- a/examples/Tcpdf/example-multicell-5-max-lines.php +++ b/examples/Tcpdf/example-multicell-5-max-lines.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Tcpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tcpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); diff --git a/examples/Tcpdf/example-multicell-6-shrinking.php b/examples/Tcpdf/example-multicell-6-shrinking.php index faf6542..49c8d4e 100644 --- a/examples/Tcpdf/example-multicell-6-shrinking.php +++ b/examples/Tcpdf/example-multicell-6-shrinking.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Tcpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tcpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); @@ -20,10 +19,10 @@ PdfSettings::setMulticellStyles($multicell); $pdf->Ln(5); //line break -$multicell->multiCell(120, 5, "

Multicell text shrinking feature

"); +$multicell->multiCell(120, 5, '

Multicell text shrinking feature

'); $pdf->Ln(10); //line break -$txt = <<TCPDF addon allows creation of an Advanced Multicell which uses as input a TAG based formatted string instead of a simple string. The use of tags allows to change the font, the style (bold, italic, underline), the size, and the color of characters and many other features.

Features:

@@ -52,7 +51,7 @@ $pdf->AddPage(); -$txt = <<ln(10); -$s = <<Typography:

Heading 1

@@ -93,9 +92,9 @@ $pdf->ln(10); -$multicell->multiCell(0, 10, "Table of Content:"); +$multicell->multiCell(0, 10, 'Table of Content:'); -$s = <<

- Paragraph 1

- Paragraph 2

- Paragraph 2.1

@@ -105,9 +104,9 @@ $multicell->multiCell(0, 5, $s); $pdf->ln(10); -$multicell->multiCell(0, 10, "Tag width and alignment:"); +$multicell->multiCell(0, 10, 'Tag width and alignment:'); -$s = << Align Left

Align Center

Align Right

@@ -115,7 +114,7 @@ $multicell->multiCell(100, 5, $s, 1, '', 1); $pdf->AddPage(); -$multicell->multiCell(0, 10, "No wrap: text will not break on normal separators"); +$multicell->multiCell(0, 10, 'No wrap: text will not break on normal separators'); $s = "The price is USD 5.344,23"; foreach ([40, 45, 50] as $width) { diff --git a/examples/Tcpdf/example-table-1-overview.php b/examples/Tcpdf/example-table-1-overview.php index 79ba991..10f13ce 100644 --- a/examples/Tcpdf/example-table-1-overview.php +++ b/examples/Tcpdf/example-table-1-overview.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Tcpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tcpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('table'); @@ -21,28 +20,27 @@ //simple table $multicell->multiCell(0, 5, "

~~~Simple table:

"); -require(__DIR__ . '/table/code-example1.php'); +require __DIR__ . '/table/code-example1.php'; //cells can be multicells and images $pdf->Ln(10); $multicell->multiCell(0, 5, "

~~~Cells can be advanced multicells and images:

"); -require(__DIR__ . '/table/code-example2.php'); +require __DIR__ . '/table/code-example2.php'; //example - Multiple header rows, rowspans, colspans $pdf->Ln(10); $multicell->multiCell(0, 5, "

~~~Multiple header rows, rowspans, colspans:

"); -require(__DIR__ . '/table/code-example3.php'); +require __DIR__ . '/table/code-example3.php'; //example - Transparent background $pdf->Ln(10); $multicell->multiCell(0, 5, "

~~~ Transparent Background:

"); -require(__DIR__ . '/table/code-example-transparent.php'); - +require __DIR__ . '/table/code-example-transparent.php'; //example - all parameters can be overwritten $pdf->Ln(10); $multicell->multiCell(0, 5, "

~~~Different alignments:

"); -require(__DIR__ . '/table/code-example-alignments.php'); +require __DIR__ . '/table/code-example-alignments.php'; //send the pdf to the browser $pdf->Output(); diff --git a/examples/Tcpdf/example-table-2-overview.php b/examples/Tcpdf/example-table-2-overview.php index cd89e2b..36047a3 100644 --- a/examples/Tcpdf/example-table-2-overview.php +++ b/examples/Tcpdf/example-table-2-overview.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Table; use EvoSys21\PdfLib\Examples\Tcpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tcpdf\PdfSettings; +use EvoSys21\PdfLib\Table; //get the PDF object $pdf = PdfFactory::newPdf('table'); @@ -32,7 +31,7 @@ //Initialize the table, 5 columns with the specified widths $table->initialize([35, 30, 40, 40, 25], [ - 'TABLE' => ['TABLE_LEFT_MARGIN' => 0] + 'TABLE' => ['TABLE_LEFT_MARGIN' => 0], ]); $header = [ @@ -40,7 +39,7 @@ ['TEXT' => 'Header 2'], ['TEXT' => 'Header 3'], ['TEXT' => 'Header 4'], - ['TEXT' => 'Header 5'] + ['TEXT' => 'Header 5'], ]; //add the header line @@ -73,7 +72,7 @@ $row[1]['TEXT'] = "Test Text Column 1- $j"; $row[1]['TEXT_SIZE'] = 13 - $fsize; $row[2]['TEXT'] = "Test Text Column 2- $j"; - $row[3]['TEXT'] = "Longer text, this will split sometimes..."; + $row[3]['TEXT'] = 'Longer text, this will split sometimes...'; $row[3]['TEXT_SIZE'] = 15 - $fsize; $row[4]['TEXT'] = "Short 4- $j"; $row[4]['TEXT_SIZE'] = 7; @@ -84,31 +83,31 @@ $row[1]['ALIGN'] = 'C'; $row[1]['LINE_SIZE'] = 5; } elseif ($j == 1) { - $row[0]['TEXT'] = "Top Right Align

Align Top

Right Right Align"; + $row[0]['TEXT'] = 'Top Right Align

Align Top

Right Right Align'; $row[0]['ALIGN'] = 'RT'; - $row[1]['TEXT'] = "Middle Center Align Bold Italic"; + $row[1]['TEXT'] = 'Middle Center Align Bold Italic'; $row[1]['TEXT_TYPE'] = 'BI'; $row[1]['ALIGN'] = 'MC'; $row[2]['TEXT'] = "\n\n\n\n\nBottom Left Align"; $row[2]['ALIGN'] = 'BL'; - $row[3]['TEXT'] = "Middle Justified Align Longer text"; + $row[3]['TEXT'] = 'Middle Justified Align Longer text'; $row[3]['ALIGN'] = 'MJ'; - $row[4]['TEXT'] = "TOP RIGHT Align with top padding(5)"; + $row[4]['TEXT'] = 'TOP RIGHT Align with top padding(5)'; $row[4]['ALIGN'] = 'TR'; $row[4]['PADDING_TOP'] = 5; } if ($j == 2) { - $row[1]['TEXT'] = "Cells can be images -->>>"; - $row[2] = array( + $row[1]['TEXT'] = 'Cells can be images -->>>'; + $row[2] = [ 'TYPE' => 'IMAGE', 'FILE' => CONTENT_PATH . '/images/dice.jpg', - 'WIDTH' => 15 - ); + 'WIDTH' => 15, + ]; } if ($j > 0) { @@ -117,7 +116,7 @@ } if ($j > 3 and $j < 7) { - $row[1]['TEXT'] = "Colspan Example - Center Align"; + $row[1]['TEXT'] = 'Colspan Example - Center Align'; $row[1]['COLSPAN'] = $colspan; $row[1]['BACKGROUND_COLOR'] = [$rgb_b, 50, 50]; $row[1]['TEXT_COLOR'] = [255, 255, $rgb_g]; @@ -129,19 +128,19 @@ } if ($j == 7) { - $row[3]['TEXT'] = "Rowspan Example"; + $row[3]['TEXT'] = 'Rowspan Example'; $row[3]['BACKGROUND_COLOR'] = [$rgb_b, $rgb_b, 250]; $row[3]['ROWSPAN'] = 4; } if ($j == 8) { - $row[1]['TEXT'] = "Rowspan Example"; + $row[1]['TEXT'] = 'Rowspan Example'; $row[1]['BACKGROUND_COLOR'] = [$rgb_b, 50, 50]; $row[1]['ROWSPAN'] = 6; } if ($j == 9) { - $row[2]['TEXT'] = "Rowspan Example"; + $row[2]['TEXT'] = 'Rowspan Example'; $row[2]['BACKGROUND_COLOR'] = [$rgb_r, $rgb_r, $rgb_r]; $row[2]['ROWSPAN'] = 3; } diff --git a/examples/Tcpdf/example-table-3-detailed.php b/examples/Tcpdf/example-table-3-detailed.php index 8e0d03b..a6d258f 100644 --- a/examples/Tcpdf/example-table-3-detailed.php +++ b/examples/Tcpdf/example-table-3-detailed.php @@ -3,13 +3,12 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; -use EvoSys21\PdfLib\Table; use EvoSys21\PdfLib\Examples\Tcpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tcpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; +use EvoSys21\PdfLib\Table; //get the PDF object $pdf = PdfFactory::newPdf('table'); @@ -34,7 +33,6 @@ // Set the styles for the advanced table PdfSettings::setTableStyles($table); - //default text color $pdf->SetTextColor(118, 0, 3); @@ -43,10 +41,10 @@ $multicell->setStyle('s1', 8, '', '118,0,3', 'helvetica'); $multicell->setStyle('s2', 6, '', '0,49,159', 'helvetica'); -$multicell->multiCell(100, 4, "Example 1 - Very Simple Table"); +$multicell->multiCell(100, 4, 'Example 1 - Very Simple Table'); $pdf->Ln(1); -require('table_example1.php'); +require 'table_example1.php'; $pdf->Ln(10); @@ -55,7 +53,7 @@ $pdf->SetX(60); $multicell->multiCell(100, 2.5, $txt); $pdf->Ln(1); -require('table_example2.php'); +require 'table_example2.php'; $pdf->Ln(10); @@ -65,7 +63,7 @@ $multicell->multiCell(100, 2.5, $txt); $pdf->Ln(1); $tableSplitMode = true; -require('table_example2.php'); +require 'table_example2.php'; $pdf->Ln(10); @@ -75,7 +73,7 @@ $multicell->multiCell(100, 2.5, $txt); $pdf->Ln(1); $tableSplitMode = false; -require('table_example2.php'); +require 'table_example2.php'; //send the pdf to the browser $pdf->Output(); diff --git a/examples/Tcpdf/example-table-4-override.php b/examples/Tcpdf/example-table-4-override.php index 19b75fb..da1884b 100644 --- a/examples/Tcpdf/example-table-4-override.php +++ b/examples/Tcpdf/example-table-4-override.php @@ -3,13 +3,12 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; -use EvoSys21\PdfLib\Table; use EvoSys21\PdfLib\Examples\Tcpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tcpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; +use EvoSys21\PdfLib\Table; //get the PDF object $pdf = PdfFactory::newPdf('table'); @@ -31,18 +30,18 @@ $multicell = Multicell::getInstance($pdf); PdfSettings::setMulticellStyles($multicell); -$multicell->multiCell(100, 4, "Example - Override Default Configuration Values"); +$multicell->multiCell(100, 4, 'Example - Override Default Configuration Values'); $columns = 3; -$config = array( - 'TABLE' => array( +$config = [ + 'TABLE' => [ 'TABLE_ALIGN' => 'L', //left align 'BORDER_COLOR' => [0, 0, 0], //border color 'BORDER_SIZE' => '0.5', //border size - ), + ], - 'HEADER' => array( + 'HEADER' => [ 'TEXT_COLOR' => [25, 60, 170], //text color 'TEXT_SIZE' => 9, //font size 'LINE_SIZE' => 6, //line size for one row @@ -50,15 +49,15 @@ 'BORDER_SIZE' => 0.5, //border size 'BORDER_TYPE' => 'B', //border type, can be: 0, 1 or a combination of: 'LRTB' 'BORDER_COLOR' => [0, 0, 0], //border color - ), + ], - 'ROW' => array( + 'ROW' => [ 'TEXT_COLOR' => [225, 20, 0], //text color 'TEXT_SIZE' => 6, //font size 'BACKGROUND_COLOR' => [232, 255, 209], //background color 'BORDER_COLOR' => [150, 255, 56], //border color - ), -); + ], +]; //Initialize the table, 3 columns $table->initialize([40, 50, 30], $config); @@ -67,7 +66,7 @@ //Table Header for ($i = 0; $i < $columns; $i++) { - $header[$i]['TEXT'] = "Header #" . ($i + 1); + $header[$i]['TEXT'] = 'Header #' . ($i + 1); } //add the header @@ -79,11 +78,10 @@ $row[1]['TEXT'] = "Line $j Text 2"; //text for column 1 $row[2]['TEXT'] = "Line $j Text 3"; //text for column 2 - //override some settings for row 2 if (2 == $j) { $row[1]['TEXT_ALIGN'] = 'L'; - $row[1]['TEXT'] = "

This is a Multicell

"; + $row[1]['TEXT'] = '

This is a Multicell

'; } //add the row diff --git a/examples/Tcpdf/example-table-5-row-height.php b/examples/Tcpdf/example-table-5-row-height.php index d560f13..5cd38a7 100644 --- a/examples/Tcpdf/example-table-5-row-height.php +++ b/examples/Tcpdf/example-table-5-row-height.php @@ -3,13 +3,12 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; -use EvoSys21\PdfLib\Table; use EvoSys21\PdfLib\Examples\Tcpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tcpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; +use EvoSys21\PdfLib\Table; //get the PDF object $pdf = PdfFactory::newPdf('table'); @@ -31,18 +30,18 @@ $multicell = Multicell::getInstance($pdf); PdfSettings::setMulticellStyles($multicell); -$multicell->multiCell(100, 4, "Example - Override Default Configuration Values"); +$multicell->multiCell(100, 4, 'Example - Override Default Configuration Values'); $columns = 3; -$config = array( - 'TABLE' => array( +$config = [ + 'TABLE' => [ 'TABLE_ALIGN' => 'L', //left align 'BORDER_COLOR' => [0, 0, 0], //border color 'BORDER_SIZE' => '0.5', //border size - ), + ], - 'HEADER' => array( + 'HEADER' => [ 'TEXT_COLOR' => [25, 60, 170], //text color 'TEXT_SIZE' => 9, //font size 'LINE_SIZE' => 6, //line size for one row @@ -50,15 +49,15 @@ 'BORDER_SIZE' => 0.5, //border size 'BORDER_TYPE' => 'B', //border type, can be: 0, 1 or a combination of: 'LRTB' 'BORDER_COLOR' => [0, 0, 0], //border color - ), + ], - 'ROW' => array( + 'ROW' => [ 'TEXT_COLOR' => [225, 20, 0], //text color 'TEXT_SIZE' => 6, //font size 'BACKGROUND_COLOR' => [232, 255, 209], //background color 'BORDER_COLOR' => [150, 255, 56], //border color - ), -); + ], +]; //Initialize the table, 3 columns $table->initialize([40, 50, 30], $config); @@ -67,7 +66,7 @@ //Table Header for ($i = 0; $i < $columns; $i++) { - $header[$i]['TEXT'] = "Header #" . ($i + 1); + $header[$i]['TEXT'] = 'Header #' . ($i + 1); } //add the header @@ -79,7 +78,6 @@ $row[1]['TEXT'] = "Line $j Text 2"; //text for column 1 $row[2]['TEXT'] = "Line $j Text 3"; //text for column 2 - //override some settings for row 2 if (2 == $j) { $row[1]['TEXT_ALIGN'] = 'L'; diff --git a/examples/Tcpdf/table/code-example-alignments.php b/examples/Tcpdf/table/code-example-alignments.php index f74fbb0..acea772 100644 --- a/examples/Tcpdf/table/code-example-alignments.php +++ b/examples/Tcpdf/table/code-example-alignments.php @@ -1,11 +1,11 @@ initialize([20, 30, 40, 50]); $table->addHeader(PdfSettings::headerRow()); @@ -53,7 +52,6 @@ $row[3]['ALIGN'] = Tools::getNextValue(PdfSettings::$alignments, $k); } - $table->addRow($row); } diff --git a/examples/Tcpdf/table/code-example-transparent.php b/examples/Tcpdf/table/code-example-transparent.php index f9212b9..249c52c 100644 --- a/examples/Tcpdf/table/code-example-transparent.php +++ b/examples/Tcpdf/table/code-example-transparent.php @@ -1,18 +1,18 @@ GetY(); $pdf->SetX(50); -$pdf->Image(CONTENT_PATH . "/images/sample-pdf.jpg"); +$pdf->Image(CONTENT_PATH . '/images/sample-pdf.jpg'); $pdf->SetY($y); @@ -27,31 +27,29 @@ /** * Set the tag styles */ - $table->initialize([20, 30, 80]); -$table->setRowConfig(array( - 'BACKGROUND_COLOR' => false -)); - - -$header = array( - array( - 'TEXT' => 'Header #1' - ), - array( - 'TEXT' => 'Header #2' - ), - array( - 'TEXT' => 'Header #3' - ) -); +$table->setRowConfig([ + 'BACKGROUND_COLOR' => false, +]); + +$header = [ + [ + 'TEXT' => 'Header #1', + ], + [ + 'TEXT' => 'Header #2', + ], + [ + 'TEXT' => 'Header #3', + ], +]; //add the header row $table->addHeader($header); //row 1 - add data as Array $row = []; -$row[0]['TEXT'] = "Line 1"; +$row[0]['TEXT'] = 'Line 1'; $row[1] = PdfSettings::$imageCell; @@ -66,7 +64,7 @@ //alternatively you can create directly the cell object $row[0] = new Image($pdf, CONTENT_PATH . '/images/blog.jpg', 10); -$row[1] = new Multicell($pdf, "

This is another Multicell

"); +$row[1] = new Multicell($pdf, '

This is another Multicell

'); $row[2]['TEXT'] = "

All table cells are fully functional Advanced Multicells\nDetails on https://github.com/evosys21/pdflib

"; $row[2]['BACKGROUND_COLOR'] = PdfSettings::$colors[1]; diff --git a/examples/Tcpdf/table/code-example1.php b/examples/Tcpdf/table/code-example1.php index 71b3ecc..874ccc1 100644 --- a/examples/Tcpdf/table/code-example1.php +++ b/examples/Tcpdf/table/code-example1.php @@ -3,10 +3,10 @@ use EvoSys21\PdfLib\Examples\Tcpdf\MyPdf; use EvoSys21\PdfLib\Table; -if (!isset($pdf)) { +if (! isset($pdf)) { $pdf = new MyPdf(); } -if (!isset($table)) { +if (! isset($table)) { $table = new Table($pdf); } @@ -20,11 +20,11 @@ */ $table->initialize([20, 30, 50]); -$header = array( +$header = [ ['TEXT' => 'Header #1'], ['TEXT' => 'Header #2'], ['TEXT' => 'Header #3'], -); +]; //add the header row $table->addHeader($header); @@ -32,7 +32,7 @@ for ($j = 1; $j < 3; $j++) { $row = []; $row[0]['TEXT'] = "Line $j"; - $row[1]['TEXT'] = "Lorem ipsum dolor sit amet..."; + $row[1]['TEXT'] = 'Lorem ipsum dolor sit amet...'; $row[2]['TEXT'] = "

Simple text\nBold text

"; //add the data row diff --git a/examples/Tcpdf/table/code-example2.php b/examples/Tcpdf/table/code-example2.php index c18d9b1..32391ce 100644 --- a/examples/Tcpdf/table/code-example2.php +++ b/examples/Tcpdf/table/code-example2.php @@ -4,7 +4,7 @@ use EvoSys21\PdfLib\Examples\Tcpdf\PdfSettings; use EvoSys21\PdfLib\Table; -if (!isset($pdf)) { +if (! isset($pdf)) { $pdf = new MyPdf(); } @@ -19,13 +19,12 @@ /** * Set the tag styles */ - $table->initialize([20, 30, 80]); $header = [ ['TEXT' => 'Header #1'], ['TEXT' => 'Header #2'], - ['TEXT' => 'Header #3'] + ['TEXT' => 'Header #3'], ]; //add the header row @@ -35,7 +34,7 @@ //row 1 - add data as Array $row = []; -$row[0]['TEXT'] = "Line 1"; +$row[0]['TEXT'] = 'Line 1'; $row[1] = PdfSettings::$imageCell; @@ -50,10 +49,10 @@ //alternatively you can create directly the cell object $row[0] = new Table\Cell\Image($pdf, CONTENT_PATH . '/images/blog.jpg', 10); -$row[1] = array( +$row[1] = [ 'TEXT' => "

SVG Images are supported\n(see right image >>>)

", - 'BACKGROUND_COLOR' => PdfSettings::$colors[0] -); + 'BACKGROUND_COLOR' => PdfSettings::$colors[0], +]; $row[2] = new Table\Cell\ImageSVG($pdf, CONTENT_PATH . '/images/Tiger.svg', 35, 35); diff --git a/examples/Tcpdf/table/code-example3.php b/examples/Tcpdf/table/code-example3.php index b4fa0b6..513c004 100644 --- a/examples/Tcpdf/table/code-example3.php +++ b/examples/Tcpdf/table/code-example3.php @@ -4,7 +4,7 @@ use EvoSys21\PdfLib\Examples\Tcpdf\PdfSettings; use EvoSys21\PdfLib\Table; -if (!isset($pdf)) { +if (! isset($pdf)) { $pdf = new MyPdf(); } @@ -21,7 +21,6 @@ /** * Set the tag styles */ - $table->initialize([20, 30, 40, 50]); $header1 = PdfSettings::headerRow(); @@ -31,7 +30,7 @@ $header2 = PdfSettings::headerRow(); $header3 = PdfSettings::headerRow(); -$header2[1]['TEXT'] = "Colspan/Rowspan in Header"; +$header2[1]['TEXT'] = 'Colspan/Rowspan in Header'; $header2[1]['COLSPAN'] = 2; $header2[1]['ROWSPAN'] = 2; @@ -39,7 +38,6 @@ $table->addHeader($header2); $table->addHeader($header3); - for ($i = 0; $i < 8; $i++) { $row = PdfSettings::dataRow(); @@ -68,7 +66,6 @@ $row[1]['ROWSPAN'] = 2; } - $table->addRow($row); } diff --git a/examples/Tcpdf/table_example1.php b/examples/Tcpdf/table_example1.php index 4ab6ea3..64b9cd8 100644 --- a/examples/Tcpdf/table_example1.php +++ b/examples/Tcpdf/table_example1.php @@ -9,7 +9,7 @@ //Table Header for ($i = 0; $i < $columns; $i++) { - $header[$i]['TEXT'] = "Header #" . ($i + 1); + $header[$i]['TEXT'] = 'Header #' . ($i + 1); } //add the header @@ -24,7 +24,6 @@ $row[2]['TEXT'] = "Line $j Text 3"; //text for column 2 $row[2]['TEXT_ALIGN'] = 'R'; //text align - //add the row $table->addRow($row); //break; diff --git a/examples/Tcpdf/table_example2.php b/examples/Tcpdf/table_example2.php index 78fbae4..db84276 100644 --- a/examples/Tcpdf/table_example2.php +++ b/examples/Tcpdf/table_example2.php @@ -9,7 +9,7 @@ //Table Header for ($i = 0; $i < $columns; $i++) { - $header[$i]['TEXT'] = "Header #" . ($i + 1); + $header[$i]['TEXT'] = 'Header #' . ($i + 1); } $table->addHeader($header); @@ -56,21 +56,21 @@ } if ($j == 7) { - $row[1]['TEXT'] = "Top Left Align"; + $row[1]['TEXT'] = 'Top Left Align'; $row[1]['VERTICAL_ALIGN'] = 'T'; $row[1]['TEXT_ALIGN'] = 'L'; - $row[2]['TEXT'] = "Bottom Right Align"; + $row[2]['TEXT'] = 'Bottom Right Align'; $row[2]['VERTICAL_ALIGN'] = 'B'; $row[2]['TEXT_ALIGN'] = 'R'; } if ($j == 8) { - $row[1]['TEXT'] = "Top Center Align"; + $row[1]['TEXT'] = 'Top Center Align'; $row[1]['VERTICAL_ALIGN'] = 'T'; $row[1]['TEXT_ALIGN'] = 'C'; - $row[2]['TEXT'] = "Bottom Center Align"; + $row[2]['TEXT'] = 'Bottom Center Align'; $row[2]['VERTICAL_ALIGN'] = 'B'; $row[2]['TEXT_ALIGN'] = 'C'; } @@ -94,7 +94,7 @@ } if ($j == 14) { - $row[1]['TEXT'] = "Cell Properties Overwriting Example"; + $row[1]['TEXT'] = 'Cell Properties Overwriting Example'; $row[1]['TEXT_FONT'] = 'Times'; $row[1]['TEXT_SIZE'] = 7; $row[1]['TEXT_TYPE'] = 'B'; diff --git a/examples/Tfpdf/MyPdf.php b/examples/Tfpdf/MyPdf.php index 0355cc1..b9aae3b 100644 --- a/examples/Tfpdf/MyPdf.php +++ b/examples/Tfpdf/MyPdf.php @@ -4,11 +4,12 @@ namespace EvoSys21\PdfLib\Examples\Tfpdf; -use EvoSys21\PdfLib\Tfpdf\Pdf; use EvoSys21\PdfLib\Multicell; +use EvoSys21\PdfLib\Tfpdf\Pdf; /** * Custom PDF class extension for Header and Footer Definitions + * * @SuppressWarnings(PHPMD.CamelCaseMethodName) * @SuppressWarnings(PHPMD.Superglobals) * phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps @@ -20,12 +21,14 @@ class MyPdf extends Pdf /** * Custom Header + * * @SuppressWarnings(PHPMD.CamelCaseMethodName) + * * @see Pdf::Header() */ public function Header() { - if (!$this->showHeader) { + if (! $this->showHeader) { return; } @@ -57,7 +60,6 @@ public function Header() $this->SetY($this->tMargin); } - /** * Custom Footer * @@ -67,7 +69,7 @@ public function Footer() { $this->drawMargins && $this->drawMarginLines(); - if (!$this->showFooter) { + if (! $this->showFooter) { return; } @@ -79,8 +81,6 @@ public function Footer() /** * Returns the default Font to be used - * - * @return string */ public function getDefaultFont(): string { @@ -105,7 +105,6 @@ public function drawMarginLines(): void $this->Line($this->w - $this->rMargin, 0, $this->w - $this->rMargin, $this->h); } - /** * Disable the Producer and CreationDate. It breaks the functional unit-testing(date always changes) * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore @@ -125,16 +124,16 @@ public function _putinfo() protected static function isTesting(): bool { - return (getenv('APP_ENV') === 'testing'); + return getenv('APP_ENV') === 'testing'; } /** - * @param string $headerSource * @return $this */ public function setHeaderSource(string $headerSource): self { $this->headerSource = $headerSource; + return $this; } } diff --git a/examples/Tfpdf/PdfFactory.php b/examples/Tfpdf/PdfFactory.php index f57e7fa..5edc182 100644 --- a/examples/Tfpdf/PdfFactory.php +++ b/examples/Tfpdf/PdfFactory.php @@ -15,10 +15,8 @@ class PdfFactory /** * Creates a new PDF Object and Initializes it * - * @param string $type * @param bool $header Show the header * @param bool $footer Show the footer - * @return MyPdf */ public static function newPdf(string $type, bool $header = true, bool $footer = true): MyPdf { @@ -43,9 +41,6 @@ public static function newPdf(string $type, bool $header = true, bool $footer = * Initializes the pdf object. * Set the margins, adds a page, adds default fonts etc... * - * @param Pdf $pdf - * @param bool $header - * @param bool $footer * @return Pdf $pdf */ public static function initPdf(Pdf $pdf, bool $header = true, bool $footer = true): Pdf diff --git a/examples/Tfpdf/PdfSettings.php b/examples/Tfpdf/PdfSettings.php index e14fa3c..017a0e7 100644 --- a/examples/Tfpdf/PdfSettings.php +++ b/examples/Tfpdf/PdfSettings.php @@ -7,7 +7,7 @@ use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Table; -if (!defined('__DIR__')) { +if (! defined('__DIR__')) { define('__DIR__', __DIR__ . '/../../..'); } @@ -20,10 +20,9 @@ class PdfSettings [86, 155, 225], [207, 247, 239], [246, 211, 207], - [216, 243, 228] + [216, 243, 228], ]; - //top, right, bottom, left public static $paddings = [ [0, 0, 0, 0], @@ -43,28 +42,26 @@ class PdfSettings [5, 5, 5, 0], [0, 5, 5, 5], [5, 0, 5, 5], - [5, 5, 0, 5] + [5, 5, 0, 5], ]; - public static $alignments = ['TL', 'TC', 'TR', 'ML', 'MC', 'MR', 'BL', 'BC', 'BR']; - - public static $textShort = "Hello world!"; - public static $text = "Lorem ipsum dolor sit amet..."; + public static $textShort = 'Hello world!'; + public static $text = 'Lorem ipsum dolor sit amet...'; public static $text2 = "

Simple text\nBold text

"; - public static $textLong = "

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

"; - public static $textExtraLong = "

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur

"; + public static $textLong = '

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

'; + public static $textExtraLong = '

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur

'; public static $textSubSuperscript = "Subscript or Superscript"; public static $columns = 5; //prepare some default row settings - public static array $imageCell = array( + public static array $imageCell = [ 'TYPE' => 'IMAGE', 'FILE' => CONTENT_PATH . '/images/dice.jpg', - 'WIDTH' => 10 - ); + 'WIDTH' => 10, + ]; public static function headerRow(): array { @@ -72,6 +69,7 @@ public static function headerRow(): array for ($i = 0; $i < static::$columns; $i++) { $headerRow[$i]['TEXT'] = "Header #$i"; } + return $headerRow; } @@ -79,12 +77,12 @@ public static function dataRow(): array { $dataRow = []; for ($i = 0; $i < static::$columns; $i++) { - $dataRow[$i]['TEXT'] = "Cool cell"; + $dataRow[$i]['TEXT'] = 'Cool cell'; } + return $dataRow; } - /** * Set the styles for the advanced multicell * @@ -115,11 +113,8 @@ public static function setMulticellStyles(Multicell $multicell) $multicell->setStyle('u8b', null, 'B', null, null, 'u8'); } - /** * Set the styles for the advanced table - * - * @param Table $table */ public static function setTableStyles(Table $table) { diff --git a/examples/Tfpdf/example-multicell-1-overview.php b/examples/Tfpdf/example-multicell-1-overview.php index 0f76200..e232c60 100644 --- a/examples/Tfpdf/example-multicell-1-overview.php +++ b/examples/Tfpdf/example-multicell-1-overview.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Tfpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tfpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); diff --git a/examples/Tfpdf/example-multicell-2-overview-page-break.php b/examples/Tfpdf/example-multicell-2-overview-page-break.php index 1c58c1a..bef3188 100644 --- a/examples/Tfpdf/example-multicell-2-overview-page-break.php +++ b/examples/Tfpdf/example-multicell-2-overview-page-break.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Tfpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tfpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); @@ -27,7 +26,6 @@ $pdf->Ln(10); //line break - //read TAG formatted text from file $txt = file_get_contents(CONTENT_PATH . '/multicell.txt'); $s = $txt . "\n\n\n\nRepeat the text to trigger a page break \n\n\n" . $txt; diff --git a/examples/Tfpdf/example-multicell-3-line-breaking.php b/examples/Tfpdf/example-multicell-3-line-breaking.php index 8bffa60..1789812 100644 --- a/examples/Tfpdf/example-multicell-3-line-breaking.php +++ b/examples/Tfpdf/example-multicell-3-line-breaking.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Tfpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tfpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); @@ -26,20 +25,17 @@ $multicell->multiCell(100, 5, $txt, 1, 'R', 0, 0, 1); $pdf->Ln(10); //new line - //create an advanced multicell $multicell->multiCell(0, 5, 'Setting > as line breaking character'); $multicell->setLineBreakingCharacters('>'); $multicell->multiCell(100, 5, $txt, 1); $pdf->Ln(10); //new line - //create an advanced multicell $multicell->multiCell(0, 5, 'Reseting the line breaking characters'); $multicell->resetLineBreakingCharacters(); $multicell->multiCell(100, 5, $txt, 1); $pdf->Ln(10); //new line - //send the pdf to the browser $pdf->Output(); diff --git a/examples/Tfpdf/example-multicell-4-page-break.php b/examples/Tfpdf/example-multicell-4-page-break.php index e59a384..653cfcd 100644 --- a/examples/Tfpdf/example-multicell-4-page-break.php +++ b/examples/Tfpdf/example-multicell-4-page-break.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Tfpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tfpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); diff --git a/examples/Tfpdf/example-multicell-5-max-lines.php b/examples/Tfpdf/example-multicell-5-max-lines.php index 6029ec4..2781376 100644 --- a/examples/Tfpdf/example-multicell-5-max-lines.php +++ b/examples/Tfpdf/example-multicell-5-max-lines.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Tfpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tfpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); diff --git a/examples/Tfpdf/example-multicell-6-shrinking.php b/examples/Tfpdf/example-multicell-6-shrinking.php index 7f2b66c..22a0480 100644 --- a/examples/Tfpdf/example-multicell-6-shrinking.php +++ b/examples/Tfpdf/example-multicell-6-shrinking.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Multicell - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Tfpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tfpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('multicell'); @@ -20,10 +19,10 @@ PdfSettings::setMulticellStyles($multicell); $pdf->Ln(5); //line break -$multicell->multiCell(120, 5, "

Multicell text shrinking feature

"); +$multicell->multiCell(120, 5, '

Multicell text shrinking feature

'); $pdf->Ln(10); //line break -$txt = <<TCPDF addon allows creation of an Advanced Multicell which uses as input a TAG based formatted string instead of a simple string. The use of tags allows to change the font, the style (bold, italic, underline), the size, and the color of characters and many other features.

Features:

@@ -52,7 +51,7 @@ $pdf->AddPage(); -$txt = <<ln(10); -$s = <<Typography:

Heading 1

@@ -93,9 +92,9 @@ $pdf->ln(10); -$multicell->multiCell(0, 10, "Table of Content:"); +$multicell->multiCell(0, 10, 'Table of Content:'); -$s = <<

- Paragraph 1

- Paragraph 2

- Paragraph 2.1

@@ -105,9 +104,9 @@ $multicell->multiCell(0, 5, $s); $pdf->ln(10); -$multicell->multiCell(0, 10, "Tag width and alignment:"); +$multicell->multiCell(0, 10, 'Tag width and alignment:'); -$s = << Align Left

Align Center

Align Right

@@ -115,7 +114,7 @@ $multicell->multiCell(100, 5, $s, 1, '', 1); $pdf->AddPage(); -$multicell->multiCell(0, 10, "No wrap: text will not break on normal separators"); +$multicell->multiCell(0, 10, 'No wrap: text will not break on normal separators'); $s = "The price is USD 5.344,23"; foreach ([40, 45, 50] as $width) { diff --git a/examples/Tfpdf/example-table-1-overview.php b/examples/Tfpdf/example-table-1-overview.php index c4224b1..2ec8235 100644 --- a/examples/Tfpdf/example-table-1-overview.php +++ b/examples/Tfpdf/example-table-1-overview.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; use EvoSys21\PdfLib\Examples\Tfpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tfpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; //get the PDF object $pdf = PdfFactory::newPdf('table'); @@ -21,28 +20,27 @@ //simple table $multicell->multiCell(0, 5, "

~~~Simple table:

"); -require(__DIR__ . '/table/code-example1.php'); +require __DIR__ . '/table/code-example1.php'; //cells can be multicells and images $pdf->Ln(10); $multicell->multiCell(0, 5, "

~~~Cells can be advanced multicells and images:

"); -require(__DIR__ . '/table/code-example2.php'); +require __DIR__ . '/table/code-example2.php'; //example - Multiple header rows, rowspans, colspans $pdf->Ln(10); $multicell->multiCell(0, 5, "

~~~Multiple header rows, rowspans, colspans:

"); -require(__DIR__ . '/table/code-example3.php'); +require __DIR__ . '/table/code-example3.php'; //example - Transparent background $pdf->Ln(10); $multicell->multiCell(0, 5, "

~~~ Transparent Background:

"); -require(__DIR__ . '/table/code-example-transparent.php'); - +require __DIR__ . '/table/code-example-transparent.php'; //example - all parameters can be overwritten $pdf->Ln(10); $multicell->multiCell(0, 5, "

~~~Different alignments:

"); -require(__DIR__ . '/table/code-example-alignments.php'); +require __DIR__ . '/table/code-example-alignments.php'; //send the pdf to the browser $pdf->Output(); diff --git a/examples/Tfpdf/example-table-2-overview.php b/examples/Tfpdf/example-table-2-overview.php index b09db81..c61abb1 100644 --- a/examples/Tfpdf/example-table-2-overview.php +++ b/examples/Tfpdf/example-table-2-overview.php @@ -3,12 +3,11 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Table; use EvoSys21\PdfLib\Examples\Tfpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tfpdf\PdfSettings; +use EvoSys21\PdfLib\Table; //get the PDF object $pdf = PdfFactory::newPdf('table'); @@ -32,7 +31,7 @@ //Initialize the table, 5 columns with the specified widths $table->initialize([35, 30, 40, 40, 25], [ - 'TABLE' => ['TABLE_LEFT_MARGIN' => 0] + 'TABLE' => ['TABLE_LEFT_MARGIN' => 0], ]); $header = [ @@ -40,7 +39,7 @@ ['TEXT' => 'Header 2'], ['TEXT' => 'Header 3'], ['TEXT' => 'Header 4'], - ['TEXT' => 'Header 5'] + ['TEXT' => 'Header 5'], ]; //add the header line @@ -73,7 +72,7 @@ $row[1]['TEXT'] = "Test Text Column 1- $j"; $row[1]['TEXT_SIZE'] = 13 - $fsize; $row[2]['TEXT'] = "Test Text Column 2- $j"; - $row[3]['TEXT'] = "Longer text, this will split sometimes..."; + $row[3]['TEXT'] = 'Longer text, this will split sometimes...'; $row[3]['TEXT_SIZE'] = 15 - $fsize; $row[4]['TEXT'] = "Short 4- $j"; $row[4]['TEXT_SIZE'] = 7; @@ -84,31 +83,31 @@ $row[1]['ALIGN'] = 'C'; $row[1]['LINE_SIZE'] = 5; } elseif ($j == 1) { - $row[0]['TEXT'] = "Top Right Align

Align Top

Right Right Align"; + $row[0]['TEXT'] = 'Top Right Align

Align Top

Right Right Align'; $row[0]['ALIGN'] = 'RT'; - $row[1]['TEXT'] = "Middle Center Align Bold Italic"; + $row[1]['TEXT'] = 'Middle Center Align Bold Italic'; $row[1]['TEXT_TYPE'] = 'BI'; $row[1]['ALIGN'] = 'MC'; $row[2]['TEXT'] = "\n\n\n\n\nBottom Left Align"; $row[2]['ALIGN'] = 'BL'; - $row[3]['TEXT'] = "Middle Justified Align Longer text"; + $row[3]['TEXT'] = 'Middle Justified Align Longer text'; $row[3]['ALIGN'] = 'MJ'; - $row[4]['TEXT'] = "TOP RIGHT Align with top padding(5)"; + $row[4]['TEXT'] = 'TOP RIGHT Align with top padding(5)'; $row[4]['ALIGN'] = 'TR'; $row[4]['PADDING_TOP'] = 5; } if ($j == 2) { - $row[1]['TEXT'] = "Cells can be images -->>>"; - $row[2] = array( + $row[1]['TEXT'] = 'Cells can be images -->>>'; + $row[2] = [ 'TYPE' => 'IMAGE', 'FILE' => CONTENT_PATH . '/images/dice.jpg', - 'WIDTH' => 15 - ); + 'WIDTH' => 15, + ]; } if ($j > 0) { @@ -117,7 +116,7 @@ } if ($j > 3 and $j < 7) { - $row[1]['TEXT'] = "Colspan Example - Center Align"; + $row[1]['TEXT'] = 'Colspan Example - Center Align'; $row[1]['COLSPAN'] = $colspan; $row[1]['BACKGROUND_COLOR'] = [$rgb_b, 50, 50]; $row[1]['TEXT_COLOR'] = [255, 255, $rgb_g]; @@ -129,19 +128,19 @@ } if ($j == 7) { - $row[3]['TEXT'] = "Rowspan Example"; + $row[3]['TEXT'] = 'Rowspan Example'; $row[3]['BACKGROUND_COLOR'] = [$rgb_b, $rgb_b, 250]; $row[3]['ROWSPAN'] = 4; } if ($j == 8) { - $row[1]['TEXT'] = "Rowspan Example"; + $row[1]['TEXT'] = 'Rowspan Example'; $row[1]['BACKGROUND_COLOR'] = [$rgb_b, 50, 50]; $row[1]['ROWSPAN'] = 6; } if ($j == 9) { - $row[2]['TEXT'] = "Rowspan Example"; + $row[2]['TEXT'] = 'Rowspan Example'; $row[2]['BACKGROUND_COLOR'] = [$rgb_r, $rgb_r, $rgb_r]; $row[2]['ROWSPAN'] = 3; } diff --git a/examples/Tfpdf/example-table-3-detailed.php b/examples/Tfpdf/example-table-3-detailed.php index 2afd3c4..79fdb6a 100644 --- a/examples/Tfpdf/example-table-3-detailed.php +++ b/examples/Tfpdf/example-table-3-detailed.php @@ -3,13 +3,12 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; -use EvoSys21\PdfLib\Table; use EvoSys21\PdfLib\Examples\Tfpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tfpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; +use EvoSys21\PdfLib\Table; //get the PDF object $pdf = PdfFactory::newPdf('table'); @@ -34,7 +33,6 @@ // Set the styles for the advanced table PdfSettings::setTableStyles($table); - //default text color $pdf->SetTextColor(118, 0, 3); @@ -43,10 +41,10 @@ $multicell->setStyle('s1', 8, '', '118,0,3', 'helvetica'); $multicell->setStyle('s2', 6, '', '0,49,159', 'helvetica'); -$multicell->multiCell(100, 4, "Example 1 - Very Simple Table"); +$multicell->multiCell(100, 4, 'Example 1 - Very Simple Table'); $pdf->Ln(1); -require('table_example1.php'); +require 'table_example1.php'; $pdf->Ln(10); @@ -55,7 +53,7 @@ $pdf->SetX(60); $multicell->multiCell(100, 2.5, $txt); $pdf->Ln(1); -require('table_example2.php'); +require 'table_example2.php'; $pdf->Ln(10); @@ -65,7 +63,7 @@ $multicell->multiCell(100, 2.5, $txt); $pdf->Ln(1); $tableSplitMode = true; -require('table_example2.php'); +require 'table_example2.php'; $pdf->Ln(10); @@ -75,7 +73,7 @@ $multicell->multiCell(100, 2.5, $txt); $pdf->Ln(1); $tableSplitMode = false; -require('table_example2.php'); +require 'table_example2.php'; //send the pdf to the browser $pdf->Output(); diff --git a/examples/Tfpdf/example-table-4-override.php b/examples/Tfpdf/example-table-4-override.php index cea71ca..9486190 100644 --- a/examples/Tfpdf/example-table-4-override.php +++ b/examples/Tfpdf/example-table-4-override.php @@ -3,13 +3,12 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; -use EvoSys21\PdfLib\Table; use EvoSys21\PdfLib\Examples\Tfpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tfpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; +use EvoSys21\PdfLib\Table; //get the PDF object $pdf = PdfFactory::newPdf('table'); @@ -31,18 +30,18 @@ $multicell = Multicell::getInstance($pdf); PdfSettings::setMulticellStyles($multicell); -$multicell->multiCell(100, 4, "Example - Override Default Configuration Values"); +$multicell->multiCell(100, 4, 'Example - Override Default Configuration Values'); $columns = 3; -$config = array( - 'TABLE' => array( +$config = [ + 'TABLE' => [ 'TABLE_ALIGN' => 'L', //left align 'BORDER_COLOR' => [0, 0, 0], //border color 'BORDER_SIZE' => '0.5', //border size - ), + ], - 'HEADER' => array( + 'HEADER' => [ 'TEXT_COLOR' => [25, 60, 170], //text color 'TEXT_SIZE' => 9, //font size 'LINE_SIZE' => 6, //line size for one row @@ -50,15 +49,15 @@ 'BORDER_SIZE' => 0.5, //border size 'BORDER_TYPE' => 'B', //border type, can be: 0, 1 or a combination of: 'LRTB' 'BORDER_COLOR' => [0, 0, 0], //border color - ), + ], - 'ROW' => array( + 'ROW' => [ 'TEXT_COLOR' => [225, 20, 0], //text color 'TEXT_SIZE' => 6, //font size 'BACKGROUND_COLOR' => [232, 255, 209], //background color 'BORDER_COLOR' => [150, 255, 56], //border color - ), -); + ], +]; //Initialize the table, 3 columns $table->initialize([40, 50, 30], $config); @@ -67,7 +66,7 @@ //Table Header for ($i = 0; $i < $columns; $i++) { - $header[$i]['TEXT'] = "Header #" . ($i + 1); + $header[$i]['TEXT'] = 'Header #' . ($i + 1); } //add the header @@ -79,11 +78,10 @@ $row[1]['TEXT'] = "Line $j Text 2"; //text for column 1 $row[2]['TEXT'] = "Line $j Text 3"; //text for column 2 - //override some settings for row 2 if (2 == $j) { $row[1]['TEXT_ALIGN'] = 'L'; - $row[1]['TEXT'] = "

This is a Multicell

"; + $row[1]['TEXT'] = '

This is a Multicell

'; } //add the row diff --git a/examples/Tfpdf/example-table-5-row-height.php b/examples/Tfpdf/example-table-5-row-height.php index 61a9420..b6044e4 100644 --- a/examples/Tfpdf/example-table-5-row-height.php +++ b/examples/Tfpdf/example-table-5-row-height.php @@ -3,13 +3,12 @@ /** * Pdf Advanced Table - Example */ - require_once __DIR__ . '/autoload.php'; -use EvoSys21\PdfLib\Multicell; -use EvoSys21\PdfLib\Table; use EvoSys21\PdfLib\Examples\Tfpdf\PdfFactory; use EvoSys21\PdfLib\Examples\Tfpdf\PdfSettings; +use EvoSys21\PdfLib\Multicell; +use EvoSys21\PdfLib\Table; //get the PDF object $pdf = PdfFactory::newPdf('table'); @@ -31,18 +30,18 @@ $multicell = Multicell::getInstance($pdf); PdfSettings::setMulticellStyles($multicell); -$multicell->multiCell(100, 4, "Example - Override Default Configuration Values"); +$multicell->multiCell(100, 4, 'Example - Override Default Configuration Values'); $columns = 3; -$config = array( - 'TABLE' => array( +$config = [ + 'TABLE' => [ 'TABLE_ALIGN' => 'L', //left align 'BORDER_COLOR' => [0, 0, 0], //border color 'BORDER_SIZE' => '0.5', //border size - ), + ], - 'HEADER' => array( + 'HEADER' => [ 'TEXT_COLOR' => [25, 60, 170], //text color 'TEXT_SIZE' => 9, //font size 'LINE_SIZE' => 6, //line size for one row @@ -50,15 +49,15 @@ 'BORDER_SIZE' => 0.5, //border size 'BORDER_TYPE' => 'B', //border type, can be: 0, 1 or a combination of: 'LRTB' 'BORDER_COLOR' => [0, 0, 0], //border color - ), + ], - 'ROW' => array( + 'ROW' => [ 'TEXT_COLOR' => [225, 20, 0], //text color 'TEXT_SIZE' => 6, //font size 'BACKGROUND_COLOR' => [232, 255, 209], //background color 'BORDER_COLOR' => [150, 255, 56], //border color - ), -); + ], +]; //Initialize the table, 3 columns $table->initialize([40, 50, 30], $config); @@ -67,7 +66,7 @@ //Table Header for ($i = 0; $i < $columns; $i++) { - $header[$i]['TEXT'] = "Header #" . ($i + 1); + $header[$i]['TEXT'] = 'Header #' . ($i + 1); } //add the header @@ -79,7 +78,6 @@ $row[1]['TEXT'] = "Line $j Text 2"; //text for column 1 $row[2]['TEXT'] = "Line $j Text 3"; //text for column 2 - //override some settings for row 2 if (2 == $j) { $row[1]['TEXT_ALIGN'] = 'L'; diff --git a/examples/Tfpdf/table/code-example-alignments.php b/examples/Tfpdf/table/code-example-alignments.php index 2b8ee71..14ec4cb 100644 --- a/examples/Tfpdf/table/code-example-alignments.php +++ b/examples/Tfpdf/table/code-example-alignments.php @@ -1,11 +1,11 @@ initialize([20, 30, 40, 50]); $table->addHeader(PdfSettings::headerRow()); @@ -53,7 +52,6 @@ $row[3]['ALIGN'] = Tools::getNextValue(PdfSettings::$alignments, $k); } - $table->addRow($row); } diff --git a/examples/Tfpdf/table/code-example-transparent.php b/examples/Tfpdf/table/code-example-transparent.php index d072055..85cc567 100644 --- a/examples/Tfpdf/table/code-example-transparent.php +++ b/examples/Tfpdf/table/code-example-transparent.php @@ -1,18 +1,18 @@ GetY(); $pdf->SetX(50); -$pdf->Image(CONTENT_PATH . "/images/sample-pdf.jpg"); +$pdf->Image(CONTENT_PATH . '/images/sample-pdf.jpg'); $pdf->SetY($y); @@ -27,31 +27,29 @@ /** * Set the tag styles */ - $table->initialize([20, 30, 80]); -$table->setRowConfig(array( - 'BACKGROUND_COLOR' => false -)); - - -$header = array( - array( - 'TEXT' => 'Header #1' - ), - array( - 'TEXT' => 'Header #2' - ), - array( - 'TEXT' => 'Header #3' - ) -); +$table->setRowConfig([ + 'BACKGROUND_COLOR' => false, +]); + +$header = [ + [ + 'TEXT' => 'Header #1', + ], + [ + 'TEXT' => 'Header #2', + ], + [ + 'TEXT' => 'Header #3', + ], +]; //add the header row $table->addHeader($header); //row 1 - add data as Array $row = []; -$row[0]['TEXT'] = "Line 1"; +$row[0]['TEXT'] = 'Line 1'; $row[1] = PdfSettings::$imageCell; @@ -66,7 +64,7 @@ //alternatively you can create directly the cell object $row[0] = new Image($pdf, CONTENT_PATH . '/images/blog.jpg', 10); -$row[1] = new Multicell($pdf, "

This is another Multicell

"); +$row[1] = new Multicell($pdf, '

This is another Multicell

'); $row[2]['TEXT'] = "

All table cells are fully functional Advanced Multicells\nDetails on https://github.com/evosys21/pdflib

"; $row[2]['BACKGROUND_COLOR'] = PdfSettings::$colors[1]; diff --git a/examples/Tfpdf/table/code-example1.php b/examples/Tfpdf/table/code-example1.php index 928ac7d..e9215d8 100644 --- a/examples/Tfpdf/table/code-example1.php +++ b/examples/Tfpdf/table/code-example1.php @@ -3,10 +3,10 @@ use EvoSys21\PdfLib\Examples\Tfpdf\MyPdf; use EvoSys21\PdfLib\Table; -if (!isset($pdf)) { +if (! isset($pdf)) { $pdf = new MyPdf(); } -if (!isset($table)) { +if (! isset($table)) { $table = new Table($pdf); } @@ -20,11 +20,11 @@ */ $table->initialize([20, 30, 50]); -$header = array( +$header = [ ['TEXT' => 'Header #1'], ['TEXT' => 'Header #2'], ['TEXT' => 'Header #3'], -); +]; //add the header row $table->addHeader($header); @@ -32,7 +32,7 @@ for ($j = 1; $j < 3; $j++) { $row = []; $row[0]['TEXT'] = "Line $j"; - $row[1]['TEXT'] = "Lorem ipsum dolor sit amet..."; + $row[1]['TEXT'] = 'Lorem ipsum dolor sit amet...'; $row[2]['TEXT'] = "

Simple text\nBold text

"; //add the data row diff --git a/examples/Tfpdf/table/code-example2.php b/examples/Tfpdf/table/code-example2.php index b3340e9..9d7fe7b 100644 --- a/examples/Tfpdf/table/code-example2.php +++ b/examples/Tfpdf/table/code-example2.php @@ -4,7 +4,7 @@ use EvoSys21\PdfLib\Examples\Tfpdf\PdfSettings; use EvoSys21\PdfLib\Table; -if (!isset($pdf)) { +if (! isset($pdf)) { $pdf = new MyPdf(); } @@ -19,13 +19,12 @@ /** * Set the tag styles */ - $table->initialize([20, 30, 80]); $header = [ ['TEXT' => 'Header #1'], ['TEXT' => 'Header #2'], - ['TEXT' => 'Header #3'] + ['TEXT' => 'Header #3'], ]; //add the header row @@ -35,7 +34,7 @@ //row 1 - add data as Array $row = []; -$row[0]['TEXT'] = "Line 1"; +$row[0]['TEXT'] = 'Line 1'; $row[1] = PdfSettings::$imageCell; @@ -50,13 +49,13 @@ //alternatively you can create directly the cell object $row[0] = new Table\Cell\Image($pdf, CONTENT_PATH . '/images/blog.jpg', 10); -$row[1] = array( - 'TEXT' => "

This is another Multicell

", - 'BACKGROUND_COLOR' => PdfSettings::$colors[0] -); +$row[1] = [ + 'TEXT' => '

This is another Multicell

', + 'BACKGROUND_COLOR' => PdfSettings::$colors[0], +]; $row[2] = new Table\Cell\Image($pdf, CONTENT_PATH . '/images/pencil.jpg', 10); -$row[2]->setAlign("R"); +$row[2]->setAlign('R'); //add the data row $table->addRow($row); diff --git a/examples/Tfpdf/table/code-example3.php b/examples/Tfpdf/table/code-example3.php index a65d169..99e695a 100644 --- a/examples/Tfpdf/table/code-example3.php +++ b/examples/Tfpdf/table/code-example3.php @@ -4,7 +4,7 @@ use EvoSys21\PdfLib\Examples\Tfpdf\PdfSettings; use EvoSys21\PdfLib\Table; -if (!isset($pdf)) { +if (! isset($pdf)) { $pdf = new MyPdf(); } @@ -21,7 +21,6 @@ /** * Set the tag styles */ - $table->initialize([20, 30, 40, 50]); $header1 = PdfSettings::headerRow(); @@ -31,7 +30,7 @@ $header2 = PdfSettings::headerRow(); $header3 = PdfSettings::headerRow(); -$header2[1]['TEXT'] = "Colspan/Rowspan in Header"; +$header2[1]['TEXT'] = 'Colspan/Rowspan in Header'; $header2[1]['COLSPAN'] = 2; $header2[1]['ROWSPAN'] = 2; @@ -39,7 +38,6 @@ $table->addHeader($header2); $table->addHeader($header3); - for ($i = 0; $i < 8; $i++) { $row = PdfSettings::dataRow(); @@ -68,7 +66,6 @@ $row[1]['ROWSPAN'] = 2; } - $table->addRow($row); } diff --git a/examples/Tfpdf/table_example1.php b/examples/Tfpdf/table_example1.php index 4ab6ea3..64b9cd8 100644 --- a/examples/Tfpdf/table_example1.php +++ b/examples/Tfpdf/table_example1.php @@ -9,7 +9,7 @@ //Table Header for ($i = 0; $i < $columns; $i++) { - $header[$i]['TEXT'] = "Header #" . ($i + 1); + $header[$i]['TEXT'] = 'Header #' . ($i + 1); } //add the header @@ -24,7 +24,6 @@ $row[2]['TEXT'] = "Line $j Text 3"; //text for column 2 $row[2]['TEXT_ALIGN'] = 'R'; //text align - //add the row $table->addRow($row); //break; diff --git a/examples/Tfpdf/table_example2.php b/examples/Tfpdf/table_example2.php index 78fbae4..db84276 100644 --- a/examples/Tfpdf/table_example2.php +++ b/examples/Tfpdf/table_example2.php @@ -9,7 +9,7 @@ //Table Header for ($i = 0; $i < $columns; $i++) { - $header[$i]['TEXT'] = "Header #" . ($i + 1); + $header[$i]['TEXT'] = 'Header #' . ($i + 1); } $table->addHeader($header); @@ -56,21 +56,21 @@ } if ($j == 7) { - $row[1]['TEXT'] = "Top Left Align"; + $row[1]['TEXT'] = 'Top Left Align'; $row[1]['VERTICAL_ALIGN'] = 'T'; $row[1]['TEXT_ALIGN'] = 'L'; - $row[2]['TEXT'] = "Bottom Right Align"; + $row[2]['TEXT'] = 'Bottom Right Align'; $row[2]['VERTICAL_ALIGN'] = 'B'; $row[2]['TEXT_ALIGN'] = 'R'; } if ($j == 8) { - $row[1]['TEXT'] = "Top Center Align"; + $row[1]['TEXT'] = 'Top Center Align'; $row[1]['VERTICAL_ALIGN'] = 'T'; $row[1]['TEXT_ALIGN'] = 'C'; - $row[2]['TEXT'] = "Bottom Center Align"; + $row[2]['TEXT'] = 'Bottom Center Align'; $row[2]['VERTICAL_ALIGN'] = 'B'; $row[2]['TEXT_ALIGN'] = 'C'; } @@ -94,7 +94,7 @@ } if ($j == 14) { - $row[1]['TEXT'] = "Cell Properties Overwriting Example"; + $row[1]['TEXT'] = 'Cell Properties Overwriting Example'; $row[1]['TEXT_FONT'] = 'Times'; $row[1]['TEXT_SIZE'] = 7; $row[1]['TEXT_TYPE'] = 'B'; diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..d9a2b6a --- /dev/null +++ b/pint.json @@ -0,0 +1,20 @@ +{ + "preset": "laravel", + "rules": { + "php_unit_method_casing": false, + "concat_space": { + "spacing": "one" + }, + "binary_operator_spaces": { + "default": "single_space" + }, + "phpdoc_align": { + "align": "left" + }, + "class_attributes_separation": { + "elements": { + "method": "one" + } + } + } +} diff --git a/sonar-project.properties b/sonar-project.properties index 1a7ff04..569ce5f 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -11,3 +11,4 @@ sonar.organization=evosys21 # Encoding of the source code. Default is default system encoding #sonar.sourceEncoding=UTF-8 +sonar.cpd.exclusions=**/dev/*.php,**/examples/*.php diff --git a/src/AbstractPdfUtils.php b/src/AbstractPdfUtils.php index e12970b..a92bc97 100644 --- a/src/AbstractPdfUtils.php +++ b/src/AbstractPdfUtils.php @@ -4,14 +4,11 @@ /** * Pdf Class Interface - * */ abstract class AbstractPdfUtils { /** * Tags Font Information - * - * @var array */ public array $fontInfo; } diff --git a/src/Fpdf/Pdf.php b/src/Fpdf/Pdf.php index afe6bac..5f535ee 100644 --- a/src/Fpdf/Pdf.php +++ b/src/Fpdf/Pdf.php @@ -14,7 +14,6 @@ * extended and these properties made public. * * In all subclasses we refer to Pdf class and not FPDF. - * */ class Pdf extends FPDF { @@ -82,7 +81,7 @@ public function Cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $ public function saveToFile($fileName) { - $this->Output("F", $fileName); + $this->Output('F', $fileName); } public function getRTL(): bool diff --git a/src/Fpdf/PdfInterface.php b/src/Fpdf/PdfInterface.php index abc831d..f1512bf 100644 --- a/src/Fpdf/PdfInterface.php +++ b/src/Fpdf/PdfInterface.php @@ -15,7 +15,6 @@ /** * Pdf Class Interface - * */ class PdfInterface extends AbstractPdfUtils implements PdfInterfaceDef { @@ -31,7 +30,6 @@ class PdfInterface extends AbstractPdfUtils implements PdfInterfaceDef protected $backupDrawColor; public $textColor; - public function __construct($pdf) { $this->pdf = $pdf; @@ -39,24 +37,20 @@ public function __construct($pdf) /** * Returns the PDF object of the Interface - * - * @return Pdf */ public function getPdfObject(): Pdf { return $this->pdf; } - /** * Returns the page width */ public function getPageWidth(): int { - return (int)$this->pdf->w - $this->pdf->rMargin - $this->pdf->lMargin; + return (int) $this->pdf->w - $this->pdf->rMargin - $this->pdf->lMargin; } - /** * Returns the current X position * @@ -67,7 +61,6 @@ public function getX() return $this->pdf->GetX(); } - /** * Returns the remaining width to the end of the current line * @@ -84,7 +77,6 @@ public function getRemainingWidth() return $n; } - /** * Split string into array of equivalent codes and return the result array * @@ -103,7 +95,6 @@ public function stringToArray(string $str): array return $aResult; } - /** * Returns the active font family * @@ -114,7 +105,6 @@ public function getFontFamily(): string return $this->pdf->FontFamily; } - /** * Returns the active font style * @@ -125,7 +115,6 @@ public function getFontStyle(): string return $this->pdf->FontStyle; } - /** * Returns the active font size in PT * @@ -136,7 +125,6 @@ public function getFontSizePt() return $this->pdf->FontSizePt; } - /** * Adds an image to the pdf document * @@ -153,7 +141,6 @@ public function Image($file, $x = null, $y = null, $w = 0, $h = 0, $type = '', $ $this->pdf->Image($file, $x, $y, $w, $h, $type, $link); } - /** * Returns the image width and height in PDF values! * @@ -168,7 +155,7 @@ public function getImageParams($file, $w = 0, $h = 0): array $w = floatval($w); // Put an image on the page - if (!isset($this->pdf->images[$file])) { + if (! isset($this->pdf->images[$file])) { $pos = strrpos($file, '.'); $type = substr($file, $pos + 1); $type = strtolower($type); @@ -176,7 +163,7 @@ public function getImageParams($file, $w = 0, $h = 0): array $type = 'jpg'; } $mtd = '_parse' . $type; - if (!method_exists($this->pdf, $mtd)) { + if (! method_exists($this->pdf, $mtd)) { debug_print_backtrace(); $this->pdf->Error('Unsupported image type: ' . $type); } @@ -206,15 +193,15 @@ public function getImageParams($file, $w = 0, $h = 0): array $h = $w * $info['h'] / $info['w']; } - return array( + return [ $w, - $h - ); + $h, + ]; } /** * Wrapper for the cell function - * @param $w + * * @param int $h * @param string $txt * @param int $border @@ -231,7 +218,6 @@ public function Cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $ /** * Sets the PDF TextColor * - * @param $color * @return $this */ public function setTextColor($color): self @@ -241,17 +227,18 @@ public function setTextColor($color): self if (is_string($color) && str_starts_with($color, self::RAW)) { $this->pdf->TextColor = substr($color, strlen(self::RAW)); $this->pdf->ColorFlag = ($this->pdf->FillColor != $this->pdf->TextColor); + return $this; } $colorData = Tools::parseColor($color); call_user_func_array([$this->pdf, 'SetTextColor'], $colorData); + return $this; } /** * Sets the PDF DrawColor * - * @param $color * @return $this */ public function setDrawColor($color): self @@ -259,15 +246,18 @@ public function setDrawColor($color): self $this->backupDrawColor = $this->pdf->DrawColor; if (is_string($color) && str_starts_with($color, self::RAW)) { $this->pdf->DrawColor = substr($color, strlen(self::RAW)); + return $this; } $colorData = Tools::parseColor($color); call_user_func_array([$this->pdf, 'SetDrawColor'], $colorData); + return $this; } /** * Restores the DrawColor from the backup + * * @return $this */ public function restoreDrawColor(): self @@ -276,6 +266,7 @@ public function restoreDrawColor(): self $this->pdf->DrawColor = $this->backupDrawColor; $this->pdf->_out($this->pdf->DrawColor); } + return $this; } @@ -295,10 +286,7 @@ public function setEncoding() /** * Returns the Available Width to draw the Text. * - * @param string $str - * @param int $start * @param int|float|null $length - * @return string */ public function substr(string $str, int $start, $length = null): string { @@ -318,7 +306,7 @@ public function getCharStringWidth($tag, $char, $fontFamily, $fontStyle, $fontSi { // apply the styles if (str_contains($fontSize, '%')) { - $fontSize = $this->pdf->FontSizePt * (((float)$fontSize) / 100); + $fontSize = $this->pdf->FontSizePt * (((float) $fontSize) / 100); } $this->pdf->SetFont($fontFamily, $fontStyle, $fontSize); @@ -326,7 +314,6 @@ public function getCharStringWidth($tag, $char, $fontFamily, $fontStyle, $fontSi $width = &$this->pdf->CurrentFont['cw']; //width $size = &$this->pdf->FontSize; //size - return $width[chr($char)] * $size / 1000; } } diff --git a/src/Multicell.php b/src/Multicell.php index 836368b..c0cdf4c 100644 --- a/src/Multicell.php +++ b/src/Multicell.php @@ -3,9 +3,10 @@ /** @noinspection PhpUnhandledExceptionInspection */ /** @noinspection PhpDocMissingThrowsInspection */ + namespace EvoSys21\PdfLib; -if (!defined('PARAGRAPH_STRING')) { +if (! defined('PARAGRAPH_STRING')) { define('PARAGRAPH_STRING', '~~~'); } @@ -26,6 +27,7 @@ class Multicell /** * Set to 1 to debug cell borders + * * @var int */ public $cellBorders = 0; @@ -40,7 +42,7 @@ class Multicell /** * Valid Tag Maximum Width * - * @var integer + * @var int */ protected $tagWidthMax = 25; @@ -76,7 +78,7 @@ class Multicell /** * == true if a tag was more times defined. * - * @var boolean + * @var bool */ protected $doubleTags = false; @@ -91,7 +93,6 @@ class Multicell * PDF Interface Object * * @var PdfInterface - * */ protected $pdfi; @@ -127,19 +128,16 @@ public function __construct($pdf) /** * Reset the multicell options - * @return self */ public function reset(): self { $this->options->resetCellOptions(); + return $this; } - /** * Returns the PDF object - * - * @return object|null */ public function getPdfObject(): ?object { @@ -148,33 +146,28 @@ public function getPdfObject(): ?object /** * Returns the Pdf Interface Object - * - * @return Object */ public function getPdfInterfaceObject(): object { return $this->pdfi; } - /** * Returns the Singleton Instance of this class. * * @param $pdf Object of the pdf class - * @return self */ public static function getInstance(object $pdf): self { $instance = &self::$singleton[spl_object_hash($pdf)]; - if (!isset($instance)) { + if (! isset($instance)) { $instance = new self($pdf); } return $instance; } - /** * Sets the list of characters that will allow a line-breaking * @@ -185,7 +178,6 @@ public function setLineBreakingCharacters(string $string) $this->lineBreakingChars = $string; } - /** * Resets the list of characters that will allow a line-breaking */ @@ -194,7 +186,6 @@ public function resetLineBreakingCharacters() $this->lineBreakingChars = self::SEPARATOR; } - /** * Sets the attributes for the specified tag * @@ -204,15 +195,14 @@ public function resetLineBreakingCharacters() * @param string|array|null $color * @param string|null $fontFamily font family * @param string $inherit Tag to be inherited - * @return self */ - public function setStyle(string $tag, $fontSize = null, ?string $fontStyle = null, $color = null, ?string $fontFamily = null, string $inherit = ""): self + public function setStyle(string $tag, $fontSize = null, ?string $fontStyle = null, $color = null, ?string $fontFamily = null, string $inherit = ''): self { if ($tag == 'ttags') { - $this->pdf->Error(">> ttags << is reserved TAG Name."); + $this->pdf->Error('>> ttags << is reserved TAG Name.'); } if ($tag == '') { - $this->pdf->Error("Empty TAG Name."); + $this->pdf->Error('Empty TAG Name.'); } //use case insensitive tags @@ -237,6 +227,7 @@ public function setStyle(string $tag, $fontSize = null, ?string $fontStyle = nul } $this->options->styles[$tag] = $tagData; + return $this; } @@ -247,7 +238,7 @@ public function setStyle(string $tag, $fontSize = null, ?string $fontStyle = nul * @param array $properties Tag properties * @param string $inherit Tag to inherit */ - public function setStyleAssoc(string $tag, array $properties = [], $inherit = "") + public function setStyleAssoc(string $tag, array $properties = [], $inherit = '') { $this->setStyle( $tag, @@ -269,7 +260,6 @@ public function setTagWidthMax(int $width = 25) $this->tagWidthMax = $width; } - /** * Resets the current class internal variables to default values */ @@ -279,18 +269,17 @@ protected function resetData() //@formatter:off $this->dataInfo = []; - $this->dataExtraInfo = array( - "LAST_LINE_BR" => '', //CURRENT LINE BREAK TYPE - "CURRENT_LINE_BR" => '', //LAST LINE BREAK TYPE - "TAB_WIDTH" => 10 - ); //The tab WIDTH IS IN mm + $this->dataExtraInfo = [ + 'LAST_LINE_BR' => '', //CURRENT LINE BREAK TYPE + 'CURRENT_LINE_BR' => '', //LAST LINE BREAK TYPE + 'TAB_WIDTH' => 10, + ]; //The tab WIDTH IS IN mm //@formatter:on //if another measure unit is used ... calculate your OWN - $this->dataExtraInfo["TAB_WIDTH"] *= (72 / 25.4) / $this->pdf->k; + $this->dataExtraInfo['TAB_WIDTH'] *= (72 / 25.4) / $this->pdf->k; } - /** * Returns the specified tag font family * @@ -302,7 +291,6 @@ public function getTagFont(string $tag): string return $this->getTagAttribute($tag, 'family'); } - /** * Returns the specified tag font style * @@ -314,7 +302,6 @@ public function getTagFontStyle(string $tag): string return $this->getTagAttribute($tag, 'style'); } - /** * Returns the specified tag font size * @@ -326,7 +313,6 @@ public function getTagSize(string $tag): string return $this->getTagAttribute($tag, 'size'); } - /** * Returns the specified tag text color * @@ -338,13 +324,13 @@ public function getTagColor(string $tag) return $this->getTagAttribute($tag, 'color'); } - /** * Returns the attribute the specified tag * * @param string $tag tag name * @param string $attribute attribute name * @return mixed + * * @throws Exception */ protected function getTagAttribute(string $tag, string $attribute) @@ -357,7 +343,7 @@ protected function getTagAttribute(string $tag, string $attribute) $tags[] = static::PDF_CURRENT; foreach ($tags as $oneTag) { $val = $this->getOneTagAttribute($oneTag, $attribute); - if (!is_null($val)) { + if (! is_null($val)) { return $val; } } @@ -394,7 +380,6 @@ protected function getOneTagAttribute(string $tag, string $attribute) return null; } - /** * Sets the styles from the specified tag active. * Font family, style, size and text color. @@ -402,7 +387,6 @@ protected function getOneTagAttribute(string $tag, string $attribute) * If the tag is not found then the DEFAULT tag is being used * * @param string $tag tag name - * @param array $style */ protected function applyStyle(string $tag, array $style = []) { @@ -417,16 +401,16 @@ protected function applyStyle(string $tag, array $style = []) $fontFamily = $this->getTagFont($tag); $fontStyle = $this->getTagFontStyle($tag); $color = Tools::getValue($style, 'color'); - if (!$color) { + if (! $color) { $color = $this->getTagColor($tag); } $fontSize = intval(Tools::getValue($style, 'font-size')); - if (!$fontSize) { + if (! $fontSize) { $fontSize = $this->getTagSize($tag); } if (str_contains($fontSize, '%')) { - $fontSize = $this->pdf->FontSizePt * (((float)$fontSize) / 100); + $fontSize = $this->pdf->FontSizePt * (((float) $fontSize) / 100); } $this->pdf->SetFont($fontFamily, $fontStyle, $fontSize); @@ -443,15 +427,15 @@ protected function getSpacer($line) return $spacer; } } + return []; } - /** * Divides $this->dataInfo and returns a line from this variable * - * @param $width * @return array $aLine - array() -> contains information to draw a line + * * @internal param number $width the width of the cell */ protected function makeLine($width, $line): array @@ -508,7 +492,7 @@ protected function makeLine($width, $line): array $this->pdfi->fontInfo[$tag] = [ 'CurrentFont' => &$this->pdf->CurrentFont, - 'FontSize' => $this->pdf->FontSize + 'FontSize' => $this->pdf->FontSize, ]; if (property_exists($this->pdf, 'unifontSubset')) { @@ -550,14 +534,14 @@ protected function makeLine($width, $line): array } //space - if ($c == ord(" ")) { + if ($c == ord(' ')) { $spaces++; } $char_width = $this->mt_getCharWidth($tag, $c); //separators - if (!$nowrap && in_array($c, array_map('ord', str_split($this->lineBreakingChars)))) { + if (! $nowrap && in_array($c, array_map('ord', str_split($this->lineBreakingChars)))) { $anteSeparatorPosition = $lastSeparatorPosition; $anteSeparatorWitdh = $lastSeparator; $anteSeparatorCharWidth = $lastSeparatorWidth; @@ -600,11 +584,10 @@ protected function makeLine($width, $line): array break; } - if ($lastSeparatorPosition != -1) { //we have a separator in this tag!!! //until now there one separator - if (($lastSeparator == $c) && ($lastSeparator != ord(" ")) && ($anteSeparatorPosition != -1)) { + if (($lastSeparator == $c) && ($lastSeparator != ord(' ')) && ($anteSeparatorPosition != -1)) { /* * this is the last character and it is a separator, if it is a space the leave it... Have to jump back to the last separator... even a space */ @@ -613,7 +596,7 @@ protected function makeLine($width, $line): array $lastSeparatorWidth = $anteSeparatorCharWidth; } - if ($lastSeparator == ord(" ")) { + if ($lastSeparator == ord(' ')) { $j = $lastSeparatorPosition; //just ignore the last space (it is at end of line) $i = $lastSeparatorPosition + 1; if ($spaces > 0) { @@ -627,7 +610,7 @@ protected function makeLine($width, $line): array } } elseif (count($lineData) > 0) { //we have elements in the last tag!!!! - if ($lastSeparator == ord(" ")) { //the last tag ends with a space, have to remove it + if ($lastSeparator == ord(' ')) { //the last tag ends with a space, have to remove it $temp = &$lineData[count($lineData) - 1]; if (' ' == $this->strChar($temp['text'], -1)) { @@ -644,12 +627,10 @@ protected function makeLine($width, $line): array } } - $returnResult = true; break; } - //increase the string width ONLY when it is added!!!! $currentWidth += $char_width; @@ -658,7 +639,6 @@ protected function makeLine($width, $line): array $totalChars++; } - $str = $this->substr($s, 0, $j); $sTmpStr = $this->dataInfo[0]['text']; @@ -680,7 +660,7 @@ protected function makeLine($width, $line): array 'width_real' => $currentWidth, 'width' => $currentWidth, 'spaces' => $spaces, - 'y' => $y + 'y' => $y, ], $cellData); if (isset($val['width'])) { @@ -691,7 +671,6 @@ protected function makeLine($width, $line): array //we have a partial result $lineData[] = $cellData; - $this->tempData['LAST_TAB_SIZE'] = $currentWidth; $this->tempData['LAST_TAB_REQSIZE'] = (isset($val['size'])) ? $val['size'] : 0; @@ -700,25 +679,24 @@ protected function makeLine($width, $line): array } //break this for } - // Check the first and last tag -> if first and last caracters are " " space remove them!!!" if ((count($lineData) > 0) && ($this->dataExtraInfo['LAST_LINE_BR'] == 'AUTO')) { // first tag // If the first character is a space, then cut it off $temp = &$lineData[0]; - if (($this->strlen($temp['text']) > 0) && (" " == $this->strChar($temp['text'], 0))) { + if (($this->strlen($temp['text']) > 0) && (' ' == $this->strChar($temp['text'], 0))) { $temp['text'] = $this->substr($temp['text'], 1, $this->strlen($temp['text'])); - $temp['width'] -= $this->mt_getCharWidth($temp['tag'], ord(" ")); - $temp['width_real'] -= $this->mt_getCharWidth($temp['tag'], ord(" ")); + $temp['width'] -= $this->mt_getCharWidth($temp['tag'], ord(' ')); + $temp['width_real'] -= $this->mt_getCharWidth($temp['tag'], ord(' ')); $temp['spaces']--; } // If the last character is a space, then cut it off $temp = &$lineData[count($lineData) - 1]; - if (($this->strlen($temp['text']) > 0) && (" " == $this->strChar($temp['text'], -1))) { + if (($this->strlen($temp['text']) > 0) && (' ' == $this->strChar($temp['text'], -1))) { $temp['text'] = $this->substr($temp['text'], 0, $this->strlen($temp['text']) - 1); - $temp['width'] -= $this->mt_getCharWidth($temp['tag'], ord(" ")); - $temp['width_real'] -= $this->mt_getCharWidth($temp['tag'], ord(" ")); + $temp['width'] -= $this->mt_getCharWidth($temp['tag'], ord(' ')); + $temp['width_real'] -= $this->mt_getCharWidth($temp['tag'], ord(' ')); $temp['spaces']--; } } @@ -733,14 +711,12 @@ protected function makeLine($width, $line): array return $lineData; } - /** * Draws a MultiCell with a TAG Based Formatted String as an Input * * * @param float $width width of the cell * @param float $height height of the lines in the cell - * @param $data * @param string|int $border * @param string $align Sets the text alignment Possible values: L: left R: right C: center J: justified * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0. @@ -760,7 +736,7 @@ public function multiCell( float $paddingTop = 0, float $paddingRight = 0, float $paddingBottom = 0, - float $minHeight = 0 + float $minHeight = 0 ) { $this->multicellData = new MulticellData($this->pdf); $this->multicellData->width = $width; @@ -803,7 +779,7 @@ public function multiCell( //Number of rows that have space on this page: $rows = floor($iLeftHeight / $height); // Added check for 'AcceptPageBreak' - if (count($lines) > $rows && $this->pdf->AcceptPageBreak() && !$this->options->disablePageBreak) { + if (count($lines) > $rows && $this->pdf->AcceptPageBreak() && ! $this->options->disablePageBreak) { $printLines = array_slice($lines, 0, $rows); $lines = array_slice($lines, $rows); $addPage = true; @@ -812,7 +788,7 @@ public function multiCell( $doBreak = true; } - if (!is_null($this->multicellData)) { + if (! is_null($this->multicellData)) { $this->multiCellSec($this->multicellData, $printLines); } @@ -829,13 +805,13 @@ public function multiCell( $this->multicellData = null; } - /** * Draws a MultiCell with TAG recognition parameters * * * @param $multicellData MulticellData * @param $data string|array + * * @internal param \or $string number $border Indicates if borders must be drawn around the cell block. * The value can be either a number: 0 = no border 1 = frame border or a string containing some or all of * the following characters (in any order): L: left T: top R: right B: bottom @@ -879,10 +855,10 @@ public function multiCellSec(MulticellData $multicellData, $data) $bFirstLine = true; - $bLastLine = !(count($data) > 0); + $bLastLine = ! (count($data) > 0); $line = 0; - while (!$bLastLine) { + while (! $bLastLine) { $line++; if ($bFirstLine && ($multicellData->paddingTop > 0)) { /** @@ -905,7 +881,7 @@ public function multiCellSec(MulticellData $multicellData, $data) //make a line $str_data = array_shift($data); //check for last line - $bLastLine = !(count($data) > 0); + $bLastLine = ! (count($data) > 0); if ($bLastLine && ($align == 'J')) { //do not Justify the Last Line $align = 'L'; @@ -963,7 +939,6 @@ public function multiCellSec(MulticellData $multicellData, $data) $this->pdf->x = $this->pdf->lMargin; } - /** * This method divides the string into the tags and puts the result into dataInfo variable. * @@ -992,7 +967,6 @@ protected function divideByTags(?string $string) /** * This method parses the current text and return an array that contains the text information for each line that will be drawn. * - * @param MulticellData $multicellData * @return array $aStrLines - contains parsed text information. */ public function stringToLines(MulticellData $multicellData): array @@ -1012,13 +986,13 @@ public function stringToLines(MulticellData $multicellData): array $dataInfo = $this->dataInfo; - $lastLine = !(count($this->dataInfo) > 0); + $lastLine = ! (count($this->dataInfo) > 0); $parsedLines = []; $lines = 0; $shrinkRun = 0; - while (!$lastLine) { + while (! $lastLine) { $lines++; $height = $lines * $multicellData->lineHeight; @@ -1026,7 +1000,7 @@ public function stringToLines(MulticellData $multicellData): array $str_data = $this->makeLine($multicellData->textWidth, $lines); $parsedLines[] = $str_data; - #1247 - limit the maximum number of lines + //1247 - limit the maximum number of lines if ($options->isHeightOverflow($lines, $height)) { if ($shrinkRun++ > 20) { break; //avoid infinite loop @@ -1038,6 +1012,7 @@ public function stringToLines(MulticellData $multicellData): array $multicellData->lineHeight = $options->shrinkValue($multicellData->lineHeight, $options->shrinkLineHeightStep); $this->dataInfo = $dataInfo; $this->currentTag = '__UNDEFINED__'; + continue; } else { break; @@ -1045,13 +1020,13 @@ public function stringToLines(MulticellData $multicellData): array } //check for last line - $lastLine = !(count($this->dataInfo) > 0); + $lastLine = ! (count($this->dataInfo) > 0); } // //APPLY THE DEFAULT STYLE // $this->applyStyle(static::DEFAULT_TAG); - if (!$options->applyAll) { + if (! $options->applyAll) { $this->reset(); } @@ -1136,7 +1111,6 @@ protected function printLine($width, $height, array $data, string $align = 'J') continue; } // No width jump over!!! - if ($align == 'J') { if ($val['spaces'] < 1) { $temp_X = 0; @@ -1192,13 +1166,11 @@ protected function printLine($width, $height, array $data, string $align = 'J') $last_width -= $width; //last column width - if ($extra_X != 0) { $this->pdf->SetX($this->pdf->GetX() + $extra_X); $last_width -= $extra_X; } - if ($bYPosUsed) { $this->pdf->y = $lastY; } @@ -1210,7 +1182,6 @@ protected function printLine($width, $height, array $data, string $align = 'J') } } - /** * Function executed BEFORE a new page is added for further actions on the current page. * Usually overwritten. @@ -1222,7 +1193,6 @@ public function beforeAddPage() */ } - /** * Function executed AFTER a new page is added for pre - actions on the current page. * Usually overwritten. @@ -1234,7 +1204,6 @@ public function afterAddPage() */ } - /** * Returns the Width of the Specified Char. * The Font Style / Size are taken from the tag specifications! @@ -1254,14 +1223,11 @@ protected function mt_getCharWidth(string $tag, string $char) ); } - /** * Returns the Available Width to draw the Text. * - * @param float $width - * @param float $paddingLeft - * @param float $paddingRight * @return float the width + * * @noinspection PhpUnused */ protected function mt_getAvailableTextWidth(float $width, float $paddingLeft = 0, float $paddingRight = 0): float @@ -1285,133 +1251,114 @@ protected function mt_getAvailableTextWidth(float $width, float $paddingLeft = 0 /** * Returns the character found in the string at the specified position - * - * @param string $string - * @param int $position - * @return string */ protected function strChar(string $string, int $position): string { return $this->substr($string, $position, 1); } - /** * Get string length - * - * @param string $sStr - * @return int */ public function strlen(string $sStr): int { return $this->pdfi->strlen($sStr); } - /** * Return part of a string * - * @param string $str * @param number $start * @param number $length - * @return string */ public function substr(string $str, $start, $length = null): string { return $this->pdfi->substr($str, $start, $length); } - /** * Enable or disable background fill. * - * @param boolean $value * @return $this */ public function enableFill(bool $value): self { $this->fill = $value; + return $this; } /** - * @param int $maxLines * @return $this + * * @noinspection PhpUnused */ public function setMaxLines(int $maxLines): self { $this->maxLines($maxLines - 1); + return $this; } /** - * @param int $maxLines * @return $this */ public function maxLines(int $maxLines): self { $this->options->maxLines = $maxLines; + return $this; } - /** - * @param int $maxHeight - * @return self - */ public function maxHeight(int $maxHeight): self { $this->options->maxHeight = $maxHeight; + return $this; } - /** - * @param bool $shrinkToFit - * @return self - */ public function shrinkToFit(bool $shrinkToFit = true): self { $this->options->shrinkToFit = $shrinkToFit; + return $this; } /** * @param int|float $step - * @return self + * * @noinspection PhpUnused */ public function shrinkFontStep($step = 1): self { $this->options->shrinkFontStep = $step; + return $this; } /** * @param int|float $step - * @return self + * * @noinspection PhpUnused */ public function shrinkLineHeightStep($step): self { $this->options->shrinkLineHeightStep = $step; + return $this; } - /** - * @return self - */ public function applyAll(): self { $this->options->applyAll = true; + return $this; } - /** * Returns the strike tag value. * If "strike" is specified in the tag and it has a value the value specifies the line width * - * @param $val * @return bool|mixed */ protected function getStrikeValue($val) @@ -1420,6 +1367,7 @@ protected function getStrikeValue($val) if (empty($val['strike'])) { return true; } + return $val['strike']; } @@ -1453,13 +1401,14 @@ public function setSpacers($from, $to, $left = 0, $right = 0): self public function resetSpacers(): self { $this->options->spacers = []; + return $this; } public function disablePageBreak(bool $disablePageBreak = true): self { $this->options->disablePageBreak = $disablePageBreak; + return $this; } - } diff --git a/src/MulticellData.php b/src/MulticellData.php index 56cf138..6a4e2d7 100644 --- a/src/MulticellData.php +++ b/src/MulticellData.php @@ -9,18 +9,21 @@ class MulticellData { /** * Contains the line height value for a multicell + * * @var int|float */ public $lineHeight; /** * Contains the width of the multicell + * * @var int|float */ public $width; /** * Contains the width of the text (without the paddings) + * * @var int|float */ public $textWidth; @@ -74,8 +77,6 @@ public function __construct($pdf) /** * Calculates the text width - * - * @return self */ public function initialize(): self { @@ -94,6 +95,7 @@ public function initialize(): self //read width of the text $this->textWidth = $this->width - $this->paddingLeft - $this->paddingRight; + return $this; } } diff --git a/src/MulticellOptions.php b/src/MulticellOptions.php index 5a5b293..5fb047c 100644 --- a/src/MulticellOptions.php +++ b/src/MulticellOptions.php @@ -20,19 +20,22 @@ class MulticellOptions /** * The maximum number of lines allowed + * * @var int */ public $maxLines = 0; /** * The maximum height allowed + * * @var int */ public $maxHeight = 0; /** * Shrink text to fit - * @var boolean + * + * @var bool */ public $shrinkToFit = false; @@ -53,18 +56,11 @@ class MulticellOptions /** * Contains the line height value for a multicell - * @var int|float */ public int|float $lineHeight; - /** - * @var object - */ public object $pdf; - /** - * @var object - */ public object $pdfi; public function __construct($pdfi) @@ -85,56 +81,51 @@ public function isHeightOverflow($lines, $height): bool if ($maxHeight > 0 && $height > $maxHeight) { return true; } + return false; } - /** * Save the TagStyles to a backup variable - * @return self */ public function saveStyles(): self { $this->stylesBackup = $this->styles; + return $this; } /** * Restore the used TagStyles from backup - * - * @return self */ public function restoreStyles(): self { if ($this->stylesBackup) { $this->styles = $this->stylesBackup; } + return $this; } /** * Shrink all font-sizes by the specified step - * - * @return self */ public function shrinkStyleFonts(): self { foreach ($this->styles as &$style) { - if (!isset($style['size'])) { + if (! isset($style['size'])) { continue; } $style['size'] = $this->shrinkValue($style['size'], $this->shrinkFontStep); } unset($style); + return $this; } /** * Shrinks a value by the specified step, but not lower than the $minValue into account * - * @param $value - * @param $step - * @param int $minValue * @return int|mixed */ public function shrinkValue($value, $step, int $minValue = 1) @@ -143,13 +134,12 @@ public function shrinkValue($value, $step, int $minValue = 1) if ($value < $minValue) { return $minValue; } + return $value; } /** * Save the current pdf settings as "current" style - * - * @return self */ public function saveCurrentStyle(): self { @@ -159,6 +149,7 @@ public function saveCurrentStyle(): self $this->styles[$current]['style'] = $this->pdfi->getFontStyle(); $this->styles[$current]['size'] = $this->pdfi->getFontSizePt(); $this->styles[$current]['color'] = PdfInterface::RAW . $this->pdf->TextColor; + return $this; } @@ -170,6 +161,7 @@ public function resetCellOptions(): self $this->shrinkLineHeightStep = 0.5; $this->shrinkToFit = false; $this->applyAll = false; + return $this; } } diff --git a/src/PdfInterfaceDef.php b/src/PdfInterfaceDef.php index 79aaa8c..389bf94 100644 --- a/src/PdfInterfaceDef.php +++ b/src/PdfInterfaceDef.php @@ -3,11 +3,9 @@ namespace EvoSys21\PdfLib; use EvoSys21\PdfLib\Fpdf\Pdf; -use EvoSys21\PdfLib\Tools; /** * Pdf Class Interface - * */ interface PdfInterfaceDef { diff --git a/src/String/Tags.php b/src/String/Tags.php index c20300d..5af2976 100644 --- a/src/String/Tags.php +++ b/src/String/Tags.php @@ -25,11 +25,10 @@ class Tags /** * The maximum number of chars for a tag * - * @var integer + * @var int */ protected $maxLength; - /** * Constructor * @@ -42,13 +41,11 @@ public function __construct(int $maxLength = 10) $this->maxLength = $maxLength; } - /** * Returns TRUE if the specified tag name is an "", (it is not already opened) * * @param string $tag - tag name * @param array $data - tag arrays - * @return boolean */ protected function isOpenTag(string $tag, array $data): bool { @@ -56,7 +53,7 @@ protected function isOpenTag(string $tag, array $data): bool $hRef = &$this->hRef; $maxElem = &$this->maxLength; - if (!preg_match("/^<([a-zA-Z\d]{1,$maxElem}) *(.*)>$/i", $tag, $reg)) { + if (! preg_match("/^<([a-zA-Z\d]{1,$maxElem}) *(.*)>$/i", $tag, $reg)) { return false; } @@ -81,12 +78,10 @@ protected function isOpenTag(string $tag, array $data): bool return false; } - /** * Returns true if $tag is a "" * * @param string $tag tag name - * @return boolean */ protected function isCloseTag(string $tag): bool { @@ -94,7 +89,7 @@ protected function isCloseTag(string $tag): bool $hRef = &$this->hRef; $maxElem = $this->maxLength; - if (!preg_match("/^<\/([a-zA-Z\d]{1,$maxElem})>$/i", $tag, $reg)) { + if (! preg_match("/^<\/([a-zA-Z\d]{1,$maxElem})>$/i", $tag, $reg)) { return false; } @@ -110,12 +105,8 @@ protected function isCloseTag(string $tag): bool return false; } - /** * Expands the parameters that are kept in Href field - * - * @param array $data - * @return array */ protected function expandParams(array $data): array { @@ -131,7 +122,6 @@ protected function expandParams(array $data): array return $data; } - /** * Optimizes the result of the tag result array In the result array there can be strings that are consecutive and have the same tag, they are concatenated. * @@ -167,7 +157,6 @@ protected function optimizeTags(array $result): array return $res_result; } - /** * Parses a string and returns an array of TAG - STRING correspondent array * The result has the following structure: [ array (string1, tag1), array (string2, tag2), ... etc ] diff --git a/src/Table.php b/src/Table.php index 7813d51..1aa28b4 100644 --- a/src/Table.php +++ b/src/Table.php @@ -1,20 +1,15 @@ EmptyCell::class, 'MULTICELL' => \EvoSys21\PdfLib\Table\Cell\Multicell::class, 'IMAGE' => Image::class, 'IMAGESVG' => ImageSVG::class, - ); + ]; /** * If set to true then page-breaks will be disabled @@ -298,16 +287,15 @@ class Table /** * Configuration file path + * * @var string|null */ protected $configFile = null; - /** * Class constructor. * * @param $pdf object Instance of the PDF class - * @param string|null $configFile */ public function __construct(object $pdf, ?string $configFile = 'table.config.php') { @@ -326,25 +314,22 @@ public function __construct(object $pdf, ?string $configFile = 'table.config.php $this->pdfi->setEncoding(); } - /** * Returnes the Singleton Instance of this class. * * @param $pdf object the pdf Object - * @return self */ public static function getInstance($pdf): Table { $oInstance = &self::$singleton[spl_object_hash($pdf)]; - if (!isset($oInstance)) { + if (! isset($oInstance)) { $oInstance = new self($pdf); } return $oInstance; } - /** * Returns the Multicell instance * @@ -355,12 +340,8 @@ public function getMulticellInstance() return $this->multicell; } - /** * Table Initialization Function - * - * @param array $columnWidths - * @param array $configuration */ public function initialize(array $columnWidths, array $configuration = []) { @@ -383,7 +364,7 @@ public function initialize(array $columnWidths, array $configuration = []) $this->headerOnCurrentPage = false; foreach ($configuration as $key => $value) { - if (!in_array($key, ['TABLE', 'HEADER', 'ROW'])) { + if (! in_array($key, ['TABLE', 'HEADER', 'ROW'])) { continue; } $this->configuration[$key] = array_merge($this->configuration[$key], $value); @@ -392,7 +373,6 @@ public function initialize(array $columnWidths, array $configuration = []) $this->markMarginX(); } - /** * Closes the table. * This function writes the table content to the PDF Object. @@ -406,7 +386,6 @@ public function close() $this->drawBorder(); } - /** * Set the width of all columns with one function call * @@ -421,20 +400,17 @@ public function setColumnsWidths(array $columnWidths = null) } } - /** * Set the Width for the specified Column * * @param int $columnIndex the column index, 0 based ( first column starts with 0) * @param int|float $width number - * */ public function setColumnWidth(int $columnIndex, $width) { $this->columnWidths[$columnIndex] = $width; } - /** * Get the Width for the specified Column * @@ -443,7 +419,7 @@ public function setColumnWidth(int $columnIndex, $width) */ public function getColumnWidth(int $columnIndex) { - if (!isset($this->columnWidths[$columnIndex])) { + if (! isset($this->columnWidths[$columnIndex])) { trigger_error("Undefined width for column $columnIndex"); return 0; @@ -452,18 +428,16 @@ public function getColumnWidth(int $columnIndex) return $this->columnWidths[$columnIndex]; } - /** * Returns the current page Width * - * @return integer - the Page Width + * @return int - the Page Width */ protected function pageWidth(): int { - return (int)$this->pdf->w - $this->pdf->rMargin - $this->pdf->lMargin; + return (int) $this->pdf->w - $this->pdf->rMargin - $this->pdf->lMargin; } - /** * Returns the current page Height * @@ -471,10 +445,9 @@ protected function pageWidth(): int */ protected function pageHeight() { - return (int)$this->pdf->h - $this->pdf->tMargin - $this->pdf->bMargin; + return (int) $this->pdf->h - $this->pdf->tMargin - $this->pdf->bMargin; } - /** * Sets the Split Mode of the Table. * Default is ON(true) @@ -486,19 +459,16 @@ public function setSplitMode(bool $bSplit = true) $this->tableSplit = $bSplit; } - /** * Enable or disables the header on a new page * * @param $bValue boolean - * */ public function setHeaderNewPage(bool $bValue) { $this->headerOnNewPage = $bValue; } - /** * Adds a Header Row to the table * @@ -522,7 +492,6 @@ public function addHeader(array $headerRow = []) $this->tableHeaderType[] = $headerRow; } - /** * Sets a specific value for a header row * @@ -534,19 +503,18 @@ public function addHeader(array $headerRow = []) public function setHeaderProperty(int $nColumn, string $sPropertyKey, $sPropertyValue, int $nRow = 0) { for ($i = 0; $i <= $nRow; $i++) { - if (!isset($this->tableHeaderType[$i])) { + if (! isset($this->tableHeaderType[$i])) { $this->tableHeaderType[$i] = []; } } - if (!isset($this->tableHeaderType[$nRow][$nColumn])) { + if (! isset($this->tableHeaderType[$nRow][$nColumn])) { $this->tableHeaderType[$nRow][$nColumn] = []; } $this->tableHeaderType[$nRow][$nColumn][$sPropertyKey] = $sPropertyValue; } - /** * Parses the header data and adds the data to the cache * @@ -555,7 +523,7 @@ public function setHeaderProperty(int $nColumn, string $sPropertyKey, $sProperty protected function parseHeader(bool $bForce = false) { //if the header was parsed don't parse it again! - if ($this->headerParsed && !$bForce) { + if ($this->headerParsed && ! $bForce) { return; } @@ -571,7 +539,6 @@ protected function parseHeader(bool $bForce = false) $this->headerHeight(); } - /** * Calculates the Header Height. * If the Header height is bigger than the page height then the script dies. @@ -586,11 +553,10 @@ protected function headerHeight() } if ($this->headerHeight > $this->pageHeight()) { - die("Header Height($this->headerHeight) bigger than Page Height({$this->pageHeight()})"); + exit("Header Height($this->headerHeight) bigger than Page Height({$this->pageHeight()})"); } } - /** * Calculates the X margin of the table depending on the ALIGN */ @@ -611,7 +577,6 @@ protected function markMarginX() }; } - /** * Draws the Table Border */ @@ -621,13 +586,12 @@ public function drawBorder() return; } - if (!$this->dataOnCurrentPage) { + if (! $this->dataOnCurrentPage) { return; } //there was no data on the current page - //set the colors - list($r, $g, $b) = $this->getTableConfig('BORDER_COLOR'); + [$r, $g, $b] = $this->getTableConfig('BORDER_COLOR'); $this->pdf->SetDrawColor($r, $g, $b); if (0 == $this->getTableConfig('BORDER_SIZE')) { @@ -651,7 +615,6 @@ public function drawBorder() ); } - /** * End Page Special Border Draw. * This is called in the case of a Page Split @@ -661,7 +624,7 @@ protected function tbEndPageBorder() if ('' != $this->getTableConfig('BRD_TYPE_END_PAGE')) { if (strpos($this->getTableConfig('BRD_TYPE_END_PAGE'), 'B') >= 0) { //set the colors - list($r, $g, $b) = $this->getTableConfig('BORDER_COLOR'); + [$r, $g, $b] = $this->getTableConfig('BORDER_COLOR'); $this->pdf->SetDrawColor($r, $g, $b); //set the line width @@ -678,11 +641,10 @@ protected function tbEndPageBorder() } } - /** * Returns the table width in user units * - * @return integer - table width + * @return int - table width */ public function getWidth() { @@ -696,7 +658,6 @@ public function getWidth() return $tb_width; } - /** * Aligns the table to the Start X point */ @@ -705,11 +666,9 @@ protected function tbAlign() $this->pdf->SetX($this->tableStartX); } - /** * "Draws the Header". * More specific puts the data from the Header Cache into the Data Cache - * */ public function drawHeader() { @@ -722,7 +681,6 @@ public function drawHeader() $this->headerOnCurrentPage = true; } - /** * Adds a line to the Table Data or Header Cache. * Call this function after the table initialization, table, header and data types are set @@ -731,26 +689,24 @@ public function drawHeader() */ public function addRow(array $rowData = []) { - if (!$this->headerOnCurrentPage) { + if (! $this->headerOnCurrentPage) { $this->drawHeader(); } $this->addDataToCache($rowData); } - /** * Adds a Page Break in the table. */ public function addPageBreak() { - $this->dataCache[] = array( + $this->dataCache[] = [ 'HEIGHT' => 0, - 'DATATYPE' => self::TB_DATA_TYPE_INSERT_NEW_PAGE - ); + 'DATATYPE' => self::TB_DATA_TYPE_INSERT_NEW_PAGE, + ]; } - /** * Applies the default values for a header or data row * @@ -768,7 +724,6 @@ protected function applyDefaultValues(array $aData, string $sDataType): array return array_merge($aReference, $aData); } - /** * Returns the default values * @@ -783,7 +738,6 @@ protected function getDefaultValues(string $sDataType): array }; } - protected function getCellObject($data = null) { if (null === $data) { @@ -794,7 +748,7 @@ protected function getCellObject($data = null) $type = $data['TYPE'] ?? 'MULTICELL'; $type = strtoupper($type); - if (!isset($this->typeMap[$type])) { + if (! isset($this->typeMap[$type])) { trigger_error("Invalid cell type: $type", E_USER_ERROR); } @@ -802,9 +756,9 @@ protected function getCellObject($data = null) $cell = new $class($this->pdf); /** @var $cell CellInterface */ - if (!is_array($data)) { + if (! is_array($data)) { $data = [ - 'TEXT' => $data + 'TEXT' => $data, ]; } $cell->setProperties($data); @@ -817,7 +771,6 @@ protected function getCellObject($data = null) return $cell; } - /** * Adds the data to the cache * @@ -867,15 +820,14 @@ protected function addDataToCache(array $data, string $dataType = 'data') if ($activeColspan > 1) { $cellObject->setSkipped(true); $activeColspan--; + continue; } - if (!empty($dataCache)) { + if (! empty($dataCache)) { //there was at least one row before and was data or header $cell = &$dataCache['DATA'][$i]; /** @var $cell CellInterface */ - - if (isset($cell) && ($cell->getRowSpan() > 1)) { /** * This is rowspan over this cell. @@ -942,21 +894,20 @@ protected function addDataToCache(array $data, string $dataType = 'data') } //@formatter:off - $cache[] = array( + $cache[] = [ 'HEIGHT' => $hm, //the line maximum height 'DATATYPE' => $dataType, //The data Type - Data/Header 'DATA' => $row, //this line's data - 'ROWSPAN' => $rowSpan //rowspan ID array - ); + 'ROWSPAN' => $rowSpan, //rowspan ID array + ]; //@formatter:on //we set the rowspan in cache variable to true if we have a rowspan - if (!empty($rowSpan) && (!$this->rowSpanInCache)) { + if (! empty($rowSpan) && (! $this->rowSpanInCache)) { $this->rowSpanInCache = true; } } - /** * Parses the Data Cache and calculates the maximum Height of each row. * Normally the cell Height of a row is calculated when the data's are added, @@ -981,10 +932,10 @@ protected function cacheParseRowspan(int $iStartIndex = 0, string $sCacheType = $val = &$aRefCache[$ix]; if ( - !in_array($val['DATATYPE'], array( - 'data', - 'header' - )) + ! in_array($val['DATATYPE'], [ + 'data', + 'header', + ]) ) { continue; } @@ -1002,12 +953,11 @@ protected function cacheParseRowspan(int $iStartIndex = 0, string $sCacheType = continue; } //skip the rows without rowspan - //@formatter:off - $rowSpans[] = array( + $rowSpans[] = [ 'row_id' => $ix, - 'reference_cell' => $cell - ); + 'reference_cell' => $cell, + ]; //@formatter:on $h_rows = 0; @@ -1044,7 +994,6 @@ protected function cacheParseRowspan(int $iStartIndex = 0, string $sCacheType = * Calculate the height of each cell that makes the rowspan. * The height of this cell is the sum of the heights of the rows where the rowspan occurs */ - foreach ($rowSpans as $val1) { /** @var CellAbstract $cell */ $cell = $val1['reference_cell']; @@ -1059,13 +1008,12 @@ protected function cacheParseRowspan(int $iStartIndex = 0, string $sCacheType = $cell->setCellDrawHeight($h_rows); - if (!$this->tableSplit) { + if (! $this->tableSplit) { $aRefCache[$val1['row_id']]['HEIGHT_ROWSPAN'] = $h_rows; } } } - /** * Splits the Data Cache into Pages. * Parses the Data Cache and when it is needed then a "new page" command is inserted into the Data Cache. @@ -1112,10 +1060,10 @@ protected function cachePaginate() if (isset($val['ROWSPAN'])) { foreach ($val['ROWSPAN'] as $v) { - $rowSpans[] = array( + $rowSpans[] = [ $i, - $v - ); + $v, + ]; $aDC[$i]['DATA'][$v]->HEIGHT_LEFT_RW = $leftHeight; } } @@ -1124,7 +1072,7 @@ protected function cachePaginate() $iRowHeight = $val['HEIGHT']; $iRowHeightRowspan = 0; - if (!$this->tableSplit && (isset($val['HEIGHT_ROWSPAN']))) { + if (! $this->tableSplit && (isset($val['HEIGHT_ROWSPAN']))) { $iRowHeightRowspan = $val['HEIGHT_ROWSPAN']; } @@ -1164,23 +1112,21 @@ protected function cachePaginate() * * SITUATION 3: * - normal split flow - * */ //@formatter:on - //use this switch for flow control switch (1) { case 1: //SITUATION 1: if ( $isHeader or - (!$headerOnPage and !$this->dataOnCurrentPage and !$this->tableSplit and ($iLastDataKey > 0)) + (! $headerOnPage and ! $this->dataOnCurrentPage and ! $this->tableSplit and ($iLastDataKey > 0)) ) { $count = $this->insertNewPage( $iLastDataKey, null, - (!$isHeader) && (!$headerOnPage) + (! $isHeader) && (! $headerOnPage) ); break; //exit from switch(1); } @@ -1211,7 +1157,7 @@ protected function cachePaginate() $data = $val['DATA']; $rowHeight = $iLeftHeightLast; - #$rowHeight = 0; + //$rowHeight = 0; $rowHeightData = 0; $aTData = []; @@ -1220,7 +1166,6 @@ protected function cachePaginate() for ($j = 0; $j < $this->columns; $j++) { /** @var $cell CellAbstract */ /** @var $cellSplit CellAbstract */ - $aTData[$j] = $data[$j]; $cellSplit = &$aTData[$j]; $cell = &$data[$j]; @@ -1234,7 +1179,7 @@ protected function cachePaginate() } if ($cell->isSplittable()) { - list($cellSplit) = $cell->split($val['HEIGHT'], $iLeftHeightLast); + [$cellSplit] = $cell->split($val['HEIGHT'], $iLeftHeightLast); $cell->setCellDrawHeight($iLeftHeightLast); } else { $cellSplit = clone $cell; @@ -1259,13 +1204,11 @@ protected function cachePaginate() /** * Parse separately the rows with the ROWSPAN */ - $bNeedParseCache = false; foreach ($rowSpans as $rws) { $rData = &$aDC[$rws[0]]['DATA'][$rws[1]]; /** @var $rData CellAbstract */ - if ($rData->isPropertySet('HEIGHT_LEFT_RW') && $rData->getCellDrawHeight() > $rData->HEIGHT_LEFT_RW) { /** * This cell has a rowspan in IT @@ -1273,9 +1216,8 @@ protected function cachePaginate() * that was set when the cell was parsed. * HEIGHT_LEFT_RW */ - if ($rData->isSplittable()) { - list($aTData[$rws[1]]) = $rData->split( + [$aTData[$rws[1]]] = $rData->split( $rData->getCellDrawHeight(), $rData->HEIGHT_LEFT_RW ); @@ -1320,7 +1262,6 @@ protected function cachePaginate() /** * Check if we have a rowspan that needs to be splitted */ - $bNeedParseCache = false; $rowSpan = $aDC[$i]['ROWSPAN']; @@ -1328,12 +1269,10 @@ protected function cachePaginate() foreach ($rowSpans as $rws) { $rData = &$aDC[$rws[0]]['DATA'][$rws[1]]; /** @var $rData CellAbstract */ - if ($rws[0] == $i) { continue; } //means that this was added at the last line, that will not appear on this page - if ($rData->getCellDrawHeight() > $rData->HEIGHT_LEFT_RW) { /** * This cell has a rowspan in IT @@ -1341,14 +1280,12 @@ protected function cachePaginate() * that was set when the cell was parsed. * HEIGHT_LEFT_RW */ - - list($aTData) = $rData->split( + [$aTData] = $rData->split( $rData->getCellDrawHeight(), $rData->HEIGHT_LEFT_RW - $iLeftHeightLast ); /** @var $aTData CellInterface */ - $rData->setCellDrawHeight($rData->HEIGHT_LEFT_RW - $iLeftHeightLast); $aTData->setRowSpan($aTData->getRowSpan() - ($i - $rws[0])); @@ -1378,7 +1315,6 @@ protected function cachePaginate() } } - /** * Inserts a new page in the Data Cache, after the specified Index. * If sent then also a new data is inserted after the new page @@ -1386,8 +1322,7 @@ protected function cachePaginate() * @param $index integer - after this index the new page inserted * @param $newData resource - default null. If specified this data is inserted after the new page * @param $insertHeader boolean - true then the header is inserted, false - no header is inserted - * @param bool $removeCurrentRow - * @return integer the new number of lines that the Data Cache Contains. + * @return int the new number of lines that the Data Cache Contains. */ protected function insertNewPage(int $index = 0, $newData = null, bool $insertHeader = true, bool $removeCurrentRow = false): int { @@ -1418,7 +1353,7 @@ protected function insertNewPage(int $index = 0, $newData = null, bool $insertHe } //if we have a header and no data on the current page, remove the header from the current page! - if ($headerLines > 0 && !$this->dataOnCurrentPage) { + if ($headerLines > 0 && ! $this->dataOnCurrentPage) { $shift -= $headerLines; } @@ -1432,10 +1367,10 @@ protected function insertNewPage(int $index = 0, $newData = null, bool $insertHe $aDC[$j + $headerLines + $shift - $nIdx] = $aDC[$j - 1]; } - $aDC[$index + $shift] = array( + $aDC[$index + $shift] = [ 'HEIGHT' => 0, - 'DATATYPE' => 'new_page' - ); + 'DATATYPE' => 'new_page', + ]; $j = $shift; @@ -1460,7 +1395,6 @@ protected function insertNewPage(int $index = 0, $newData = null, bool $insertHe return count($aDC); } - /** * Sends all the Data Cache to the PDF Document. * This is the Function that Outputs the table data to the pdf document @@ -1489,6 +1423,7 @@ protected function cachePrepOutputData() if ($val['DATATYPE'] == 'new_page') { //add a new page $this->addPage(); + continue; } @@ -1507,7 +1442,6 @@ protected function cachePrepOutputData() //render the cell to the pdf //$data[$i]->render($rowHeight = $val['HEIGHT']); - if ($val['HEIGHT'] > $cell->getCellDrawHeight()) { $cell->setCellDrawHeight($val['HEIGHT']); } @@ -1529,7 +1463,6 @@ protected function cachePrepOutputData() $this->pdf->SetAutoPageBreak($oldAutoPageBreak, $oldbMargin); } - /** * Prepares the cache for Output. * Parses the cache for Rowspans, Paginates the cache and then send the data to the pdf document @@ -1545,7 +1478,6 @@ protected function cachePrepOutput() $this->cachePrepOutputData(); } - /** * Adds a new page in the pdf document and initializes the table and the header if necessary. */ @@ -1563,7 +1495,6 @@ protected function addPage() $this->markMarginX(); } - /** * Sends to the pdf document the cache data */ @@ -1572,7 +1503,6 @@ public function ouputData() $this->cachePrepOutput(); } - /** * Sets the attributes for the specified tag * @@ -1582,6 +1512,7 @@ public function ouputData() * @param string|array|null $color * @param string|null $fontFamily font family * @param string $inherit Tag to be inherited + * * @noinspection PhpMissingParamTypeInspection */ public function setStyle($tag, $fontSize = null, $fontStyle = null, $color = null, $fontFamily = null, $inherit = 'base') @@ -1623,18 +1554,16 @@ public static function getValue($var, $index = '', $default = '') /** * Returns the table configuration value specified by the input key * - * @param string $key * @return mixed - * */ protected function getTableConfig(string $key) { return self::getValue($this->configuration['TABLE'], $key); } - /** * Sets the Table Config + * * @param $aConfig array - array containing the Table Configuration */ public function setTableConfig(array $aConfig) @@ -1645,8 +1574,6 @@ public function setTableConfig(array $aConfig) /** * Sets Header configuration values - * - * @param array $aConfig */ public function setHeaderConfig(array $aConfig) { @@ -1655,41 +1582,32 @@ public function setHeaderConfig(array $aConfig) /** * Sets Row configuration values - * - * @param array $aConfig */ public function setRowConfig(array $aConfig) { $this->configuration['ROW'] = array_merge($this->configuration['ROW'], $aConfig); } - /** * Returns the header configuration value specified by the input key * - * @param string $key * @return mixed - * */ protected function getHeaderConfig(string $key) { return self::getValue($this->configuration['HEADER'], $key); } - /** * Returns the row configuration value specified by the input key * - * @param string $key * @return mixed - * */ protected function getRowConfig(string $key) { return self::getValue($this->configuration['ROW'], $key); } - /** * Returns the default configuration array of the table. * The array contains values for the Table style, Header Style and Data Style. @@ -1710,23 +1628,22 @@ protected function getDefaultConfiguration(): array foreach ($files as $file) { if (is_readable($file)) { - return require($file); + return require $file; } } - trigger_error("Table Configuration file not found. Please check your settings"); + trigger_error('Table Configuration file not found. Please check your settings'); + return []; } /** * Returns the compatibility map between STRINGS and Constants - * - * @return array */ protected function compatibilityMap(): array { //@formatter:off - return array( + return [ 'TEXT_COLOR' => self::TEXT_COLOR, 'TEXT_SIZE' => self::TEXT_SIZE, 'TEXT_FONT' => self::TEXT_FONT, @@ -1745,31 +1662,24 @@ protected function compatibilityMap(): array 'PADDING_BOTTOM' => self::PADDING_BOTTOM, 'TABLE_ALIGN' => self::TABLE_ALIGN, 'TABLE_LEFT_MARGIN' => self::TABLE_LEFT_MARGIN, - ); + ]; //@formatter:on } - /** * Returns the current type map - * - * @return array */ protected function getTypeMap(): array { return $this->typeMap; } - /** * Adds a type/class relationship - * - * @param string $name - * @param string $class */ public function addTypeMap(string $name, string $class) { - if (!class_exists($class)) { + if (! class_exists($class)) { //fatal error trigger_error("Invalid class specified: $class", E_USER_ERROR); } @@ -1777,11 +1687,9 @@ public function addTypeMap(string $name, string $class) $this->typeMap[strtoupper($name)] = $class; } - /** * Sets the disable page break value. If TRUE then page-breaks are disabled * - * @param boolean $value * @return $this */ public function setDisablePageBreak(bool $value): Table @@ -1793,8 +1701,6 @@ public function setDisablePageBreak(bool $value): Table /** * Returns the PDF object - * - * @return Object|null */ public function getPdfObject(): ?object { diff --git a/src/Table/Cell/CellAbstract.php b/src/Table/Cell/CellAbstract.php index da26510..c8b53a2 100644 --- a/src/Table/Cell/CellAbstract.php +++ b/src/Table/Cell/CellAbstract.php @@ -1,4 +1,5 @@ setInternValues($values, false); + return $this; } @@ -204,12 +206,8 @@ protected function setInternValues(array $values = [], bool $checkSet = true) } } - /** * Returns true if the property is already set - * - * @param string $key - * @return bool */ protected function isInternValueSet(string $key): bool { @@ -218,8 +216,6 @@ protected function isInternValueSet(string $key): bool /** * Marks the property as set - * - * @param string $key */ protected function markInternValueAsSet(string $key) { @@ -228,19 +224,16 @@ protected function markInternValueAsSet(string $key) /** * Sets an intern value - * - * @param $key - * @param $value */ protected function setInternValue($key, $value) { $this->markInternValueAsSet($key); if (isset($this->propMap[$key])) { - call_user_func_array(array( + call_user_func_array([ $this, - $this->propMap[$key] - ), Tools::makeArray($value)); + $this->propMap[$key], + ], Tools::makeArray($value)); return; } @@ -248,10 +241,10 @@ protected function setInternValue($key, $value) $method = 'set' . ucfirst($key); if (method_exists($this, $method)) { - call_user_func_array(array( + call_user_func_array([ $this, - $method - ), Tools::makeArray($value)); + $method, + ], Tools::makeArray($value)); return; } @@ -259,47 +252,41 @@ protected function setInternValue($key, $value) $this->properties[$key] = $value; } - /** * Set image alignment. * It can be any combination of the 2 Vertical and Horizontal values: * Vertical values: TBM * Horizontal values: LRC - * - * @param string $alignment */ public function setAlign(string $alignment) { $this->alignment = strtoupper($alignment); } - public function setColSpan(int $value): CellInterface { $this->colSpan = Validate::intPositive($value); + return $this; } - public function getColSpan(): int { return $this->colSpan; } - public function setRowSpan(int $value): CellInterface { $this->rowSpan = Validate::intPositive($value); + return $this; } - public function getRowSpan(): int { return $this->rowSpan; } - public function setCellWidth($value): CellInterface { $value = Validate::float($value, 0); @@ -309,16 +296,15 @@ public function setCellWidth($value): CellInterface if ($value > $this->getCellDrawWidth()) { $this->setCellDrawWidth($value); } + return $this; } - public function getCellWidth(): float { return $this->cellWidth; } - public function setCellHeight($value): CellInterface { $value = Validate::float($value, 0); @@ -328,16 +314,15 @@ public function setCellHeight($value): CellInterface if ($value > $this->getCellDrawHeight()) { $this->setCellDrawHeight($value); } + return $this; } - public function getCellHeight(): float { return $this->cellHeight; } - public function setCellDrawHeight($value): CellInterface { $value = Validate::float($value, 0); @@ -345,84 +330,79 @@ public function setCellDrawHeight($value): CellInterface if ($this->getCellHeight() <= $value) { $this->cellDrawHeight = $value; } + return $this; } - public function getCellDrawHeight() { if ($this->height > 0) { return Validate::float($this->height, 0); } + return $this->cellDrawHeight; } - public function setCellDrawWidth($value): CellInterface { $value = Validate::float($value, 0); $this->cellDrawWidth = $value; $this->setCellWidth($value); + return $this; } - public function getCellDrawWidth() { return $this->cellDrawWidth; } - public function setContentWidth($value): CellInterface { $this->contentWidth = Validate::float($value, 0); + return $this; } - public function getContentWidth() { return $this->contentWidth; } - public function setContentHeight($value): CellInterface { $this->contentHeight = Validate::float($value, 0); + return $this; } - public function getContentHeight() { return $this->contentHeight; } - public function setSkipped(bool $value): CellInterface { $this->bSkip = $value; + return $this; } - public function getSkipped(): bool { return $this->bSkip; } - public function __get($property) { if (isset($this->properties[$property])) { return $this->properties[$property]; } - return null; + return null; } - public function __set($property, $value) { $this->setInternValue($property, $value); @@ -430,7 +410,6 @@ public function __set($property, $value) return $this; } - public function isPropertySet($property): bool { if (isset($this->properties[$property])) { @@ -440,14 +419,13 @@ public function isPropertySet($property): bool return false; } - public function setDefaultValues(array $values = []): CellInterface { $this->setInternValues($values); + return $this; } - /** * Renders the base cell layout - Borders and Background Color */ @@ -459,14 +437,14 @@ public function renderCellLayout() //border size BORDER_SIZE $this->pdf->SetLineWidth($this->getBorderSize()); - if (!$this->isTransparent()) { + if (! $this->isTransparent()) { //fill color = BACKGROUND_COLOR - list($r, $g, $b) = $this->getBackgroundColor(); + [$r, $g, $b] = $this->getBackgroundColor(); $this->pdf->SetFillColor($r, $g, $b); } //Draw Color = BORDER_COLOR - list($r, $g, $b) = $this->getBorderColor(); + [$r, $g, $b] = $this->getBorderColor(); $this->pdf->SetDrawColor($r, $g, $b); $this->pdf->Cell( @@ -476,19 +454,17 @@ public function renderCellLayout() $this->getBorderType(), 0, '', - !$this->isTransparent() + ! $this->isTransparent() ); $this->pdf->SetXY($x, $y); } - protected function isTransparent(): bool { return Tools::isFalse($this->getBackgroundColor()); } - public function copyProperties(CellAbstract $source) { $this->rowSpan = $source->getRowSpan(); @@ -508,94 +484,87 @@ public function copyProperties(CellAbstract $source) $this->alignVertical = $source->getAlignVertical(); } - public function processContent() { } - public function setPadding($top = 0, $right = 0, $bottom = 0, $left = 0): CellInterface { $this->setPaddingTop($top); $this->setPaddingRight($right); $this->setPaddingBottom($bottom); $this->setPaddingLeft($left); + return $this; } - public function setPaddingBottom($paddingBottom): CellInterface { $this->paddingBottom = Validate::float($paddingBottom, 0); + return $this; } - public function getPaddingBottom() { return $this->paddingBottom; } - public function setPaddingLeft($paddingLeft): CellInterface { $this->paddingLeft = Validate::float($paddingLeft, 0); + return $this; } - public function getPaddingLeft() { return $this->paddingLeft; } - public function setPaddingRight($paddingRight): CellInterface { $this->paddingRight = Validate::float($paddingRight, 0); + return $this; } - public function getPaddingRight() { return $this->paddingRight; } - public function setPaddingTop($paddingTop): CellInterface { $this->paddingTop = Validate::float($paddingTop, 0); + return $this; } - public function getPaddingTop() { return $this->paddingTop; } - public function setBorderSize($borderSize): CellInterface { $this->borderSize = Validate::float($borderSize, 0); + return $this; } - public function getBorderSize(): float { return $this->borderSize; } - public function setBorderType($borderType): CellInterface { $this->borderType = $borderType; + return $this; } - public function getBorderType(): string { return $this->borderType; @@ -604,6 +573,7 @@ public function getBorderType(): string public function setBorderColor($r, ?int $g = null, ?int $b = null): CellInterface { $this->borderColor = Tools::getColor($r, $g, $b); + return $this; } @@ -612,15 +582,14 @@ public function getBorderColor() return $this->borderColor; } - public function setAlignVertical(string $alignVertical): CellInterface { $this->markInternValueAsSet('VERTICAL_ALIGN'); $this->alignVertical = Validate::alignVertical($alignVertical); + return $this; } - public function getAlignVertical(): string { return $this->alignVertical; @@ -629,6 +598,7 @@ public function getAlignVertical(): string public function setBackgroundColor($r, ?int $g = null, ?int $b = null): CellInterface { $this->backgroundColor = Tools::getColor($r, $g, $b); + return $this; } @@ -652,9 +622,6 @@ public function getHeight() return $this->height; } - /** - * @param $height - */ public function setHeight($height) { $this->height = $height; diff --git a/src/Table/Cell/CellInterface.php b/src/Table/Cell/CellInterface.php index 4956bec..a8c7cb1 100644 --- a/src/Table/Cell/CellInterface.php +++ b/src/Table/Cell/CellInterface.php @@ -19,7 +19,6 @@ interface CellInterface */ public function __construct($pdf); - /** * Returns true of the cell is splittable */ @@ -34,16 +33,11 @@ public function isSplittable(); */ public function split($rowHeight, $maxHeight): array; - /** * Set the default values - * - * @param array $values - * @return self */ public function setDefaultValues(array $values = []): self; - /** * Process the cell content * This method is called when all the properties/values are set and the cell content can be processed. @@ -52,12 +46,10 @@ public function setDefaultValues(array $values = []): self; */ public function processContent(); - /** * Set the properties of the cell * * @param array $values key=>value pair - * @return self */ public function setProperties(array $values = []): self; @@ -65,35 +57,24 @@ public function render(); /** * Returns the colspan value - * - * @return integer */ public function getColSpan(): int; /** * Sets the colspan value - * - * @param int $value - * @return self */ public function setColSpan(int $value): self; /** * Returns the rowspan value - * - * @return int */ public function getRowSpan(): int; /** * Sets the rowspan value - * - * @param int $value - * @return self */ public function setRowSpan(int $value): self; - /** * Sets the paddings * @@ -101,7 +82,6 @@ public function setRowSpan(int $value): self; * @param int|float $right Right padding * @param int|float $bottom Bottom padding * @param int|float $left Left padding - * @return self */ public function setPadding($top = 0, $right = 0, $bottom = 0, $left = 0): self; @@ -109,7 +89,6 @@ public function setPadding($top = 0, $right = 0, $bottom = 0, $left = 0): self; * Sets the padding bottom * * @param int|float $paddingBottom - * @return self */ public function setPaddingBottom($paddingBottom): self; @@ -124,7 +103,6 @@ public function getPaddingBottom(); * Sets the padding left * * @param int|float $paddingLeft - * @return self */ public function setPaddingLeft($paddingLeft): self; @@ -139,7 +117,6 @@ public function getPaddingLeft(); * Sets the padding right * * @param int|float $paddingRight - * @return self */ public function setPaddingRight($paddingRight): self; @@ -154,7 +131,6 @@ public function getPaddingRight(); * Sets the padding top * * @param int|float $paddingTop - * @return self */ public function setPaddingTop($paddingTop): self; @@ -169,7 +145,6 @@ public function getPaddingTop(); * Sets the border Size * * @param int|float $borderSize - * @return self */ public function setBorderSize($borderSize): self; @@ -185,7 +160,6 @@ public function getBorderSize(); * Can be: 0, 1 or a combination of: 'LRTB' * * @param int|string $borderType - * @return self */ public function setBorderType($borderType): self; @@ -201,9 +175,6 @@ public function getBorderType(); * If the value is set to FALSE, 0 or '0' then we assume transparency * * @param int|bool|array $r - * @param int|null $g - * @param int|null $b - * @return self */ public function setBorderColor($r, ?int $g = null, ?int $b = null): self; @@ -216,16 +187,11 @@ public function getBorderColor(); /** * Sets the Align Vertical - * - * @param string $alignVertical - * @return self */ public function setAlignVertical(string $alignVertical): self; /** * Returns the Align Vertical - * - * @return string */ public function getAlignVertical(): string; @@ -234,9 +200,6 @@ public function getAlignVertical(): string; * If the value is set to FALSE, 0 or '0' then we assume transparency * * @param int|bool|array $r - * @param int|null $g - * @param int|null $b - * @return self */ public function setBackgroundColor($r, ?int $g = null, ?int $b = null): self; diff --git a/src/Table/Cell/EmptyCell.php b/src/Table/Cell/EmptyCell.php index 902d67b..be26095 100644 --- a/src/Table/Cell/EmptyCell.php +++ b/src/Table/Cell/EmptyCell.php @@ -12,7 +12,6 @@ public function isSplittable(): bool return false; } - public function render(): void { $this->renderCellLayout(); diff --git a/src/Table/Cell/Image.php b/src/Table/Cell/Image.php index 14b864d..f287a8a 100644 --- a/src/Table/Cell/Image.php +++ b/src/Table/Cell/Image.php @@ -27,16 +27,10 @@ class Image extends CellAbstract implements CellInterface */ protected $alignment = 'MC'; - /** * Image cell constructor * * @param Pdf|PdfInterface $pdf - * @param string $file - * @param int $width - * @param int $height - * @param string $type - * @param string $link */ public function __construct($pdf, string $file = '', int $width = 0, int $height = 0, string $type = '', string $link = '') { @@ -47,13 +41,11 @@ public function __construct($pdf, string $file = '', int $width = 0, int $height } } - public function setProperties(array $values = []): CellInterface { //call the parent function parent::setProperties($values); - $this->setImage( Tools::getValue($values, 'FILE'), Tools::getValue($values, 'WIDTH'), @@ -65,7 +57,6 @@ public function setProperties(array $values = []): CellInterface return $this; } - public function setImage($file = '', $width = 0, $height = 0, $type = '', $link = '') { $this->file = $file; @@ -75,20 +66,18 @@ public function setImage($file = '', $width = 0, $height = 0, $type = '', $link //check if file exists etc... $this->doChecks(); - list($width, $height) = $this->pdfi->getImageParams($file, $width, $height); + [$width, $height] = $this->pdfi->getImageParams($file, $width, $height); $this->setContentWidth($width); $this->setContentHeight($height); } - /** * Set image alignment. * It can be any combination of the 2 Vertical and Horizontal values: * Vertical values: TBM * Horizontal values: LRC * - * @param string $alignment * @todo: check if this function is REALLY used */ public function setAlign(string $alignment) @@ -96,25 +85,21 @@ public function setAlign(string $alignment) $this->alignment = strtoupper($alignment); } - public function isSplittable(): bool { return false; } - public function getType(): string { return $this->type; } - public function getLink(): string { return $this->link; } - /** * Renders the image in the pdf Object */ @@ -168,7 +153,6 @@ public function render() ); } - /** * Checks if the image file is set and it is accessible */ @@ -176,15 +160,14 @@ protected function doChecks() { //check if the image is set if (0 == strlen($this->file)) { - trigger_error("Image File not set!", E_USER_ERROR); + trigger_error('Image File not set!', E_USER_ERROR); } - if (!file_exists($this->file)) { + if (! file_exists($this->file)) { trigger_error("Image File Not found: $this->file!", E_USER_ERROR); } } - public function processContent() { $this->doChecks(); diff --git a/src/Table/Cell/ImageSVG.php b/src/Table/Cell/ImageSVG.php index 238786a..1e6284a 100644 --- a/src/Table/Cell/ImageSVG.php +++ b/src/Table/Cell/ImageSVG.php @@ -1,4 +1,5 @@ doChecks(); - list($width, $height) = $this->getImageParamsSVG($file, $width, $height); + [$width, $height] = $this->getImageParamsSVG($file, $width, $height); $this->setContentWidth($width); $this->setContentHeight($height); @@ -49,7 +50,7 @@ private function getImageParamsSVG($file, $w = 0, $h = 0) $regs = []; // get original image width and height preg_match('/]*)>/i', $svgData, $regs); - if (isset($regs[1]) and !empty($regs[1])) { + if (isset($regs[1]) and ! empty($regs[1])) { $tmp = []; if (preg_match('/[\s]+width[\s]*=[\s]*"([^"]*)"/i', $regs[1], $tmp)) { $ow = $this->pdf->getHTMLUnitToUnits($tmp[1], 1, $this->pdf->svgunit, false); @@ -76,16 +77,14 @@ private function getImageParamsSVG($file, $w = 0, $h = 0) $h = $w * $oh / $ow; } - return array( + return [ $w, - $h - ); + $h, + ]; } - /** * Renders the image in the pdf Object at the specified position - * */ public function render() { diff --git a/src/Table/Cell/Multicell.php b/src/Table/Cell/Multicell.php index 4e06a6a..7ab299e 100644 --- a/src/Table/Cell/Multicell.php +++ b/src/Table/Cell/Multicell.php @@ -7,6 +7,7 @@ /** * Pdf Table Cell Multicell\Table\Cell + * * @property string|array $TEXT_STRLINES * @property string|null $TEXT_ALIGN * @property string|int $LINE_SIZE @@ -25,7 +26,6 @@ class Multicell extends CellAbstract implements CellInterface { /** - * * @var \EvoSys21\PdfLib\Multicell */ protected $multicell; @@ -47,29 +47,26 @@ public function __construct($pdf, $data = ' ') } } - public function getDefaultValues(): array { - $values = array( + $values = [ 'TEXT' => '', 'TEXT_COLOR' => [0, 0, 0], //text color 'TEXT_SIZE' => 6, //font size 'TEXT_FONT' => 'Arial', //font family 'TEXT_ALIGN' => 'C', //horizontal alignment, possible values: LRC (left, right, center) 'TEXT_TYPE' => '', //font type - 'LINE_SIZE' => 4 - ); //line size for one row + 'LINE_SIZE' => 4, + ]; //line size for one row return array_merge(parent::getDefaultValues(), $values); } - /** * Alignment - can be any combination of the following values: * Vertical values: TBMJ * Horizontal values: LRC * - * @param string $alignment * @see CellAbstract::setAlign() */ public function setAlign(string $alignment) @@ -94,22 +91,20 @@ public function setAlign(string $alignment) } } - public function attachMulticell($multicell) { $this->multicell = $multicell; $this->multicell->enableFill(false); } - public function setCellDrawWidth($value): CellInterface { parent::setCellDrawWidth($value); $this->calculateContentWidth(); + return $this; } - public function isSplittable(): bool { if ($this->isPropertySet('SPLITTABLE')) { @@ -119,13 +114,11 @@ public function isSplittable(): bool return true; } - /** * Splits the current cell * * @param int|float $rowHeight - the Height of the row that contains this cell * @param int|float $maxHeight - the Max height available - * @return array */ public function split($rowHeight, $maxHeight): array { @@ -214,32 +207,28 @@ public function split($rowHeight, $maxHeight): array $oCell2->calculateCellHeight(); //$oCell2->setCellDrawHeight($rowHeight); - $this->setCellDrawHeight($maxHeight); - return array( + return [ $oCell2, - $splitHeight - ); + $splitHeight, + ]; } - public function getText(): string { return $this->TEXT ?? ''; } - public function getLineSize() { return $this->LINE_SIZE; } - public function processContent() { //Text Color = TEXT_COLOR - list($r, $g, $b) = $this->TEXT_COLOR; + [$r, $g, $b] = $this->TEXT_COLOR; $this->pdf->SetTextColor($r, $g, $b); //Set the font, font type and size @@ -257,7 +246,6 @@ public function processContent() $this->calculateCellHeight(); } - public function calculateCellHeight() { $this->nLines = count($this->TEXT_STRLINES); @@ -266,19 +254,15 @@ public function calculateCellHeight() $this->setCellDrawHeight($this->cellHeight); } - - /** - */ public function calculateContentWidth() { $this->contentWidth = $this->getCellWidth() - $this->getPaddingLeft() - $this->getPaddingRight(); if ($this->contentWidth < 0) { - trigger_error("Cell with negative value. Please check width, padding left and right"); + trigger_error('Cell with negative value. Please check width, padding left and right'); } } - /** * Renders the image in the pdf Object at the specified position */ @@ -287,7 +271,7 @@ public function render() $this->renderCellLayout(); //Text Color = TEXT_COLOR - list($r, $g, $b) = $this->TEXT_COLOR; + [$r, $g, $b] = $this->TEXT_COLOR; $this->pdf->SetTextColor($r, $g, $b); //Set the font, font type and size @@ -310,7 +294,6 @@ public function render() ); } - public function multiCellTbl( $w, $h, diff --git a/src/Tcpdf/Pdf.php b/src/Tcpdf/Pdf.php index 636ec72..1756616 100644 --- a/src/Tcpdf/Pdf.php +++ b/src/Tcpdf/Pdf.php @@ -14,7 +14,6 @@ * extended and these properties made public. * * In all subclasses we refer to Pdf class and not TCPDF. - * */ class Pdf extends TCPDF { diff --git a/src/Tcpdf/PdfInterface.php b/src/Tcpdf/PdfInterface.php index c186891..f44de8e 100644 --- a/src/Tcpdf/PdfInterface.php +++ b/src/Tcpdf/PdfInterface.php @@ -15,7 +15,6 @@ /** * Pdf Class Interface - * */ class PdfInterface extends AbstractPdfUtils implements PdfInterfaceDef { @@ -31,7 +30,6 @@ class PdfInterface extends AbstractPdfUtils implements PdfInterfaceDef protected $backupDrawColor; public $textColor; - public function __construct($pdf) { $this->pdf = $pdf; @@ -39,24 +37,20 @@ public function __construct($pdf) /** * Returns the PDF object of the Interface - * - * @return Pdf */ public function getPdfObject(): Pdf { return $this->pdf; } - /** * Returns the page width */ public function getPageWidth(): int { - return (int)$this->pdf->w - $this->pdf->rMargin - $this->pdf->lMargin; + return (int) $this->pdf->w - $this->pdf->rMargin - $this->pdf->lMargin; } - /** * Returns the current X position * @@ -67,7 +61,6 @@ public function getX() return $this->pdf->GetX(); } - /** * Returns the remaining width to the end of the current line * @@ -84,7 +77,6 @@ public function getRemainingWidth() return $n; } - /** * Returns the character width for the specified input parameters * @@ -96,12 +88,11 @@ public function getRemainingWidth() */ public function getCharStringWidth($tag, $char, $fontFamily, $fontStyle, $fontsize) { - return $this->pdf->GetArrStringWidth(array( - $char - ), $fontFamily, $fontStyle, $fontsize); + return $this->pdf->GetArrStringWidth([ + $char, + ], $fontFamily, $fontStyle, $fontsize); } - /** * Split string into array of equivalent codes and return the result array * @@ -113,7 +104,6 @@ public function stringToArray($str) return TCPDF_FONTS::UTF8StringToArray($str, $this->pdf->isunicode, $this->pdf->CurrentFont); } - /** * Returns the active font family * @@ -124,7 +114,6 @@ public function getFontFamily(): string return $this->pdf->FontFamily; } - /** * Returns the active font style * @@ -135,7 +124,6 @@ public function getFontStyle(): string return $this->pdf->FontStyle; } - /** * Returns the active font size in PT * @@ -146,7 +134,6 @@ public function getFontSizePt() return $this->pdf->FontSizePt; } - /** * Adds an image to the pdf document * @@ -163,7 +150,6 @@ public function Image($file, $x = null, $y = null, $w = 0, $h = 0, $type = '', $ $this->pdf->Image($file, $x, $y, $w, $h, $type, $link); } - /** * Returns the image width and height in PDF values! * @@ -205,15 +191,15 @@ public function getImageParams($file, $w = 0, $h = 0): array $h = $w * $info['h'] / $info['w']; } - return array( + return [ $w, - $h - ); + $h, + ]; } /** * Wrapper for the cell function - * @param $w + * * @param int $h * @param string $txt * @param int $border @@ -229,8 +215,6 @@ public function Cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $ /** * Returns true if unicode charset is being used - * - * @return bool */ public function isUnicode(): bool { @@ -240,7 +224,6 @@ public function isUnicode(): bool /** * Sets the PDF TextColor * - * @param $color * @return $this */ public function setTextColor($color): self @@ -250,17 +233,18 @@ public function setTextColor($color): self if (is_string($color) && str_starts_with($color, self::RAW)) { $this->pdf->TextColor = substr($color, strlen(self::RAW)); $this->pdf->ColorFlag = ($this->pdf->FillColor != $this->pdf->TextColor); + return $this; } $colorData = Tools::parseColor($color); call_user_func_array([$this->pdf, 'SetTextColor'], $colorData); + return $this; } /** * Sets the PDF DrawColor * - * @param $color * @return $this */ public function setDrawColor($color): self @@ -268,15 +252,18 @@ public function setDrawColor($color): self $this->backupDrawColor = $this->pdf->DrawColor; if (is_string($color) && str_starts_with($color, self::RAW)) { $this->pdf->DrawColor = substr($color, strlen(self::RAW)); + return $this; } $colorData = Tools::parseColor($color); call_user_func_array([$this->pdf, 'SetDrawColor'], $colorData); + return $this; } /** * Restores the DrawColor from the backup + * * @return $this */ public function restoreDrawColor(): self @@ -284,6 +271,7 @@ public function restoreDrawColor(): self if ($this->backupDrawColor) { $this->pdf->DrawColor = $this->backupDrawColor; } + return $this; } @@ -303,10 +291,7 @@ public function setEncoding() /** * Returns the Available Width to draw the Text. * - * @param string $str - * @param int $start * @param int|float|null $length - * @return string */ public function substr(string $str, int $start, $length = null): string { @@ -317,7 +302,6 @@ public function substr(string $str, int $start, $length = null): string } } - public function strlen(string $s): int { return mb_strlen($s); diff --git a/src/Tfpdf/Pdf.php b/src/Tfpdf/Pdf.php index d21d3b9..9db8934 100644 --- a/src/Tfpdf/Pdf.php +++ b/src/Tfpdf/Pdf.php @@ -14,7 +14,6 @@ * extended and these properties made public. * * In all subclasses we refer to Pdf class and not tFPDF. - * */ class Pdf extends tFPDF { @@ -84,7 +83,7 @@ public function Cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $ public function saveToFile($fileName) { - $this->Output("F", $fileName); + $this->Output('F', $fileName); } public function UTF8StringToArray($str) diff --git a/src/Tfpdf/PdfInterface.php b/src/Tfpdf/PdfInterface.php index 0ad5dd1..38d0f99 100644 --- a/src/Tfpdf/PdfInterface.php +++ b/src/Tfpdf/PdfInterface.php @@ -15,7 +15,6 @@ /** * Pdf Class Interface - * */ class PdfInterface extends AbstractPdfUtils implements PdfInterfaceDef { @@ -31,7 +30,6 @@ class PdfInterface extends AbstractPdfUtils implements PdfInterfaceDef protected $backupDrawColor; public $textColor; - public function __construct($pdf) { $this->pdf = $pdf; @@ -39,24 +37,20 @@ public function __construct($pdf) /** * Returns the PDF object of the Interface - * - * @return Pdf */ public function getPdfObject(): Pdf { return $this->pdf; } - /** * Returns the page width */ public function getPageWidth(): int { - return (int)$this->pdf->w - $this->pdf->rMargin - $this->pdf->lMargin; + return (int) $this->pdf->w - $this->pdf->rMargin - $this->pdf->lMargin; } - /** * Returns the current X position * @@ -67,7 +61,6 @@ public function getX() return $this->pdf->GetX(); } - /** * Returns the remaining width to the end of the current line * @@ -84,7 +77,6 @@ public function getRemainingWidth() return $n; } - /** * Split string into array of equivalent codes and return the result array * @@ -96,7 +88,6 @@ public function stringToArray(string $str): array return $this->pdf->UTF8StringToArray($str); } - /** * Returns the active font family * @@ -107,7 +98,6 @@ public function getFontFamily(): string return $this->pdf->FontFamily; } - /** * Returns the active font style * @@ -118,7 +108,6 @@ public function getFontStyle(): string return $this->pdf->FontStyle; } - /** * Returns the active font size in PT * @@ -129,7 +118,6 @@ public function getFontSizePt() return $this->pdf->FontSizePt; } - /** * Adds an image to the pdf document * @@ -146,7 +134,6 @@ public function Image($file, $x = null, $y = null, $w = 0, $h = 0, $type = '', $ $this->pdf->Image($file, $x, $y, $w, $h, $type, $link); } - /** * Returns the image width and height in PDF values! * @@ -161,7 +148,7 @@ public function getImageParams($file, $w = 0, $h = 0): array $w = floatval($w); // Put an image on the page - if (!isset($this->pdf->images[$file])) { + if (! isset($this->pdf->images[$file])) { $pos = strrpos($file, '.'); $type = substr($file, $pos + 1); $type = strtolower($type); @@ -169,7 +156,7 @@ public function getImageParams($file, $w = 0, $h = 0): array $type = 'jpg'; } $mtd = '_parse' . $type; - if (!method_exists($this->pdf, $mtd)) { + if (! method_exists($this->pdf, $mtd)) { $this->pdf->Error('Unsupported image type: ' . $type); } $info = $this->pdf->$mtd($file); @@ -198,15 +185,15 @@ public function getImageParams($file, $w = 0, $h = 0): array $h = $w * $info['h'] / $info['w']; } - return array( + return [ $w, - $h - ); + $h, + ]; } /** * Wrapper for the cell function - * @param $w + * * @param int $h * @param string $txt * @param int $border @@ -223,7 +210,6 @@ public function Cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $ /** * Sets the PDF TextColor * - * @param $color * @return $this */ public function setTextColor($color): self @@ -233,17 +219,18 @@ public function setTextColor($color): self if (is_string($color) && str_starts_with($color, self::RAW)) { $this->pdf->TextColor = substr($color, strlen(self::RAW)); $this->pdf->ColorFlag = ($this->pdf->FillColor != $this->pdf->TextColor); + return $this; } $colorData = Tools::parseColor($color); call_user_func_array([$this->pdf, 'SetTextColor'], $colorData); + return $this; } /** * Sets the PDF DrawColor * - * @param $color * @return $this */ public function setDrawColor($color): self @@ -251,15 +238,18 @@ public function setDrawColor($color): self $this->backupDrawColor = $this->pdf->DrawColor; if (is_string($color) && str_starts_with($color, self::RAW)) { $this->pdf->DrawColor = substr($color, strlen(self::RAW)); + return $this; } $colorData = Tools::parseColor($color); call_user_func_array([$this->pdf, 'SetDrawColor'], $colorData); + return $this; } /** * Restores the DrawColor from the backup + * * @return $this */ public function restoreDrawColor(): self @@ -268,6 +258,7 @@ public function restoreDrawColor(): self $this->pdf->DrawColor = $this->backupDrawColor; $this->pdf->_out($this->pdf->DrawColor); } + return $this; } @@ -287,10 +278,7 @@ public function setEncoding() /** * Returns the Available Width to draw the Text. * - * @param string $str - * @param int $start * @param int|float|null $length - * @return string */ public function substr(string $str, int $start, $length = null): string { @@ -301,7 +289,6 @@ public function substr(string $str, int $start, $length = null): string } } - public function strlen(string $s): int { return mb_strlen($s); diff --git a/src/Tools.php b/src/Tools.php index 1fa7432..a240c11 100644 --- a/src/Tools.php +++ b/src/Tools.php @@ -1,4 +1,5 @@ = count($data))) { + if (! isset($index) || ($index >= count($data))) { $index = 0; } @@ -86,8 +85,6 @@ public static function getNextValue(array $data, &$index) * Returns the color array of the 3 parameters or the 1st param if the others are not specified * * @param string|int $r - * @param int|null $g - * @param int|null $b * @return array|string */ public static function getColor($r, ?int $g = null, ?int $b = null) @@ -104,7 +101,6 @@ public static function getColor($r, ?int $g = null, ?int $b = null) * Otherwise a array($value) will be returned; * * @param mixed $value - * @return array */ public static function makeArray($value): array { @@ -115,12 +111,10 @@ public static function makeArray($value): array return [$value]; } - /** * Returns TRUE if value is FALSE(0, '0', FALSE) * * @param mixed $value - * @return bool */ public static function isFalse($value): bool { @@ -142,6 +136,7 @@ public static function isFalse($value): bool public static function getCellAlign($align): string { $align = strtoupper($align); + return match ($align) { 'L', 'LEFT' => 'L', 'R', 'RIGHT' => 'R', @@ -152,11 +147,6 @@ public static function getCellAlign($align): string /** * Compares 2 float values by the specified precision - * - * @param float $value1 - * @param float $value2 - * @param int $precision - * @return bool */ public static function compareFloats(float $value1, float $value2, int $precision = 5): bool { @@ -165,10 +155,6 @@ public static function compareFloats(float $value1, float $value2, int $precisio /** * Parses array1 and sets all the null values from array2 if they exist - * - * @param array $array1 - * @param array $array2 - * @return array */ public static function mergeNonNull(array $array1, array $array2): array { @@ -177,26 +163,25 @@ public static function mergeNonNull(array $array1, array $array2): array $array1[$key] = $array2[$key]; } } + return $array1; } /** * Parses html attributes and returns an associative array * color: #0000BB; font-size: 20px - * - * @param $value - * @return array */ public static function parseHtmlAttribute($value): array { - $values = array_map('trim', explode(";", $value)); + $values = array_map('trim', explode(';', $value)); $result = []; foreach ($values as $entry) { - $entries = array_map('trim', explode(":", $entry)); + $entries = array_map('trim', explode(':', $entry)); if (isset($entries[0]) && isset($entries[1])) { $result[$entries[0]] = $entries[1]; } } + return $result; } @@ -208,7 +193,8 @@ public static function parseColor($color): array if (preg_match("#\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*#", $color, $matches)) { array_shift($matches); //remove first element - return array_map("intval", $matches); + + return array_map('intval', $matches); } $result = self::hex2rgb($color); @@ -216,27 +202,24 @@ public static function parseColor($color): array return $result; } - return array_map('trim', explode(",", $color)); + return array_map('trim', explode(',', $color)); } /** * Convert a hexa decimal color code to its RGB equivalent - * - * @param $hex_color - * @return array|null */ public static function hex2rgb($hex_color): ?array { $values = str_replace('#', '', $hex_color); switch (strlen($values)) { case 3: - list($r, $g, $b) = sscanf($values, "%1s%1s%1s"); + [$r, $g, $b] = sscanf($values, '%1s%1s%1s'); if (ctype_xdigit($r) && ctype_xdigit($g) && ctype_xdigit($b)) { return [hexdec("$r$r"), hexdec("$g$g"), hexdec("$b$b")]; } break; case 6: - return array_map('hexdec', sscanf($values, "%2s%2s%2s")); + return array_map('hexdec', sscanf($values, '%2s%2s%2s')); } return null; @@ -245,18 +228,18 @@ public static function hex2rgb($hex_color): ?array /** * Converts code highlight for the Multicell Output * - * @param $content * @return string|string[] */ public static function convertHighlight($content) { $content = preg_replace("##", "\n", $content); - $content = preg_replace("##", "", $content); + $content = preg_replace('##', '', $content); $replacements = [ - " " => " ", + ' ' => ' ', '' => '' . "\n", '' => "\n\n", ]; + return str_replace(array_keys($replacements), array_values($replacements), $content); } } diff --git a/src/Utils/Arr.php b/src/Utils/Arr.php index 9b4819c..0fcdbe6 100644 --- a/src/Utils/Arr.php +++ b/src/Utils/Arr.php @@ -13,8 +13,7 @@ class Arr /** * Determine whether the given value is array accessible. * - * @param mixed $value - * @return bool + * @param mixed $value */ public static function accessible($value): bool { @@ -24,9 +23,8 @@ public static function accessible($value): bool /** * Check if an item or items exist in an array using "dot" notation. * - * @param ArrayAccess|array $array - * @param string|array $keys - * @return bool + * @param ArrayAccess|array $array + * @param string|array $keys */ public static function has($array, $keys): bool { @@ -58,9 +56,8 @@ public static function has($array, $keys): bool /** * Determine if the given key exists in the provided array. * - * @param ArrayAccess|array $array - * @param string|int $key - * @return bool + * @param ArrayAccess|array $array + * @param string|int $key */ public static function exists($array, $key): bool { @@ -74,9 +71,9 @@ public static function exists($array, $key): bool /** * Get an item from an array using "dot" notation. * - * @param ArrayAccess|array $array - * @param string|int|null $key - * @param mixed $default + * @param ArrayAccess|array $array + * @param string|int|null $key + * @param mixed $default * @return mixed */ public static function get($array, $key, $default = null) @@ -93,7 +90,7 @@ public static function get($array, $key, $default = null) return $array[$key]; } - if (!str_contains($key, '.')) { + if (! str_contains($key, '.')) { return $array[$key] ?? $default; } @@ -111,7 +108,6 @@ public static function get($array, $key, $default = null) /** * Returns the first found key value match in the input array * - * @param array $data * @param array|string $keys * @param mixed $default Default value * @return mixed diff --git a/src/Validate.php b/src/Validate.php index 477729f..607f896 100644 --- a/src/Validate.php +++ b/src/Validate.php @@ -9,9 +9,6 @@ class Validate { /** * Returns a positive(>0) integer value - * - * @param $value - * @return int */ public static function intPositive($value): int { @@ -23,7 +20,6 @@ public static function intPositive($value): int return $value; } - /** * Returns a float value. * If min and max are specified, then $value will have to be between $min and $max @@ -31,7 +27,6 @@ public static function intPositive($value): int * @param mixed $value * @param int|float|null $min * @param int|float|null $max - * @return float */ public static function float($value, $min = null, $max = null): float { @@ -54,12 +49,8 @@ public static function float($value, $min = null, $max = null): float return $value; } - /** * Validates the align Vertical value - * - * @param $value - * @return string */ public static function alignVertical($value): string { @@ -67,7 +58,7 @@ public static function alignVertical($value): string $aValid = ['T', 'B', 'M']; - if (!in_array($value, $aValid)) { + if (! in_array($value, $aValid)) { return 'M'; } diff --git a/tests/BaseExamplesTestCase.php b/tests/BaseExamplesTestCase.php index 4f11395..e532284 100644 --- a/tests/BaseExamplesTestCase.php +++ b/tests/BaseExamplesTestCase.php @@ -30,7 +30,7 @@ protected function runTestWithExample($require, $expected): void TestUtils::toFile($expected, $content); $this->assertTrue(file_exists($generated), $require); - $this->assertComparePdf($expected, $generated, "FAILED: " . basename($expected) . " / $require"); + $this->assertComparePdf($expected, $generated, 'FAILED: ' . basename($expected) . " / $require"); } protected function runTestPdf($pdf, $expected, $message): void @@ -44,6 +44,6 @@ protected function runTestPdf($pdf, $expected, $message): void TestUtils::toFile($expected, $generated); $this->assertTrue(file_exists($generated), $message); - $this->assertComparePdf($expected, $generated, "FAILED: " . basename($expected) . " / $message"); + $this->assertComparePdf($expected, $generated, 'FAILED: ' . basename($expected) . " / $message"); } } diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index bd9c01b..a15a160 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -2,8 +2,8 @@ namespace EvoSys21\PdfLib\Tests; -use EvoSys21\PdfLib\Fpdf\Pdf; use EvoSys21\PdfLib\Examples\Fpdf\PdfFactory; +use EvoSys21\PdfLib\Fpdf\Pdf; use EvoSys21\PdfLib\Tests\Utils\Helper; use EvoSys21\PdfLib\Tests\Utils\TestUtils; use PHPUnit\Framework\TestCase; @@ -15,8 +15,6 @@ class BaseTestCase extends TestCase { /** * Returns the pdf object - * - * @return object */ protected function getPdfObject(): object { @@ -32,7 +30,7 @@ protected function getPdfObject(): object public function assertComparePdf($pdfExpected, $pdfGenerated, $message): void { - if (!file_exists($pdfExpected)) { + if (! file_exists($pdfExpected)) { TestUtils::toFile($pdfExpected, $pdfGenerated, true); } @@ -40,7 +38,7 @@ public function assertComparePdf($pdfExpected, $pdfGenerated, $message): void $shaExpected = is_readable($pdfExpected) ? sha1_file($pdfExpected) : null; $basename = basename($pdfExpected); - $coreName = substr($basename, 0, strrpos($basename, ".")); + $coreName = substr($basename, 0, strrpos($basename, '.')); if (($shaExpected !== $shaGenerated) && getenv('TRACK_FAILED')) { $pdf = TestUtils::failPath($pdfExpected); diff --git a/tests/Dev/DevTest.php b/tests/Dev/DevTest.php index 7817edf..1369753 100644 --- a/tests/Dev/DevTest.php +++ b/tests/Dev/DevTest.php @@ -11,9 +11,6 @@ class DevTest extends BaseExamplesTestCase /** * @dataProvider examplesProvider - * @param string $dir - * @param string $file - * @return void */ public function testExamples(string $dir, string $file): void { diff --git a/tests/Feature/ExamplesTest.php b/tests/Feature/ExamplesTest.php index 00873a0..139d19f 100644 --- a/tests/Feature/ExamplesTest.php +++ b/tests/Feature/ExamplesTest.php @@ -5,7 +5,7 @@ use EvoSys21\PdfLib\Tests\BaseExamplesTestCase; /** - * @covers \EvoSys21\PdfLib\Multicell + * @covers \EvoSys21\PdfLib\Multicell * @covers \EvoSys21\PdfLib\MulticellOptions * @covers \EvoSys21\PdfLib\Table */ diff --git a/tests/Feature/GenericTest.php b/tests/Feature/GenericTest.php index 22a03c5..7afdf98 100644 --- a/tests/Feature/GenericTest.php +++ b/tests/Feature/GenericTest.php @@ -6,8 +6,6 @@ use EvoSys21\PdfLib\Tests\BaseExamplesTestCase; use EvoSys21\PdfLib\Tests\Utils\Helper; -/** - */ class GenericTest extends BaseExamplesTestCase { use ProviderTrait; diff --git a/tests/Unit/Table/CellAbstractTest.php b/tests/Unit/Table/CellAbstractTest.php index a098823..da533ef 100644 --- a/tests/Unit/Table/CellAbstractTest.php +++ b/tests/Unit/Table/CellAbstractTest.php @@ -1,10 +1,10 @@ setPadding($set[0], $set[1], $set[2], $set[3]); $this->assertEquals($get[0], $o->getPaddingTop()); $this->assertEquals($get[1], $o->getPaddingRight()); @@ -131,13 +131,12 @@ public function testSetColSpan1() $this->assertEquals($aProps['COLSPAN'], $mock->getColSpan()); } - public function testSetProperties() { $pdf = $this->getPdfObject(); $mock = new CellAbstractMock($pdf); - $aProps = array( + $aProps = [ 'ALIGN' => 'R', 'VERTICAL_ALIGN' => 'T', 'COLSPAN' => 5, @@ -147,7 +146,7 @@ public function testSetProperties() 'BORDER_SIZE' => 2.5, 'BORDER_COLOR' => [1, 2, 3], 'BACKGROUND_COLOR' => [5, 6, 7], - ); + ]; $mock->setProperties($aProps); //$this->assertEquals($aProps['ALIGN'], $o->getAlignVertical()) @@ -179,15 +178,15 @@ public function testSetDefaultValues() $pdf = $this->getPdfObject(); $mock = new CellAbstractMock($pdf); - $aProps = array( + $aProps = [ 'ALIGN' => 'R', 'VERTICAL_ALIGN' => 'T', 'COLSPAN' => 5, 'ROWSPAN' => 6, 'BACKGROUND_COLOR' => [5, 6, 7], - ); + ]; - $aDefault = array( + $aDefault = [ 'ALIGN' => 'M', 'VERTICAL_ALIGN' => 'M', 'COLSPAN' => 1, @@ -197,8 +196,7 @@ public function testSetDefaultValues() 'BORDER_SIZE' => 1, 'BORDER_COLOR' => [2, 2, 2], 'BACKGROUND_COLOR' => [3, 3, 3], - ); - + ]; $mock->setProperties($aProps); $mock->setDefaultValues($aDefault); @@ -255,7 +253,6 @@ public function testIsPropertySetReturnValue() error_reporting($error_level); } - protected function doTestAnyValue($setter, $getter) { $pdf = $this->getPdfObject(); @@ -288,7 +285,6 @@ protected function doTestPositiveInteger($setter, $getter) $this->assertEquals(2, $mock->$getter()); } - public function testRenderCellLayout() { $pdf = $this->getPdfObject(); @@ -318,7 +314,7 @@ public function testCopyProperties() $mock = new CellAbstractMock($pdf); $source = new CellAbstractMock($pdf); - $aProps = array( + $aProps = [ 'ALIGN' => 'R', 'VERTICAL_ALIGN' => 'T', 'COLSPAN' => 5, @@ -328,7 +324,7 @@ public function testCopyProperties() 'BORDER_SIZE' => 2.5, 'BORDER_COLOR' => [1, 2, 3], 'BACKGROUND_COLOR' => [5, 6, 7], - ); + ]; $source->setProperties($aProps); $mock->copyProperties($source); @@ -353,12 +349,8 @@ public function _testProcessContent() $mock->processContent(); } - /** * Test float Greater Than 0 - * - * @param $setter - * @param $getter */ protected function doTestFloatGT0($setter, $getter) { @@ -375,16 +367,12 @@ protected function doTestFloatGT0($setter, $getter) $mock->$setter(0.1); $this->assertEquals(0.1, $mock->$getter()); - $mock->$setter(1); $this->assertEquals(1, $mock->$getter()); } /** * Test float Greater Than 0 - * - * @param $setter - * @param $getter */ protected function doTestBoolean($setter, $getter) { diff --git a/tests/Unit/ToolsTest.php b/tests/Unit/ToolsTest.php index 5798254..94eaf23 100644 --- a/tests/Unit/ToolsTest.php +++ b/tests/Unit/ToolsTest.php @@ -1,6 +1,7 @@ assertSame([], Tools::parseHtmlAttribute('')); $this->assertSame([ 'color' => '#0000BB', - 'font-size' => '20px' + 'font-size' => '20px', ], Tools::parseHtmlAttribute('color: #0000BB; font-size: 20px')); } public function testParseColor(): void { $this->assertSame([255, 255, 255], Tools::parseColor([255, 255, 255])); - $this->assertSame([255, 255, 255], Tools::parseColor("255,255,255")); - $this->assertSame([0, 0, 0], Tools::parseColor("0,0,0")); - $this->assertSame([255, 255, 255], Tools::parseColor("255,255,255")); - $this->assertSame([0, 0, 0], Tools::parseColor("rgb(0,0,0)")); - $this->assertSame([255, 255, 255], Tools::parseColor("rgb(255,255,255)")); - $this->assertSame([255, 68, 204], Tools::parseColor("#ff44cc")); - $this->assertSame([255, 68, 204], Tools::parseColor("ff44cc")); - $this->assertSame([255, 68, 204], Tools::parseColor("#f4c")); - $this->assertSame([255, 68, 204], Tools::parseColor("f4c")); - $this->assertSame(['#f4'], Tools::parseColor("#f4")); - $this->assertSame(['f489'], Tools::parseColor("f489")); + $this->assertSame([255, 255, 255], Tools::parseColor('255,255,255')); + $this->assertSame([0, 0, 0], Tools::parseColor('0,0,0')); + $this->assertSame([255, 255, 255], Tools::parseColor('255,255,255')); + $this->assertSame([0, 0, 0], Tools::parseColor('rgb(0,0,0)')); + $this->assertSame([255, 255, 255], Tools::parseColor('rgb(255,255,255)')); + $this->assertSame([255, 68, 204], Tools::parseColor('#ff44cc')); + $this->assertSame([255, 68, 204], Tools::parseColor('ff44cc')); + $this->assertSame([255, 68, 204], Tools::parseColor('#f4c')); + $this->assertSame([255, 68, 204], Tools::parseColor('f4c')); + $this->assertSame(['#f4'], Tools::parseColor('#f4')); + $this->assertSame(['f489'], Tools::parseColor('f489')); } public function testHex2rgb(): void { - $this->assertSame([255, 68, 204], Tools::hex2rgb("#ff44cc")); - $this->assertSame([255, 68, 204], Tools::hex2rgb("ff44cc")); - $this->assertSame([255, 68, 204], Tools::hex2rgb("#f4c")); - $this->assertSame([255, 68, 204], Tools::hex2rgb("f4c")); - $this->assertSame(null, Tools::hex2rgb("#f4")); - $this->assertSame(null, Tools::hex2rgb("f489")); + $this->assertSame([255, 68, 204], Tools::hex2rgb('#ff44cc')); + $this->assertSame([255, 68, 204], Tools::hex2rgb('ff44cc')); + $this->assertSame([255, 68, 204], Tools::hex2rgb('#f4c')); + $this->assertSame([255, 68, 204], Tools::hex2rgb('f4c')); + $this->assertSame(null, Tools::hex2rgb('#f4')); + $this->assertSame(null, Tools::hex2rgb('f489')); } } diff --git a/tests/Utils/Helper.php b/tests/Utils/Helper.php index 5d355a2..0f51d1f 100644 --- a/tests/Utils/Helper.php +++ b/tests/Utils/Helper.php @@ -15,10 +15,10 @@ class Helper public static function pdfObject1() { //create the pdf object and do some initialization - $pdf = new TestPdf('P', 'mm', array( + $pdf = new TestPdf('P', 'mm', [ 130, - 180 - )); + 180, + ]); PdfFactory::initPdf($pdf); @@ -28,9 +28,6 @@ public static function pdfObject1() return $pdf; } - /** - * @param object $pdf - */ public static function setFontStyle1(object $pdf): void { $pdf->SetFont('helvetica', 'I', 7); @@ -47,24 +44,25 @@ public static function pdfScreenshot($pdf, $dest = null, $page = 0) '300', $pdf . "[$page]", '-flatten', - $dest + $dest, ]); // print_r($process->getCommandLine()); - if (!$dest) { + if (! $dest) { $dest = TestUtils::replaceExtension($pdf, 'png'); } $dir = dirname($dest); - if (!is_dir($dir)) { + if (! is_dir($dir)) { mkdir($dir); } $process->run(); - if (!$process->isSuccessful()) { + if (! $process->isSuccessful()) { echo $process->getErrorOutput() . PHP_EOL; } + return $dest; } } diff --git a/tests/Utils/TestPdf.php b/tests/Utils/TestPdf.php index 0f85603..34286cc 100644 --- a/tests/Utils/TestPdf.php +++ b/tests/Utils/TestPdf.php @@ -2,13 +2,14 @@ /** * phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps + * * @SuppressWarnings(PHPMD.CamelCaseMethodName) */ namespace EvoSys21\PdfLib\Tests\Utils; -use EvoSys21\PdfLib\Fpdf\Pdf; use EvoSys21\PdfLib\Examples\Tfpdf\MyPdf; +use EvoSys21\PdfLib\Fpdf\Pdf; /** * TestPdf Class @@ -18,6 +19,7 @@ class TestPdf extends MyPdf { /** * Custom Header + * * @see Pdf::Header() */ public function Header() @@ -26,6 +28,7 @@ public function Header() /** * Custom Footer + * * @see Pdf::Footer() */ public function Footer() diff --git a/tests/Utils/TestUtils.php b/tests/Utils/TestUtils.php index 6ccd532..1c7beaa 100644 --- a/tests/Utils/TestUtils.php +++ b/tests/Utils/TestUtils.php @@ -6,7 +6,6 @@ /** * Testing Utilities and Helpers - * @package App\Utils\Testing */ class TestUtils { @@ -18,22 +17,21 @@ class TestUtils * @param string $file File to be saved to * @param string|array $data Data to be written * @param bool $force Force write to file - * @return void */ public static function toFile(string $file, $data, bool $force = false): void { - if (!static::generateOn($force)) { + if (! static::generateOn($force)) { return; } - if (!static::$notified) { + if (! static::$notified) { print_r(PHP_EOL . str_repeat('x', 80)); - print_r(PHP_EOL . "!!! TESTS_FILE_GENERATE - ON !!!"); + print_r(PHP_EOL . '!!! TESTS_FILE_GENERATE - ON !!!'); print_r(PHP_EOL . str_repeat('x', 80)); print_r(PHP_EOL); static::$notified = true; } $md5 = is_readable($file) ? md5_file($file) : null; - if (!is_string($data)) { + if (! is_string($data)) { $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } else { if (file_exists($data)) { @@ -51,10 +49,6 @@ public static function toFile(string $file, $data, bool $force = false): void /** * Reads the $data from the specified file - * - * @param string $file - * @param bool $decode - * @return mixed */ public static function fromFile(string $file, bool $decode = false): mixed { @@ -62,6 +56,7 @@ public static function fromFile(string $file, bool $decode = false): mixed if ($decode) { return json_decode($content, true); } + return $content; } @@ -83,21 +78,24 @@ public static function isDebug(): bool public static function copy($src, $dst): bool { static::mkdir($dst); + return copy($src, $dst); } public static function mkdir(string $dir): bool { $dir = dirname($dir); - if (!is_dir($dir)) { + if (! is_dir($dir)) { return mkdir($dir, 0777, true); } + return true; } public static function relativePath(string $path): string { $path = realpath($path); + return str_replace(TEST_PATH, '', $path); } @@ -109,12 +107,14 @@ public static function failPath(string $path): string public static function coreName(string $path): string { $pathInfo = pathinfo($path); + return $pathInfo['filename']; } public static function replaceExtension($path, $ext): string { $pathInfo = pathinfo($path); + return $pathInfo['dirname'] . DIRECTORY_SEPARATOR . $pathInfo['filename'] . '.' . $ext; } @@ -125,8 +125,8 @@ public static function execRequire($require): string $content = ob_get_clean(); //CreationDate (D:20240101010000) - $content = preg_replace("#CreationDate \(D:[0-9]+#", "CreationDate (D:20240101010000", $content); - $content = preg_replace("#LastModified \(D:[0-9]+#", "LastModified (D:20240101010000", $content); + $content = preg_replace("#CreationDate \(D:[0-9]+#", 'CreationDate (D:20240101010000', $content); + $content = preg_replace("#LastModified \(D:[0-9]+#", 'LastModified (D:20240101010000', $content); return $content; } diff --git a/tests/_files/dev/Fpdf/test-multicell-style.pdf b/tests/_files/dev/Fpdf/test-multicell-style.pdf index d628c31..45e2631 100644 Binary files a/tests/_files/dev/Fpdf/test-multicell-style.pdf and b/tests/_files/dev/Fpdf/test-multicell-style.pdf differ diff --git a/tests/_files/dev/Tcpdf/test-multicell-style.pdf b/tests/_files/dev/Tcpdf/test-multicell-style.pdf index b630a96..40758f3 100644 Binary files a/tests/_files/dev/Tcpdf/test-multicell-style.pdf and b/tests/_files/dev/Tcpdf/test-multicell-style.pdf differ diff --git a/tests/_files/dev/Tfpdf/test-multicell-style.pdf b/tests/_files/dev/Tfpdf/test-multicell-style.pdf index 024d8a8..cc5d44c 100644 Binary files a/tests/_files/dev/Tfpdf/test-multicell-style.pdf and b/tests/_files/dev/Tfpdf/test-multicell-style.pdf differ diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a234e3c..f686483 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,7 +1,7 @@