-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from smalot/feature/add-cs-fixer
Add FriendsOfPHP/PHP-CS-Fixer to "require-dev" to enforce coding styles
- Loading branch information
Showing
54 changed files
with
1,201 additions
and
1,354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
/composer | ||
debug* | ||
composer.lock | ||
/.php_cs.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
return PhpCsFixer\Config::create() | ||
->setRules([ | ||
'@Symfony' => true, | ||
'@Symfony:risky' => true, | ||
'array_syntax' => ['syntax' => 'short'], | ||
'no_empty_phpdoc' => true, | ||
'no_unused_imports' => true, | ||
'no_superfluous_phpdoc_tags' => true, | ||
'ordered_imports' => true, | ||
'phpdoc_summary' => false, | ||
'protected_to_private' => false, | ||
]) | ||
->setRiskyAllowed(true) | ||
->setFinder( | ||
PhpCsFixer\Finder::create() | ||
->files() | ||
->in(__DIR__ . '/samples') | ||
->in(__DIR__ . '/src') | ||
->name('*.php') | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
* | ||
* @author Sébastien MALOT <[email protected]> | ||
* @date 2017-01-03 | ||
* | ||
* @license LGPLv3 | ||
* @url <https://github.com/smalot/pdfparser> | ||
* | ||
|
@@ -25,13 +26,10 @@ | |
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. | ||
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>. | ||
* | ||
*/ | ||
|
||
namespace Smalot\PdfParser; | ||
|
||
use Smalot\PdfParser\Element\ElementDate; | ||
|
||
/** | ||
* Technical references : | ||
* - http://www.mactech.com/articles/mactech/Vol.15/15.09/PDFIntro/index.html | ||
|
@@ -43,20 +41,18 @@ | |
* - http://cpansearch.perl.org/src/JV/PostScript-Font-1.10.02/lib/PostScript/WinAnsiEncoding.pm | ||
* | ||
* Class Document | ||
* | ||
* @package Smalot\PdfParser | ||
*/ | ||
class Document | ||
{ | ||
/** | ||
* @var PDFObject[] | ||
*/ | ||
protected $objects = array(); | ||
protected $objects = []; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $dictionary = array(); | ||
protected $dictionary = []; | ||
|
||
/** | ||
* @var Header | ||
|
@@ -68,17 +64,11 @@ class Document | |
*/ | ||
protected $details = null; | ||
|
||
/** | ||
* | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->trailer = new Header(array(), $this); | ||
$this->trailer = new Header([], $this); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function init() | ||
{ | ||
$this->buildDictionary(); | ||
|
@@ -97,7 +87,7 @@ public function init() | |
protected function buildDictionary() | ||
{ | ||
// Build dictionary. | ||
$this->dictionary = array(); | ||
$this->dictionary = []; | ||
|
||
foreach ($this->objects as $id => $object) { | ||
$type = $object->getHeader()->get('Type')->getContent(); | ||
|
@@ -114,23 +104,23 @@ protected function buildDictionary() | |
protected function buildDetails() | ||
{ | ||
// Build details array. | ||
$details = array(); | ||
$details = []; | ||
|
||
// Extract document info | ||
if ($this->trailer->has('Info')) { | ||
/** @var PDFObject $info */ | ||
$info = $this->trailer->get('Info'); | ||
// This could be an ElementMissing object, so we need to check for | ||
// the getHeader method first. | ||
if ($info !== null && method_exists($info, 'getHeader')) { | ||
if (null !== $info && method_exists($info, 'getHeader')) { | ||
$details = $info->getHeader()->getDetails(); | ||
} | ||
} | ||
|
||
// Retrieve the page count | ||
try { | ||
$pages = $this->getPages(); | ||
$details['Pages'] = count($pages); | ||
$details['Pages'] = \count($pages); | ||
} catch (\Exception $e) { | ||
$details['Pages'] = 0; | ||
} | ||
|
@@ -149,9 +139,9 @@ public function getDictionary() | |
/** | ||
* @param PDFObject[] $objects | ||
*/ | ||
public function setObjects($objects = array()) | ||
public function setObjects($objects = []) | ||
{ | ||
$this->objects = (array)$objects; | ||
$this->objects = (array) $objects; | ||
|
||
$this->init(); | ||
} | ||
|
@@ -186,11 +176,11 @@ public function getObjectById($id) | |
*/ | ||
public function getObjectsByType($type, $subtype = null) | ||
{ | ||
$objects = array(); | ||
$objects = []; | ||
|
||
foreach ($this->objects as $id => $object) { | ||
if ($object->getHeader()->get('Type') == $type && | ||
(is_null($subtype) || $object->getHeader()->get('Subtype') == $subtype) | ||
(null === $subtype || $object->getHeader()->get('Subtype') == $subtype) | ||
) { | ||
$objects[$id] = $object; | ||
} | ||
|
@@ -209,6 +199,7 @@ public function getFonts() | |
|
||
/** | ||
* @return Page[] | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function getPages() | ||
|
@@ -221,13 +212,14 @@ public function getPages() | |
$object = $this->objects[$id]->get('Pages'); | ||
if (method_exists($object, 'getPages')) { | ||
$pages = $object->getPages(true); | ||
|
||
return $pages; | ||
} | ||
} | ||
|
||
if (isset($this->dictionary['Pages'])) { | ||
// Search for pages to list kids. | ||
$pages = array(); | ||
$pages = []; | ||
|
||
/** @var Pages[] $objects */ | ||
$objects = $this->getObjectsByType('Pages'); | ||
|
@@ -255,14 +247,14 @@ public function getPages() | |
*/ | ||
public function getText(Page $page = null) | ||
{ | ||
$texts = array(); | ||
$texts = []; | ||
$pages = $this->getPages(); | ||
|
||
foreach ($pages as $index => $page) { | ||
/** | ||
* In some cases, the $page variable may be null. | ||
*/ | ||
if (is_null($page)) { | ||
if (null === $page) { | ||
continue; | ||
} | ||
if ($text = trim($page->getText())) { | ||
|
@@ -281,9 +273,6 @@ public function getTrailer() | |
return $this->trailer; | ||
} | ||
|
||
/** | ||
* @param Header $trailer | ||
*/ | ||
public function setTrailer(Header $trailer) | ||
{ | ||
$this->trailer = $trailer; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
* | ||
* @author Sébastien MALOT <[email protected]> | ||
* @date 2017-01-03 | ||
* | ||
* @license LGPLv3 | ||
* @url <https://github.com/smalot/pdfparser> | ||
* | ||
|
@@ -25,7 +26,6 @@ | |
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. | ||
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>. | ||
* | ||
*/ | ||
|
||
namespace Smalot\PdfParser; | ||
|
@@ -43,8 +43,6 @@ | |
|
||
/** | ||
* Class Element | ||
* | ||
* @package Smalot\PdfParser | ||
*/ | ||
class Element | ||
{ | ||
|
@@ -53,47 +51,35 @@ class Element | |
*/ | ||
protected $document = null; | ||
|
||
/** | ||
* @var mixed | ||
*/ | ||
protected $value = null; | ||
|
||
/** | ||
* @param mixed $value | ||
* @param Document $document | ||
*/ | ||
public function __construct($value, Document $document = null) | ||
{ | ||
$this->value = $value; | ||
$this->value = $value; | ||
$this->document = $document; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function init() | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @param mixed $value | ||
* | ||
* @return bool | ||
*/ | ||
public function equals($value) | ||
{ | ||
return ($value == $this->value); | ||
return $value == $this->value; | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
* | ||
* @return bool | ||
*/ | ||
public function contains($value) | ||
{ | ||
if (is_array($this->value)) { | ||
if (\is_array($this->value)) { | ||
/** @var Element $val */ | ||
foreach ($this->value as $val) { | ||
if ($val->equals($value)) { | ||
|
@@ -107,9 +93,6 @@ public function contains($value) | |
} | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getContent() | ||
{ | ||
return $this->value; | ||
|
@@ -120,7 +103,7 @@ public function getContent() | |
*/ | ||
public function __toString() | ||
{ | ||
return (string)($this->value); | ||
return (string) ($this->value); | ||
} | ||
|
||
/** | ||
|
@@ -129,14 +112,15 @@ public function __toString() | |
* @param int $position | ||
* | ||
* @return array | ||
* | ||
* @throws \Exception | ||
*/ | ||
public static function parse($content, Document $document = null, &$position = 0) | ||
{ | ||
$args = func_get_args(); | ||
$args = \func_get_args(); | ||
$only_values = isset($args[3]) ? $args[3] : false; | ||
$content = trim($content); | ||
$values = array(); | ||
$content = trim($content); | ||
$values = []; | ||
|
||
do { | ||
$old_position = $position; | ||
|
@@ -145,12 +129,12 @@ public static function parse($content, Document $document = null, &$position = 0 | |
if (!preg_match('/^\s*(?P<name>\/[A-Z0-9\._]+)(?P<value>.*)/si', substr($content, $position), $match)) { | ||
break; | ||
} else { | ||
$name = ltrim($match['name'], '/'); | ||
$value = $match['value']; | ||
$position = strpos($content, $value, $position + strlen($match['name'])); | ||
$name = ltrim($match['name'], '/'); | ||
$value = $match['value']; | ||
$position = strpos($content, $value, $position + \strlen($match['name'])); | ||
} | ||
} else { | ||
$name = count($values); | ||
$name = \count($values); | ||
$value = substr($content, $position); | ||
} | ||
|
||
|
@@ -178,7 +162,7 @@ public static function parse($content, Document $document = null, &$position = 0 | |
$position = $old_position; | ||
break; | ||
} | ||
} while ($position < strlen($content)); | ||
} while ($position < \strlen($content)); | ||
|
||
return $values; | ||
} | ||
|
Oops, something went wrong.