Skip to content

Commit

Permalink
Consolidated exceptions with horstoeko/orderx
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Oct 13, 2024
1 parent 9229906 commit ef86636
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 220 deletions.
23 changes: 23 additions & 0 deletions src/exception/ZugferdBaseException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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;

/**
* Class representing an exception for missing a file
*
* @category Zugferd
* @package Zugferd
* @author D. Erling <[email protected]>
* @license https://opensource.org/licenses/MIT MIT
* @link https://github.com/horstoeko/zugferd
*/
class ZugferdBaseException extends \Exception
{
}
32 changes: 32 additions & 0 deletions src/exception/ZugferdExceptionCodes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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;

/**
* Class representing the internal coes for Order-X-Exceptions
*
* @category Zugferd
* @package Zugferd
* @author D. Erling <[email protected]>
* @license https://opensource.org/licenses/MIT MIT
* @link https://github.com/horstoeko/zugferd
*/
class ZugferdExceptionCodes
{
public const CANNOTFINDPROFILESTRING = -1101;
public const UNKNOWNPROFILE = -1102;
public const MIMETYPENOTSUPPORTED = -1103;
public const UNKNOWNDATEFORMAT = -1104;
public const NOVALIDATTACHMENTFOUNDINPDF = -1105;
public const UNKNOWNPROFILEPARAMETER = -1106;
public const UNKNOWNSYNTAX = -1107;
public const FILENOTFOUND = -2000;
public const FILENOTREADABLE = -2001;
}
38 changes: 6 additions & 32 deletions src/exception/ZugferdFileNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace horstoeko\zugferd\exception;

use Exception;
use Throwable;

/**
* Class representing an exception for missing a file
Expand All @@ -20,42 +20,16 @@
* @license https://opensource.org/licenses/MIT MIT
* @link https://github.com/horstoeko/zugferd
*/
class ZugferdFileNotFoundException extends Exception
class ZugferdFileNotFoundException extends ZugferdBaseException
{
/**
* The context of the type element
*
* @var string
*/
private $filePath = "";

/**
* Constructor
*
* @param string $filePath
*/
public function __construct(string $filePath)
{
$this->filePath = $filePath;

parent::__construct($this->buildMessage());
}

/**
* @inheritDoc
*/
public function __toString()
{
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
}

/**
* Build the message
*
* @return string
* @param string $filename
* @param Throwable|null $previous
*/
private function buildMessage(): string
public function __construct(string $filename, ?Throwable $previous = null)
{
return sprintf("The filer %s is missing", $this->filePath);
parent::__construct(sprintf("The file %s was not found", $filename), ZugferdExceptionCodes::FILENOTFOUND, $previous);
}
}
38 changes: 6 additions & 32 deletions src/exception/ZugferdFileNotReadableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace horstoeko\zugferd\exception;

use Exception;
use Throwable;

/**
* Class representing an exception for non-readable a file
Expand All @@ -20,42 +20,16 @@
* @license https://opensource.org/licenses/MIT MIT
* @link https://github.com/horstoeko/zugferd
*/
class ZugferdFileNotReadableException extends Exception
class ZugferdFileNotReadableException extends ZugferdBaseException
{
/**
* The context of the type element
*
* @var string
*/
private $filePath = "";

/**
* Constructor
*
* @param string $filePath
*/
public function __construct(string $filePath)
{
$this->filePath = $filePath;

parent::__construct($this->buildMessage());
}

/**
* @inheritDoc
*/
public function __toString()
{
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
}

/**
* Build the message
*
* @return string
* @param string $filename
* @param Throwable|null $previous
*/
private function buildMessage(): string
public function __construct(string $filename, ?Throwable $previous = null)
{
return sprintf("The filer %s is not readable", $this->filePath);
parent::__construct(sprintf("The file %s is not readable", $filename), ZugferdExceptionCodes::FILENOTFOUND, $previous);
}
}
40 changes: 5 additions & 35 deletions src/exception/ZugferdUnknownDateFormatException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace horstoeko\zugferd\exception;

use Throwable;

/**
* Class representing an exception for unknown date formates
*
Expand All @@ -18,42 +20,10 @@
* @license https://opensource.org/licenses/MIT MIT
* @link https://github.com/horstoeko/zugferd
*/
class ZugferdUnknownDateFormatException extends \Exception
class ZugferdUnknownDateFormatException extends ZugferdBaseException
{
/**
* The context of the type element
*
* @var string
*/
private $dateFormat = "";

/**
* Constructor
*
* @param string $dateFormat
*/
public function __construct(string $dateFormat)
{
$this->dateFormat = $dateFormat;

parent::__construct($this->buildMessage());
}

/**
* @inheritDoc
*/
public function __toString()
{
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
}

/**
* Build the message
*
* @return string
*/
private function buildMessage(): string
public function __construct(string $dateFormatCode, ?Throwable $previous = null)
{
return sprintf("The date format identifier %s is unknown or not supported", $this->dateFormat);
parent::__construct(sprintf("Invalid date format %s", $dateFormatCode), ZugferdExceptionCodes::UNKNOWNDATEFORMAT, $previous);
}
}
38 changes: 6 additions & 32 deletions src/exception/ZugferdUnknownProfileException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace horstoeko\zugferd\exception;

use Exception;
use Throwable;

/**
* Class representing an exception for unknown profile
Expand All @@ -20,42 +20,16 @@
* @license https://opensource.org/licenses/MIT MIT
* @link https://github.com/horstoeko/zugferd
*/
class ZugferdUnknownProfileException extends Exception
class ZugferdUnknownProfileException extends ZugferdBaseException
{
/**
* The context of the type element
*
* @var string
*/
private $contextElement = "";

/**
* Constructor
*
* @param string $contextElement
*/
public function __construct(string $contextElement)
{
$this->contextElement = $contextElement;

parent::__construct($this->buildMessage());
}

/**
* @inheritDoc
*/
public function __toString()
{
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
}

/**
* Build the message
*
* @return string
* @param string $profileString
* @param Throwable|null $previous
*/
private function buildMessage(): string
public function __construct(string $profileString, ?Throwable $previous = null)
{
return sprintf("A context parameter was found, but the content of \"%s\" is not a valid profile", $this->contextElement);
parent::__construct(sprintf("Cannot determain the profile by %s", $profileString), ZugferdExceptionCodes::UNKNOWNPROFILE, $previous);
}
}
38 changes: 6 additions & 32 deletions src/exception/ZugferdUnknownProfileIdException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace horstoeko\zugferd\exception;

use Exception;
use Throwable;

/**
* Class representing an exception for unknown profile id
Expand All @@ -20,42 +20,16 @@
* @license https://opensource.org/licenses/MIT MIT
* @link https://github.com/horstoeko/zugferd
*/
class ZugferdUnknownProfileIdException extends Exception
class ZugferdUnknownProfileIdException extends ZugferdBaseException
{
/**
* The context of the type element
*
* @var integer
*/
private $profileId = 0;

/**
* Constructor
*
* @param integer $profileId
*/
public function __construct(int $profileId)
{
$this->profileId = $profileId;

parent::__construct($this->buildMessage());
}

/**
* @inheritDoc
*/
public function __toString()
{
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
}

/**
* Build the message
*
* @return string
* @param int $profileId
* @param Throwable|null $previous
*/
private function buildMessage(): string
public function __construct(int $profileId, ?Throwable $previous = null)
{
return sprintf("The profile id %s is uknown", $this->profileId);
parent::__construct(sprintf("The profile id %s is uknown", $profileId), ZugferdExceptionCodes::UNKNOWNPROFILE, $previous);
}
}
38 changes: 6 additions & 32 deletions src/exception/ZugferdUnknownProfileParameterException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace horstoeko\zugferd\exception;

use Exception;
use Throwable;

/**
* Class representing an exception for unknown profile parameter
Expand All @@ -20,42 +20,16 @@
* @license https://opensource.org/licenses/MIT MIT
* @link https://github.com/horstoeko/zugferd
*/
class ZugferdUnknownProfileParameterException extends Exception
class ZugferdUnknownProfileParameterException extends ZugferdBaseException
{
/**
* The context of the type element
*
* @var string
*/
private $profileParameter = "";

/**
* Constructor
*
* @param string $profileParameter
*/
public function __construct(string $profileParameter)
{
$this->profileParameter = $profileParameter;

parent::__construct($this->buildMessage());
}

/**
* @inheritDoc
*/
public function __toString()
{
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
}

/**
* Build the message
*
* @return string
* @param string $profileParameter
* @param Throwable|null $previous
*/
private function buildMessage(): string
public function __construct(string $profileParameter, ?Throwable $previous = null)
{
return sprintf("The profile parameter %s is uknown", $this->profileParameter);
parent::__construct(sprintf("The profile parameter %s is uknown", $profileParameter), ZugferdExceptionCodes::UNKNOWNPROFILEPARAMETER, $previous);
}
}
Loading

0 comments on commit ef86636

Please sign in to comment.