Skip to content

Commit

Permalink
Seperated exception Codes (const in OrderExceptionCodes class), Renam…
Browse files Browse the repository at this point in the history
…ed Exception class "OrderUnknownDateFormat" to "OrderUnknownDateFormatException"
  • Loading branch information
ruff committed Jan 12, 2023
1 parent 8c62bea commit fb78024
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/OrderObjectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use DateTime;
use horstoeko\orderx\exception\OrderMimeTypeNotSupportedException;
use horstoeko\orderx\exception\OrderUnknownDateFormat;
use horstoeko\orderx\exception\OrderUnknownDateFormatException;
use horstoeko\stringmanagement\FileUtils;
use horstoeko\stringmanagement\StringUtils;
use MimeTyper\Repository\MimeDbRepository;
Expand Down Expand Up @@ -1319,7 +1319,7 @@ public function toDateTime(?string $dateTimeString = null, ?string $format = nul
} elseif ($format == "204") {
return DateTime::createFromFormat("YmdHis", $dateTimeString);
} else {
throw new OrderUnknownDateFormat($format);
throw new OrderUnknownDateFormatException($format);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/exception/OrderCannotFindProfileString.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ class OrderCannotFindProfileString extends OrderBaseException
*/
public function __construct(?Throwable $previous = null)
{
parent::__construct("The string containing the profile was not found", -1101, $previous);
parent::__construct("The string containing the profile was not found", OrderExceptionCodes::CANNOTFINDPROFILESTRING, $previous);
}
}
20 changes: 20 additions & 0 deletions src/exception/OrderExceptionCodes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

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

namespace horstoeko\orderx\exception;

class OrderExceptionCodes
{
public const CANNOTFINDPROFILESTRING = -1101;
public const UNKNOWNPROFILE = -1102;
public const MIMETYPENOTSUPPORTED = -1103;
public const UNKNOWNDATEFORMAT = -1104;
public const NOVALIDATTACHMENTFOUNDINPDF = -1105;
public const FILENOTFOUND = -2000;
}
2 changes: 1 addition & 1 deletion src/exception/OrderFileNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ class OrderFileNotFoundException extends OrderBaseException
*/
public function __construct(string $filename, ?Throwable $previous = null)
{
parent::__construct(sprintf("The file %s was not found", $filename), -2000, $previous);
parent::__construct(sprintf("The file %s was not found", $filename), OrderExceptionCodes::FILENOTFOUND, $previous);
}
}
2 changes: 1 addition & 1 deletion src/exception/OrderMimeTypeNotSupportedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ class OrderMimeTypeNotSupportedException extends OrderBaseException
*/
public function __construct(string $mimetype, ?Throwable $previous = null)
{
parent::__construct(sprintf("The Mime Type %s is not supported", $mimetype), -1103, $previous);
parent::__construct(sprintf("The Mime Type %s is not supported", $mimetype), OrderExceptionCodes::MIMETYPENOTSUPPORTED, $previous);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ class OrderNoValidAttachmentFoundInPdfException extends OrderBaseException
*/
public function __construct(?Throwable $previous = null)
{
parent::__construct("No valid attachment file found in PDF", -1105, $previous);
parent::__construct("No valid attachment file found in PDF", OrderExceptionCodes::NOVALIDATTACHMENTFOUNDINPDF, $previous);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @license https://opensource.org/licenses/MIT MIT
* @link https://github.com/horstoeko/orderx
*/
class OrderUnknownDateFormat extends OrderBaseException
class OrderUnknownDateFormatException extends OrderBaseException
{
/**
* Constructor
Expand All @@ -30,6 +30,6 @@ class OrderUnknownDateFormat extends OrderBaseException
*/
public function __construct(string $dateFormatCode, ?Throwable $previous = null)
{
parent::__construct(sprintf("Invalid date format %s", $dateFormatCode), -1104, $previous);
parent::__construct(sprintf("Invalid date format %s", $dateFormatCode), OrderExceptionCodes::UNKNOWNDATEFORMAT, $previous);
}
}
2 changes: 1 addition & 1 deletion src/exception/OrderUnknownProfileException.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ class OrderUnknownProfileException extends OrderBaseException
*/
public function __construct(string $profileString, ?Throwable $previous = null)
{
parent::__construct(sprintf("Cannot determain the profile by %s", $profileString), -1102, $previous);
parent::__construct(sprintf("Cannot determain the profile by %s", $profileString), OrderExceptionCodes::UNKNOWNPROFILE, $previous);
}
}
4 changes: 2 additions & 2 deletions tests/testcases/OrderObjectHelperBasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace horstoeko\orderx\tests\testcases;

use horstoeko\orderx\exception\OrderUnknownDateFormat;
use horstoeko\orderx\exception\OrderUnknownDateFormatException;
use horstoeko\orderx\OrderObjectHelper;
use horstoeko\orderx\OrderProfiles;
use horstoeko\orderx\tests\TestCase;
Expand Down Expand Up @@ -1120,7 +1120,7 @@ public function testToDateTime(): void
$this->assertEquals("31.12.2022 14:30:00", self::$objectHelper->toDateTime("202212311430", "203")->format("d.m.Y H:i:s"));
$this->assertEquals("31.12.2022 14:30:44", self::$objectHelper->toDateTime("20221231143044", "204")->format("d.m.Y H:i:s"));

$this->expectException(OrderUnknownDateFormat::class);
$this->expectException(OrderUnknownDateFormatException::class);
self::$objectHelper->toDateTime("20221231", "999");
}

Expand Down
4 changes: 2 additions & 2 deletions tests/testcases/OrderObjectHelperComfortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace horstoeko\orderx\tests\testcases;

use horstoeko\orderx\exception\OrderMimeTypeNotSupportedException;
use horstoeko\orderx\exception\OrderUnknownDateFormat;
use horstoeko\orderx\exception\OrderUnknownDateFormatException;
use horstoeko\orderx\OrderObjectHelper;
use horstoeko\orderx\OrderProfiles;
use horstoeko\orderx\tests\TestCase;
Expand Down Expand Up @@ -1202,7 +1202,7 @@ public function testToDateTime(): void
$this->assertEquals("31.12.2022 14:30:00", self::$objectHelper->toDateTime("202212311430", "203")->format("d.m.Y H:i:s"));
$this->assertEquals("31.12.2022 14:30:44", self::$objectHelper->toDateTime("20221231143044", "204")->format("d.m.Y H:i:s"));

$this->expectException(OrderUnknownDateFormat::class);
$this->expectException(OrderUnknownDateFormatException::class);
self::$objectHelper->toDateTime("20221231", "999");
}

Expand Down
4 changes: 2 additions & 2 deletions tests/testcases/OrderObjectHelperExtendedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace horstoeko\orderx\tests\testcases;

use horstoeko\orderx\exception\OrderMimeTypeNotSupportedException;
use horstoeko\orderx\exception\OrderUnknownDateFormat;
use horstoeko\orderx\exception\OrderUnknownDateFormatException;
use horstoeko\orderx\OrderObjectHelper;
use horstoeko\orderx\OrderProfiles;
use horstoeko\orderx\tests\TestCase;
Expand Down Expand Up @@ -1226,7 +1226,7 @@ public function testToDateTime(): void
$this->assertEquals("31.12.2022 14:30:00", self::$objectHelper->toDateTime("202212311430", "203")->format("d.m.Y H:i:s"));
$this->assertEquals("31.12.2022 14:30:44", self::$objectHelper->toDateTime("20221231143044", "204")->format("d.m.Y H:i:s"));

$this->expectException(OrderUnknownDateFormat::class);
$this->expectException(OrderUnknownDateFormatException::class);
self::$objectHelper->toDateTime("20221231", "999");
}

Expand Down

0 comments on commit fb78024

Please sign in to comment.