Skip to content

Commit

Permalink
[ENH] Changed InvalidArgumentException to ZugferdInvalidArgumentExcep…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
HorstOeko committed Dec 8, 2024
1 parent e5e0498 commit d799b4c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/ZugferdDocumentPdfBuilderAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

use DOMDocument;
use DOMXpath;
use InvalidArgumentException;
use Throwable;
use horstoeko\mimedb\MimeDb;
use horstoeko\stringmanagement\FileUtils;
use horstoeko\zugferd\codelists\ZugferdInvoiceType;
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;
Expand Down Expand Up @@ -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
Expand All @@ -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)) {
Expand Down Expand Up @@ -285,21 +285,21 @@ 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 = "")
{
// 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
Expand Down
1 change: 1 addition & 0 deletions src/exception/ZugferdExceptionCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ class ZugferdExceptionCodes
public const NOPDFATTACHMENTFOUND = -1110;
public const FILENOTFOUND = -2000;
public const FILENOTREADABLE = -2001;
public const INVALIDARGUMENT = -3000;
}
35 changes: 35 additions & 0 deletions src/exception/ZugferdInvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* This file is a part of horstoeko/zugferd.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace horstoeko\zugferd\exception;

use Throwable;

/**
* Class representing an exception if an argument is invalid or an argument is not of the expected type
*
* @category Zugferd
* @package Zugferd
* @author D. Erling <horstoeko@erling.com.de>
* @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);
}
}
8 changes: 4 additions & 4 deletions tests/testcases/PdfBuilderEn16931Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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";
Expand Down

0 comments on commit d799b4c

Please sign in to comment.