Skip to content

Commit

Permalink
Merge pull request #33 from Setasign/development
Browse files Browse the repository at this point in the history
Merge development branch into master
  • Loading branch information
JanSlabon authored Nov 13, 2017
2 parents e44dd4e + 511173d commit 879dd95
Show file tree
Hide file tree
Showing 27 changed files with 173 additions and 177 deletions.
26 changes: 13 additions & 13 deletions src/FpdfTpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class FpdfTpl extends \FPDF
*/
public function setPageFormat($size, $orientation)
{
if (!in_array($orientation, ['P', 'L'], true)) {
throw new \InvalidArgumentException(sprintf(
if (!\in_array($orientation, ['P', 'L'], true)) {
throw new \InvalidArgumentException(\sprintf(
'Invalid page orientation "%s"! Only "P" and "L" are allowed!',
$orientation
));
Expand Down Expand Up @@ -101,12 +101,12 @@ public function useTemplate($tpl, $x = 0, $y = 0, $width = null, $height = null,
throw new \InvalidArgumentException('Template does not exist!');
}

if (is_array($x)) {
if (\is_array($x)) {
unset($x['tpl']);
extract($x, EXTR_IF_EXISTS);
\extract($x, EXTR_IF_EXISTS);
/** @noinspection NotOptimalIfConditionsInspection */
/** @noinspection CallableParameterUseCaseInTypeContextInspection */
if (is_array($x)) {
if (\is_array($x)) {
$x = 0;
}
}
Expand All @@ -121,7 +121,7 @@ public function useTemplate($tpl, $x = 0, $y = 0, $width = null, $height = null,

$this->_out(
// reset standard values, translate and scale
sprintf(
\sprintf(
'q 0 J 1 w 0 j 0 G 0 g %.4F 0 0 %.4F %.4F %.4F cm /%s Do Q',
($newSize['width'] / $originalSize['width']),
($newSize['height'] / $originalSize['height']),
Expand Down Expand Up @@ -196,10 +196,10 @@ public function beginTemplate($width = null, $height = null)

// initiate buffer with current state of FPDF
$buffer = "2 J\n"
. sprintf('%.2F w', $this->LineWidth * $this->k) . "\n";
. \sprintf('%.2F w', $this->LineWidth * $this->k) . "\n";

if ($this->FontFamily) {
$buffer .= sprintf("BT /F%d %.2F Tf ET\n", $this->CurrentFont['i'], $this->FontSizePt);
$buffer .= \sprintf("BT /F%d %.2F Tf ET\n", $this->CurrentFont['i'], $this->FontSizePt);
}

if ($this->DrawColor !== '0 G') {
Expand Down Expand Up @@ -347,7 +347,7 @@ public function SetLineWidth($width)
{
parent::SetLineWidth($width);
if ($this->page === 0 && $this->currentTemplateId !== null) {
$this->_out(sprintf('%.2F w', $width * $this->k));
$this->_out(\sprintf('%.2F w', $width * $this->k));
}
}

Expand All @@ -358,7 +358,7 @@ public function SetFont($family, $style = '', $size = 0)
{
parent::SetFont($family, $style, $size);
if ($this->page === 0 && $this->currentTemplateId !== null) {
$this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
$this->_out(\sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
}
}

Expand All @@ -385,17 +385,17 @@ protected function _putimages()
$this->templates[$key]['objectNumber'] = $this->n;

$this->_put('<</Type /XObject /Subtype /Form /FormType 1');
$this->_put(sprintf('/BBox[0 0 %.2F %.2F]', $template['width'] * $this->k, $template['height'] * $this->k));
$this->_put(\sprintf('/BBox[0 0 %.2F %.2F]', $template['width'] * $this->k, $template['height'] * $this->k));
$this->_put('/Resources 2 0 R'); // default resources dictionary of FPDF

if ($this->compress) {
$buffer = gzcompress($template['buffer']);
$buffer = \gzcompress($template['buffer']);
$this->_put('/Filter/FlateDecode');
} else {
$buffer = $template['buffer'];
}

$this->_put('/Length ' . strlen($buffer));
$this->_put('/Length ' . \strlen($buffer));
$this->_put('>>');
$this->_putstream($buffer);
$this->_put('endobj');
Expand Down
4 changes: 2 additions & 2 deletions src/Fpdi.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ protected function _putimages()
$this->_put('endobj');
}

foreach (array_keys($this->readers) as $readerId) {
foreach (\array_keys($this->readers) as $readerId) {
$parser = $this->getPdfReader($readerId)->getParser();
$this->currentReaderId = $readerId;

while (($objectNumber = array_pop($this->objectsToCopy[$readerId])) !== null) {
while (($objectNumber = \array_pop($this->objectsToCopy[$readerId])) !== null) {
try {
$object = $parser->getIndirectObject($objectNumber);

Expand Down
50 changes: 25 additions & 25 deletions src/FpdiTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ trait FpdiTrait
*/
protected function setMinPdfVersion($pdfVersion)
{
if (version_compare($pdfVersion, $this->PDFVersion, '>')) {
if (\version_compare($pdfVersion, $this->PDFVersion, '>')) {
$this->PDFVersion = $pdfVersion;
}
}
Expand All @@ -100,7 +100,7 @@ protected function setMinPdfVersion($pdfVersion)
protected function getPdfParserInstance(StreamReader $streamReader)
{
/** @noinspection PhpUndefinedClassInspection */
if (class_exists(FpdiPdfParser::class)) {
if (\class_exists(FpdiPdfParser::class)) {
/** @noinspection PhpUndefinedClassInspection */
return new FpdiPdfParser($streamReader);
}
Expand All @@ -117,28 +117,28 @@ protected function getPdfParserInstance(StreamReader $streamReader)
*/
protected function getPdfReaderId($file)
{
if (is_resource($file)) {
if (\is_resource($file)) {
$id = (string) $file;
} elseif (is_string($file)) {
$id = realpath($file);
} elseif (\is_string($file)) {
$id = \realpath($file);
if (false === $id) {
$id = $file;
}
} elseif (is_object($file)) {
$id = spl_object_hash($file);
} elseif (\is_object($file)) {
$id = \spl_object_hash($file);
} else {
throw new \InvalidArgumentException(
sprintf('Invalid type in $file parameter (%s)', gettype($file))
\sprintf('Invalid type in $file parameter (%s)', \gettype($file))
);
}

if (isset($this->readers[$id])) {
return $id;
}

if (is_resource($file)) {
if (\is_resource($file)) {
$streamReader = new StreamReader($file);
} elseif (is_string($file)) {
} elseif (\is_string($file)) {
$streamReader = StreamReader::createByFile($file);
} else {
$streamReader = $file;
Expand All @@ -163,7 +163,7 @@ protected function getPdfReader($id)
}

throw new \InvalidArgumentException(
sprintf('No pdf reader with the given id (%s) exists.', $id)
\sprintf('No pdf reader with the given id (%s) exists.', $id)
);
}

Expand Down Expand Up @@ -206,10 +206,10 @@ public function importPage($pageNumber, $box = PageBoundaries::CROP_BOX, $groupX
$pageId .= '|' . $pageNumber . '|' . ($groupXObject ? '1' : '0');

// for backwards compatibility with FPDI 1
$box = ltrim($box, '/');
$box = \ltrim($box, '/');
if (!PageBoundaries::isValidName($box)) {
throw new \InvalidArgumentException(
sprintf('Box name is invalid: "%s"', $box)
\sprintf('Box name is invalid: "%s"', $box)
);
}

Expand All @@ -225,7 +225,7 @@ public function importPage($pageNumber, $box = PageBoundaries::CROP_BOX, $groupX
$bbox = $page->getBoundary($box);
if ($bbox === false) {
throw new PdfReaderException(
sprintf("Page doesn't have a boundary box (%s).", $box),
\sprintf("Page doesn't have a boundary box (%s).", $box),
PdfReaderException::MISSING_DATA
);
}
Expand Down Expand Up @@ -263,8 +263,8 @@ public function importPage($pageNumber, $box = PageBoundaries::CROP_BOX, $groupX
if ($rotation !== 0) {
$rotation *= -1;
$angle = $rotation * M_PI/180;
$a = cos($angle);
$b = sin($angle);
$a = \cos($angle);
$b = \sin($angle);
$c = -$b;
$d = $a;

Expand Down Expand Up @@ -300,7 +300,7 @@ public function importPage($pageNumber, $box = PageBoundaries::CROP_BOX, $groupX

// just copy the stream reference if it is only a single stream
if (($contentsIsStream = ($contents instanceof PdfStream))
|| ($contents instanceof PdfArray && count($contents->value) === 1)
|| ($contents instanceof PdfArray && \count($contents->value) === 1)
) {
if ($contentsIsStream) {
/**
Expand All @@ -322,10 +322,10 @@ public function importPage($pageNumber, $box = PageBoundaries::CROP_BOX, $groupX
// otherwise extract it from the array and re-compress the whole stream
} else {
$streamContent = $this->compress
? gzcompress($page->getContentStream())
? \gzcompress($page->getContentStream())
: $page->getContentStream();

$dict->value['Length'] = PdfNumeric::create(strlen($streamContent));
$dict->value['Length'] = PdfNumeric::create(\strlen($streamContent));
if ($this->compress) {
$dict->value['Filter'] = PdfName::create('FlateDecode');
}
Expand Down Expand Up @@ -363,11 +363,11 @@ public function importPage($pageNumber, $box = PageBoundaries::CROP_BOX, $groupX
*/
public function useImportedPage($pageId, $x = 0, $y = 0, $width = null, $height = null, $adjustPageSize = false)
{
if (is_array($x)) {
if (\is_array($x)) {
unset($x['pageId']);
extract($x, EXTR_IF_EXISTS);
\extract($x, EXTR_IF_EXISTS);
/** @noinspection NotOptimalIfConditionsInspection */
if (is_array($x)) {
if (\is_array($x)) {
$x = 0;
}
}
Expand All @@ -386,7 +386,7 @@ public function useImportedPage($pageId, $x = 0, $y = 0, $width = null, $height

$this->_out(
// reset standard values, translate and scale
sprintf(
\sprintf(
'q 0 J 1 w 0 j 0 G 0 g %.4F 0 0 %.4F %.4F %.4F cm /%s Do Q',
($newSize['width'] / $originalSize['width']),
($newSize['height'] / $originalSize['height']),
Expand Down Expand Up @@ -450,10 +450,10 @@ public function getImportedPageSize($tpl, $width = null, $height = null)
protected function writePdfType(PdfType $value)
{
if ($value instanceof PdfNumeric) {
if (is_int($value->value)) {
if (\is_int($value->value)) {
$this->_put($value->value . ' ', false);
} else {
$this->_put(rtrim(rtrim(sprintf('%.5F', $value->value), '0'), '.') . ' ', false);
$this->_put(\rtrim(\rtrim(\sprintf('%.5F', $value->value), '0'), '.') . ' ', false);
}

} elseif ($value instanceof PdfName) {
Expand Down
2 changes: 1 addition & 1 deletion src/PdfParser/CrossReference/AbstractReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function readTrailer()
$trailerKeyword->value !== 'trailer'
) {
throw new CrossReferenceException(
sprintf(
\sprintf(
'Unexpected end of cross reference. "trailer"-keyword expected, got: %s',
$trailerKeyword instanceof PdfToken ? $trailerKeyword->value : 'nothing'
),
Expand Down
10 changes: 5 additions & 5 deletions src/PdfParser/CrossReference/CrossReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function getIndirectObject($objectNumber)
$offset = $this->getOffsetFor($objectNumber);
if (false === $offset) {
throw new CrossReferenceException(
sprintf('Object (id:%s) not found.', $objectNumber),
\sprintf('Object (id:%s) not found.', $objectNumber),
CrossReferenceException::OBJECT_NOT_FOUND
);
}
Expand All @@ -155,14 +155,14 @@ public function getIndirectObject($objectNumber)
$object = $parser->readValue();
if (false === $object || !($object instanceof PdfIndirectObject)) {
throw new CrossReferenceException(
sprintf('Object (id:%s) not found at location (%s).', $objectNumber, $offset),
\sprintf('Object (id:%s) not found at location (%s).', $objectNumber, $offset),
CrossReferenceException::OBJECT_NOT_FOUND
);
}

if ($object->objectNumber !== $objectNumber) {
throw new CrossReferenceException(
sprintf('Wrong object found, got %s while %s was expected.', $object->objectNumber, $objectNumber),
\sprintf('Wrong object found, got %s while %s was expected.', $object->objectNumber, $objectNumber),
CrossReferenceException::OBJECT_NOT_FOUND
);
}
Expand Down Expand Up @@ -266,11 +266,11 @@ protected function findStartXref()
$reader->reset(-self::$trailerSearchLength, self::$trailerSearchLength);

$buffer = $reader->getBuffer(false);
$pos = strrpos($buffer, 'startxref');
$pos = \strrpos($buffer, 'startxref');
$addOffset = 9;
if (false === $pos) {
// Some corrupted documents uses startref, instead of startxref
$pos = strrpos($buffer, 'startref');
$pos = \strrpos($buffer, 'startref');
if (false === $pos) {
throw new CrossReferenceException(
'Unable to find pointer to xref table',
Expand Down
16 changes: 8 additions & 8 deletions src/PdfParser/CrossReference/FixedReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getOffsetFor($objectNumber)
return false;
}

return (int) substr($line, 0, 10);
return (int) \substr($line, 0, 10);
}
}

Expand All @@ -93,13 +93,13 @@ protected function read()
$startObject = $entryCount = $lastLineStart = null;
$validityChecked = false;
while (($line = $this->reader->readLine(20)) !== false) {
if (strpos($line, 'trailer') !== false) {
if (\strpos($line, 'trailer') !== false) {
$this->reader->reset($lastLineStart);
break;
}

// jump over if line content doesn't match the expected string
if (2 !== sscanf($line, '%d %d', $startObject, $entryCount)) {
if (2 !== \sscanf($line, '%d %d', $startObject, $entryCount)) {
continue;
}

Expand All @@ -111,7 +111,7 @@ protected function read()
/* Check the next line for maximum of 20 bytes and not longer
* By catching 21 bytes and trimming the length should be still 21.
*/
if (strlen(trim($nextLine)) !== 21) {
if (\strlen(\trim($nextLine)) !== 21) {
throw new CrossReferenceException(
'Cross-reference entries are larger than 20 bytes.',
CrossReferenceException::ENTRIES_TOO_LARGE
Expand All @@ -122,7 +122,7 @@ protected function read()
* If it would have less bytes the substring would get the first bytes of the next line which would
* evaluate to a 20 bytes long string after trimming.
*/
if (strlen(trim(substr($nextLine, 0, 20))) !== 18) {
if (\strlen(\trim(\substr($nextLine, 0, 20))) !== 18) {
throw new CrossReferenceException(
'Cross-reference entries are less than 20 bytes.',
CrossReferenceException::ENTRIES_TOO_SHORT
Expand All @@ -138,7 +138,7 @@ protected function read()
$this->reader->reset($lastLineStart);
}

if (count($subSections) === 0) {
if (\count($subSections) === 0) {
throw new CrossReferenceException(
'No entries found in cross-reference.',
CrossReferenceException::NO_ENTRIES
Expand Down Expand Up @@ -172,11 +172,11 @@ protected function read()
public function fixFaultySubSectionShift()
{
$subSections = $this->getSubSections();
if (count($subSections) > 1) {
if (\count($subSections) > 1) {
return false;
}

$subSection = current($subSections);
$subSection = \current($subSections);
if ($subSection[0] != 1) {
return false;
}
Expand Down
Loading

0 comments on commit 879dd95

Please sign in to comment.