Skip to content

Commit

Permalink
QA Fixes. phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
klodoma committed Oct 25, 2024
1 parent 16bdaec commit 2b70cd5
Show file tree
Hide file tree
Showing 27 changed files with 86 additions and 420 deletions.
2 changes: 1 addition & 1 deletion dev/dev-example-multicell.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
$multicell->setStyle('bi', null, 'BI');
$multicell->setStyle('u', null, 'U');
$multicell->setStyle('h', null, 'B', '203,0,48');
$multicell->setStyle('s', 8, null);
$multicell->setStyle('s', 8);
$multicell->setStyle('title', 14, null, [102, 0, 0], null, 'h');
$multicell->setStyle('h1', 16, null, null, null, 'h');
$multicell->setStyle('h2', 14, null, null, null, 'h');
Expand Down
4 changes: 2 additions & 2 deletions dev/example-table-dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@

// Set the styles for the advanced table
$table->setStyle('default', 11, '', [0, 0, 77], 'helvetica');
$table->setStyle('p', null, null);
$table->setStyle('p');
$table->setStyle('b', null, 'B');
$table->setStyle('i', null, 'I');
$table->setStyle('bi', null, 'BI');
$table->setStyle('u', null, 'U');
$table->setStyle('h', null, 'B', '203,0,48');
$table->setStyle('s', 8, null);
$table->setStyle('s', 8);
$table->setStyle('title', 14, null, [102, 0, 0], null, 'h');
$table->setStyle('h1', 16, null, null, null, 'h');
$table->setStyle('h2', 14, null, null, null, 'h');
Expand Down
4 changes: 2 additions & 2 deletions dev/example-table-dev1.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@

// Set the styles for the advanced table
$table->setStyle('default', 11, '', [0, 0, 77], 'helvetica');
$table->setStyle('p', null, null);
$table->setStyle('p');
$table->setStyle('b', null, 'B');
$table->setStyle('i', null, 'I');
$table->setStyle('bi', null, 'BI');
$table->setStyle('u', null, 'U');
$table->setStyle('h', null, 'B', '203,0,48');
$table->setStyle('s', 8, null);
$table->setStyle('s', 8);
$table->setStyle('title', 14, null, [102, 0, 0], null, 'h');
$table->setStyle('h1', 16, null, null, null, 'h');
$table->setStyle('h2', 14, null, null, null, 'h');
Expand Down
2 changes: 1 addition & 1 deletion docs/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ $table = new Table($pdf, 'path/to/my-table.config.php');

If `PDF_TABLE_CONFIG_PATH` value is defined, then the `table.config.php` is being looked up in that folder too.

The values specified in this file are used by default. The configuration file content looks like the following and it
The values specified in this file are used by default. The configuration file content looks like the following, and it
contains all the values that you can specify for a header/row.

```php
Expand Down
6 changes: 4 additions & 2 deletions examples/Fpdf/table/code-example-transparent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use EvoSys21\PdfLib\Table;
use EvoSys21\PdfLib\Examples\Fpdf\MyPdf;
use EvoSys21\PdfLib\Examples\Fpdf\PdfSettings;
use EvoSys21\PdfLib\Table\Cell\Image;
use EvoSys21\PdfLib\Table\Cell\Multicell;

if (!isset($pdf)) {
$pdf = new MyPdf();
Expand Down Expand Up @@ -65,8 +67,8 @@
$row = [];

//alternatively you can create directly the cell object
$row[0] = new \EvoSys21\PdfLib\Table\Cell\Image($pdf, CONTENT_PATH . '/images/blog.jpg', 10);
$row[1] = new \EvoSys21\PdfLib\Table\Cell\Multicell($pdf, "<p>This is another <b>Multicell</b></p>");
$row[0] = new Image($pdf, CONTENT_PATH . '/images/blog.jpg', 10);
$row[1] = new Multicell($pdf, "<p>This is another <b>Multicell</b></p>");
$row[2]['TEXT'] = "<p>All <b>table cells</b> are fully functional <bi>Advanced Multicells</bi>\nDetails on <bi href='https://github.com/evosys21/pdflib'>https://github.com/evosys21/pdflib</bi></p>";
$row[2]['BACKGROUND_COLOR'] = PdfSettings::$colors[1];

Expand Down
5 changes: 3 additions & 2 deletions examples/Fpdf/table/code-example2.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use EvoSys21\PdfLib\Table;
use EvoSys21\PdfLib\Examples\Fpdf\MyPdf;
use EvoSys21\PdfLib\Examples\Fpdf\PdfSettings;
use EvoSys21\PdfLib\Table\Cell\Image;

if (!isset($pdf)) {
$pdf = new MyPdf();
Expand Down Expand Up @@ -49,13 +50,13 @@
$row = [];

//alternatively you can create directly the cell object
$row[0] = new \EvoSys21\PdfLib\Table\Cell\Image($pdf, CONTENT_PATH . '/images/blog.jpg', 10);
$row[0] = new Image($pdf, CONTENT_PATH . '/images/blog.jpg', 10);
$row[1] = array(
'TEXT' => "<p>This is another <b>Multicell</b></p>",
'BACKGROUND_COLOR' => PdfSettings::$colors[0]
);

$row[2] = new \EvoSys21\PdfLib\Table\Cell\Image($pdf, CONTENT_PATH . '/images/pensil.jpg', 10);
$row[2] = new Image($pdf, CONTENT_PATH . '/images/pencil.jpg', 10);
$row[2]->setAlign("R");

//add the data row
Expand Down
6 changes: 3 additions & 3 deletions examples/Tcpdf/example-multicell-3-line-breaking.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
$txt = 'This is a demo of <b>NON BREAKING > S P>A C E EXAMPLE</b>';

//create an advanced multicell
$multicell->multiCell(0, 5, 'Default line breaking characters: ,.:;', 0);
$multicell->multiCell(0, 5, 'Default line breaking characters: ,.:;');
$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', 0);
$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', 0);
$multicell->multiCell(0, 5, 'Reseting the line breaking characters');
$multicell->resetLineBreakingCharacters();
$multicell->multiCell(100, 5, $txt, 1);
$pdf->Ln(10); //new line
Expand Down
2 changes: 1 addition & 1 deletion examples/Tcpdf/example-multicell-4-page-break.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
$txt .= '</p>';

//create an advanced multicell
$multicell->multiCell(0, 5, $txt, 1, 'J', 1, 0, 0, 0, 0);
$multicell->multiCell(0, 5, $txt, 1, 'J', 1);

$pdf->Ln(10); // new line

Expand Down
2 changes: 1 addition & 1 deletion examples/Tcpdf/example-multicell.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
$multicell->setStyle('bi', null, 'BI');
$multicell->setStyle('u', null, 'U');
$multicell->setStyle('h', null, 'B', '203,0,48');
$multicell->setStyle('s', 8, null);
$multicell->setStyle('s', 8);
$multicell->setStyle('title', 14, null, [102, 0, 0], null, 'h');
$multicell->setStyle('h1', 16, null, null, null, 'h');
$multicell->setStyle('h2', 14, null, null, null, 'h');
Expand Down
6 changes: 4 additions & 2 deletions examples/Tcpdf/table/code-example-transparent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use EvoSys21\PdfLib\Examples\Tcpdf\MyPdf;
use EvoSys21\PdfLib\Table;
use EvoSys21\PdfLib\Examples\Tcpdf\PdfSettings;
use EvoSys21\PdfLib\Table\Cell\Image;
use EvoSys21\PdfLib\Table\Cell\Multicell;

if (!isset($pdf)) {
$pdf = new MyPdf();
Expand Down Expand Up @@ -63,8 +65,8 @@
$row = [];

//alternatively you can create directly the cell object
$row[0] = new \EvoSys21\PdfLib\Table\Cell\Image($pdf, CONTENT_PATH . '/images/blog.jpg', 10);
$row[1] = new \EvoSys21\PdfLib\Table\Cell\Multicell($pdf, "<p>This is another <b>Multicell</b></p>");
$row[0] = new Image($pdf, CONTENT_PATH . '/images/blog.jpg', 10);
$row[1] = new Multicell($pdf, "<p>This is another <b>Multicell</b></p>");
$row[2]['TEXT'] = "<p>All <b>table cells</b> are fully functional <bi>Advanced Multicells</bi>\nDetails on <bi href='https://github.com/evosys21/pdflib'>https://github.com/evosys21/pdflib</bi></p>";
$row[2]['BACKGROUND_COLOR'] = PdfSettings::$colors[1];

Expand Down
6 changes: 4 additions & 2 deletions examples/Tfpdf/table/code-example-transparent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use EvoSys21\PdfLib\Examples\Tfpdf\MyPdf;
use EvoSys21\PdfLib\Table;
use EvoSys21\PdfLib\Examples\Tfpdf\PdfSettings;
use EvoSys21\PdfLib\Table\Cell\Image;
use EvoSys21\PdfLib\Table\Cell\Multicell;

if (!isset($pdf)) {
$pdf = new MyPdf();
Expand Down Expand Up @@ -65,8 +67,8 @@
$row = [];

//alternatively you can create directly the cell object
$row[0] = new \EvoSys21\PdfLib\Table\Cell\Image($pdf, CONTENT_PATH . '/images/blog.jpg', 10);
$row[1] = new \EvoSys21\PdfLib\Table\Cell\Multicell($pdf, "<p>This is another <b>Multicell</b></p>");
$row[0] = new Image($pdf, CONTENT_PATH . '/images/blog.jpg', 10);
$row[1] = new Multicell($pdf, "<p>This is another <b>Multicell</b></p>");
$row[2]['TEXT'] = "<p>All <b>table cells</b> are fully functional <bi>Advanced Multicells</bi>\nDetails on <bi href='https://github.com/evosys21/pdflib'>https://github.com/evosys21/pdflib</bi></p>";
$row[2]['BACKGROUND_COLOR'] = PdfSettings::$colors[1];

Expand Down
2 changes: 1 addition & 1 deletion examples/Tfpdf/table/code-example2.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
'BACKGROUND_COLOR' => PdfSettings::$colors[0]
);

$row[2] = new Table\Cell\Image($pdf, CONTENT_PATH . '/images/pensil.jpg', 10);
$row[2] = new Table\Cell\Image($pdf, CONTENT_PATH . '/images/pencil.jpg', 10);
$row[2]->setAlign("R");

//add the data row
Expand Down
File renamed without changes
4 changes: 2 additions & 2 deletions src/Fpdf/PdfInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function setTextColor($color): self
{
$this->textColor = $color;

if (is_string($color) && strpos($color, self::RAW) === 0) {
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;
Expand All @@ -257,7 +257,7 @@ public function setTextColor($color): self
public function setDrawColor($color): self
{
$this->backupDrawColor = $this->pdf->DrawColor;
if (is_string($color) && strpos($color, self::RAW) === 0) {
if (is_string($color) && str_starts_with($color, self::RAW)) {
$this->pdf->DrawColor = substr($color, strlen(self::RAW));
return $this;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Multicell.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function setStyle(string $tag, $fontSize = null, ?string $fontStyle = nul
$this->pdf->Error("Empty TAG Name.");
}

$inherit = strval($inherit);
$inherit = $inherit;

//use case insensitive tags
$tag = trim(strtoupper($tag));
Expand Down Expand Up @@ -427,7 +427,7 @@ protected function applyStyle(string $tag, array $style = [])
$fontSize = $this->getTagSize($tag);
}

if (strpos($fontSize, '%') !== false) {
if (str_contains($fontSize, '%')) {
$fontSize = $this->pdf->FontSizePt * (((float)$fontSize) / 100);
}

Expand Down Expand Up @@ -518,7 +518,7 @@ protected function makeLine($width, $line): array
}

$isParagraph = false;
if (($s == "\t") && (strpos($tag, 'pparg') !== false)) {
if (($s == "\t") && (str_contains($tag, 'pparg'))) {
$isParagraph = true;
$s = "\t"; //place instead a TAB
}
Expand Down
52 changes: 18 additions & 34 deletions src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,24 +599,16 @@ protected function markMarginX()
$tb_align = $this->getTableConfig('TABLE_ALIGN');

//set the table align
switch ($tb_align) {
case 'C':
$this->tableStartX = $this->pdf->lMargin +
$this->getTableConfig('TABLE_LEFT_MARGIN') +
($this->pageWidth() - $this->getWidth()) / 2;
break;
case 'R':
$this->tableStartX = $this->pdf->lMargin +
$this->getTableConfig('TABLE_LEFT_MARGIN') +
($this->pageWidth() - $this->getWidth());
break;
case 'L':
$this->tableStartX = $this->pdf->lMargin + $this->getTableConfig('TABLE_LEFT_MARGIN');
break;
default:
$this->tableStartX = $this->pdf->getX();
break;
}
$this->tableStartX = match ($tb_align) {
'C' => $this->pdf->lMargin +
$this->getTableConfig('TABLE_LEFT_MARGIN') +
($this->pageWidth() - $this->getWidth()) / 2,
'R' => $this->pdf->lMargin +
$this->getTableConfig('TABLE_LEFT_MARGIN') +
($this->pageWidth() - $this->getWidth()),
'L' => $this->pdf->lMargin + $this->getTableConfig('TABLE_LEFT_MARGIN'),
default => $this->pdf->getX(),
};
}


Expand Down Expand Up @@ -768,15 +760,10 @@ public function addPageBreak()
*/
protected function applyDefaultValues(array $aData, string $sDataType): array
{
switch ($sDataType) {
case 'header':
$aReference = $this->configuration['HEADER'];
break;

default:
$aReference = $this->configuration['ROW'];
break;
}
$aReference = match ($sDataType) {
'header' => $this->configuration['HEADER'],
default => $this->configuration['ROW'],
};

return array_merge($aReference, $aData);
}
Expand All @@ -790,13 +777,10 @@ protected function applyDefaultValues(array $aData, string $sDataType): array
*/
protected function getDefaultValues(string $sDataType): array
{
switch ($sDataType) {
case 'header':
return $this->configuration['HEADER'];

default:
return $this->configuration['ROW'];
}
return match ($sDataType) {
'header' => $this->configuration['HEADER'],
default => $this->configuration['ROW'],
};
}


Expand Down
10 changes: 5 additions & 5 deletions src/Table/Cell/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ public function render()
$y = $this->pdf->GetY() + $this->getBorderSize();

//Horizontal Alignment
if (strpos($this->alignment, 'J') !== false) {
if (str_contains($this->alignment, 'J')) {
//justified - image is fully stretched
$x += $this->getPaddingLeft();
$this->setContentWidth($this->getCellDrawWidth() - 2 * $this->getBorderSize() - $this->getPaddingLeft() - $this->getPaddingRight());
} elseif (strpos($this->alignment, 'C') !== false) {
} elseif (str_contains($this->alignment, 'C')) {
//center
$x += ($this->getCellDrawWidth() - $this->getContentWidth()) / 2;
} elseif (strpos($this->alignment, 'R') !== false) {
} elseif (str_contains($this->alignment, 'R')) {
//right
$x += $this->getCellDrawWidth() - $this->getContentWidth() - $this->getPaddingRight();
} else {
Expand All @@ -142,10 +142,10 @@ public function render()
}

//Vertical Alignment
if (strpos($this->alignment, 'T') !== false) {
if (str_contains($this->alignment, 'T')) {
//top
$y += $this->getPaddingTop();
} elseif (strpos($this->alignment, 'B') !== false) {
} elseif (str_contains($this->alignment, 'B')) {
//bottom
$y += $this->getCellDrawHeight() - $this->getContentHeight() - $this->getPaddingBottom();
} else {
Expand Down
19 changes: 12 additions & 7 deletions src/Table/Cell/ImageSVG.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<?php
/** @noinspection PhpUndefinedMethodInspection */
/** @noinspection PhpUndefinedFieldInspection */

namespace EvoSys21\PdfLib\Table\Cell;

use TCPDF_IMAGES;
use TCPDF_STATIC;

/**
* Pdf Table Cell SVG Image
*/
class ImageSVG extends Image
{
public function isImageSVG($file): bool
{
return \TCPDF_IMAGES::getImageFileType($file) == 'svg';
return TCPDF_IMAGES::getImageFileType($file) == 'svg';
}

public function setImage($file = '', $width = 0, $height = 0, $type = '', $link = '')
Expand All @@ -33,7 +38,7 @@ public function setImage($file = '', $width = 0, $height = 0, $type = '', $link

private function getImageParamsSVG($file, $w = 0, $h = 0)
{
$svgData = \TCPDF_STATIC::fileGetContents($file);
$svgData = TCPDF_STATIC::fileGetContents($file);

if ($svgData === false) {
$this->pdf->Error('SVG file not found: ' . $file);
Expand Down Expand Up @@ -90,17 +95,17 @@ public function render()
$y = $this->pdf->GetY() + $this->getBorderSize();

//Horizontal Alignment
if (strpos($this->alignment, 'J') !== false) {
if (str_contains($this->alignment, 'J')) {
//justified - image is fully stretched

//var_dump($this->getCellDrawWidth());

$x += $this->PADDING_LEFT;
$this->setContentWidth($this->getCellDrawWidth() - 2 * $this->getBorderSize() - $this->getPaddingLeft() - $this->getPaddingRight());
} elseif (strpos($this->alignment, 'C') !== false) {
} elseif (str_contains($this->alignment, 'C')) {
//center
$x += ($this->getCellDrawWidth() - $this->getContentWidth()) / 2;
} elseif (strpos($this->alignment, 'R') !== false) {
} elseif (str_contains($this->alignment, 'R')) {
//right
$x += $this->getCellDrawWidth() - $this->getContentWidth() - $this->getPaddingRight();
} else {
Expand All @@ -109,10 +114,10 @@ public function render()
}

//Vertical Alignment
if (strpos($this->alignment, 'T') !== false) {
if (str_contains($this->alignment, 'T')) {
//top
$y += $this->getPaddingTop();
} elseif (strpos($this->alignment, 'B') !== false) {
} elseif (str_contains($this->alignment, 'B')) {
//bottom
$y += $this->getCellDrawHeight() - $this->getContentHeight() - $this->getPaddingBottom();
} else {
Expand Down
Loading

0 comments on commit 2b70cd5

Please sign in to comment.