Skip to content

Commit

Permalink
Refined new exceptions; added NotImplementedException
Browse files Browse the repository at this point in the history
also fixed some coding style issues
  • Loading branch information
k00ni committed Oct 31, 2024
1 parent ec362fa commit d9772be
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/Smalot/PdfParser/Exception/EmptyPdfException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?php declare(strict_types = 1);
<?php

declare(strict_types=1);

namespace Smalot\PdfParser\Exception;

/**
* This Exception is thrown when no PDF data was given.
*/
class EmptyPdfException extends \Exception
{
}
7 changes: 6 additions & 1 deletion src/Smalot/PdfParser/Exception/MissingPdfHeaderException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?php declare(strict_types = 1);
<?php

declare(strict_types=1);

namespace Smalot\PdfParser\Exception;

/**
* This Exception is thrown when the %PDF- header is missing.
*/
class MissingPdfHeaderException extends \Exception
{
}
12 changes: 12 additions & 0 deletions src/Smalot/PdfParser/Exception/NotImplementedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Smalot\PdfParser\Exception;

/**
* This Exception is thrown when a functionality has not yet been implemented.
*/
class NotImplementedException extends \Exception
{
}
15 changes: 9 additions & 6 deletions src/Smalot/PdfParser/RawData/FilterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

namespace Smalot\PdfParser\RawData;

use Smalot\PdfParser\Exception\NotImplementedException;

class FilterHelper
{
protected $availableFilters = ['ASCIIHexDecode', 'ASCII85Decode', 'LZWDecode', 'FlateDecode', 'RunLengthDecode'];
Expand All @@ -54,7 +56,8 @@ class FilterHelper
*
* @return string Decoded data string
*
* @throws \Exception if a certain decode function is not implemented yet
* @throws \Exception
* @throws \Smalot\PdfParser\Exception\NotImplementedException if a certain decode function is not implemented yet
*/
public function decodeFilter(string $filter, string $data, int $decodeMemoryLimit = 0): string
{
Expand All @@ -75,15 +78,15 @@ public function decodeFilter(string $filter, string $data, int $decodeMemoryLimi
return $this->decodeFilterRunLengthDecode($data);

case 'CCITTFaxDecode':
throw new \Exception('Decode CCITTFaxDecode not implemented yet.');
throw new NotImplementedException('Decode CCITTFaxDecode not implemented yet.');
case 'JBIG2Decode':
throw new \Exception('Decode JBIG2Decode not implemented yet.');
throw new NotImplementedException('Decode JBIG2Decode not implemented yet.');
case 'DCTDecode':
throw new \Exception('Decode DCTDecode not implemented yet.');
throw new NotImplementedException('Decode DCTDecode not implemented yet.');
case 'JPXDecode':
throw new \Exception('Decode JPXDecode not implemented yet.');
throw new NotImplementedException('Decode JPXDecode not implemented yet.');
case 'Crypt':
throw new \Exception('Decode Crypt not implemented yet.');
throw new NotImplementedException('Decode Crypt not implemented yet.');
default:
return $data;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Smalot/PdfParser/RawData/RawDataParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
namespace Smalot\PdfParser\RawData;

use Smalot\PdfParser\Config;
use Smalot\PdfParser\Exception\MissingPdfHeaderException;
use Smalot\PdfParser\Exception\EmptyPdfException;
use Smalot\PdfParser\Exception\MissingPdfHeaderException;

class RawDataParser
{
Expand Down

0 comments on commit d9772be

Please sign in to comment.