diff --git a/src/ZugferdDocumentPdfBuilderAbstract.php b/src/ZugferdDocumentPdfBuilderAbstract.php index 6f238fe1..f156f0b9 100644 --- a/src/ZugferdDocumentPdfBuilderAbstract.php +++ b/src/ZugferdDocumentPdfBuilderAbstract.php @@ -11,7 +11,6 @@ use DOMDocument; use DOMXpath; -use InvalidArgumentException; use Throwable; use horstoeko\mimedb\MimeDb; use horstoeko\stringmanagement\FileUtils; @@ -19,6 +18,7 @@ use horstoeko\zugferd\exception\ZugferdFileNotFoundException; use horstoeko\zugferd\exception\ZugferdFileNotReadableException; use horstoeko\zugferd\exception\ZugferdUnknownMimetype; +use horstoeko\zugferd\exception\ZugferdInvalidArgumentException; use horstoeko\zugferd\ZugferdPackageVersion; use horstoeko\zugferd\ZugferdPdfWriter; use horstoeko\zugferd\ZugferdSettings; @@ -240,7 +240,7 @@ public function setAttachmentRelationshipTypeToSource() * @param string $displayName * @param string $relationshipType * @return static - * @throws InvalidArgumentException + * @throws ZugferdInvalidArgumentException * @throws ZugferdFileNotFoundException * @throws ZugferdFileNotReadableException * @throws ZugferdUnknownMimetype @@ -250,7 +250,7 @@ public function attachAdditionalFileByRealFile(string $fullFilename, string $dis // Checks that the file really exists if (empty($fullFilename)) { - throw new InvalidArgumentException("You must specify a filename for the content to attach"); + throw new ZugferdInvalidArgumentException("You must specify a filename for the content to attach"); } if (!file_exists($fullFilename)) { @@ -285,7 +285,7 @@ public function attachAdditionalFileByRealFile(string $fullFilename, string $dis * @param string $displayName * @param string $relationshipType * @return static - * @throws InvalidArgumentException + * @throws ZugferdInvalidArgumentException * @throws ZugferdUnknownMimetype */ public function attachAdditionalFileByContent(string $content, string $filename, string $displayName = "", string $relationshipType = "") @@ -293,13 +293,13 @@ public function attachAdditionalFileByContent(string $content, string $filename, // Check content. The content must not be empty if (empty($content)) { - throw new InvalidArgumentException("You must specify a content to attach"); + throw new ZugferdInvalidArgumentException("You must specify a content to attach"); } // Check filename. The filename must not be empty if (empty($filename)) { - throw new InvalidArgumentException("You must specify a filename for the content to attach"); + throw new ZugferdInvalidArgumentException("You must specify a filename for the content to attach"); } // Mimetype for the file must exist diff --git a/src/exception/ZugferdExceptionCodes.php b/src/exception/ZugferdExceptionCodes.php index 9624cbf1..16df8b2b 100644 --- a/src/exception/ZugferdExceptionCodes.php +++ b/src/exception/ZugferdExceptionCodes.php @@ -32,4 +32,5 @@ class ZugferdExceptionCodes public const NOPDFATTACHMENTFOUND = -1110; public const FILENOTFOUND = -2000; public const FILENOTREADABLE = -2001; + public const INVALIDARGUMENT = -3000; } diff --git a/src/exception/ZugferdInvalidArgumentException.php b/src/exception/ZugferdInvalidArgumentException.php new file mode 100644 index 00000000..463c35d7 --- /dev/null +++ b/src/exception/ZugferdInvalidArgumentException.php @@ -0,0 +1,35 @@ + + * @license https://opensource.org/licenses/MIT MIT + * @link https://github.com/horstoeko/zugferd + */ +class ZugferdInvalidArgumentException extends ZugferdBaseException +{ + /** + * Constructor + * + * @param string $message + * @param Throwable|null $previous + */ + public function __construct(string $message, ?Throwable $previous = null) + { + parent::__construct($message, ZugferdExceptionCodes::INVALIDARGUMENT, $previous); + } +} diff --git a/tests/testcases/PdfBuilderEn16931Test.php b/tests/testcases/PdfBuilderEn16931Test.php index 35e2d853..d53bca4f 100644 --- a/tests/testcases/PdfBuilderEn16931Test.php +++ b/tests/testcases/PdfBuilderEn16931Test.php @@ -2,10 +2,10 @@ namespace horstoeko\zugferd\tests\testcases; -use InvalidArgumentException; use horstoeko\zugferd\codelists\ZugferdPaymentMeans; use horstoeko\zugferd\exception\ZugferdFileNotFoundException; use horstoeko\zugferd\exception\ZugferdUnknownMimetype; +use horstoeko\zugferd\exception\ZugferdInvalidArgumentException; use horstoeko\zugferd\tests\TestCase; use horstoeko\zugferd\tests\traits\HandlesXmlTests; use horstoeko\zugferd\ZugferdDocumentBuilder; @@ -251,7 +251,7 @@ public function testAttachAdditionalFileFileDoesNotExist(): void public function testAttachAdditionalFileFileIsEmpty(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(ZugferdInvalidArgumentException::class); $this->expectExceptionMessage("You must specify a filename for the content to attach"); $pdfBuilder = ZugferdDocumentPdfBuilder::fromPdfFile(self::$document, self::$sourcePdfFilename); @@ -404,7 +404,7 @@ public function testAdditionalFilesAreEmbedded(): void public function testAttachAdditionalFileByContentEmptyContent(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(ZugferdInvalidArgumentException::class); $this->expectExceptionMessage("You must specify a content to attach"); $pdfBuilder = ZugferdDocumentPdfBuilder::fromPdfFile(self::$document, self::$sourcePdfFilename); @@ -413,7 +413,7 @@ public function testAttachAdditionalFileByContentEmptyContent(): void public function testAttachAdditionalFileByContentEmptyFilename(): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(ZugferdInvalidArgumentException::class); $this->expectExceptionMessage("You must specify a filename for the content to attach"); $filename = dirname(__FILE__) . "/../assets/txt_addattachment_1.txt";