Skip to content

Commit f83ed70

Browse files
committed
refactor: add parent exception to avoid repeated code
1 parent b98655d commit f83ed70

File tree

4 files changed

+30
-24
lines changed

4 files changed

+30
-24
lines changed

src/Exception/AccessDeniedException.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@
1414

1515
namespace MultiTheftAuto\Sdk\Exception;
1616

17-
use Exception;
18-
19-
class AccessDeniedException extends Exception
17+
class AccessDeniedException extends MessageException
2018
{
2119
protected const EXCEPTION_MESSAGE = 'Access Denied. This server requires authentication. Please ensure that a valid username and password combination is provided.';
22-
23-
public function __construct()
24-
{
25-
parent::__construct(self::EXCEPTION_MESSAGE);
26-
}
2720
}

src/Exception/FunctionNotFoundException.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@
1414

1515
namespace MultiTheftAuto\Sdk\Exception;
1616

17-
use Exception;
18-
19-
class FunctionNotFoundException extends Exception
17+
class FunctionNotFoundException extends MessageException
2018
{
2119
protected const EXCEPTION_MESSAGE = 'Attempted function call was not found';
22-
23-
public function __construct()
24-
{
25-
parent::__construct(self::EXCEPTION_MESSAGE);
26-
}
2720
}

src/Exception/MessageException.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*****************************************************************************
4+
*
5+
* PROJECT: MTA PHP SDK
6+
* LICENSE: See LICENSE in the top level directory
7+
* FILE: MessageException.php
8+
*
9+
* Multi Theft Auto is available from http://www.multitheftauto.com/
10+
*
11+
*****************************************************************************/
12+
13+
declare(strict_types=1);
14+
15+
namespace MultiTheftAuto\Sdk\Exception;
16+
17+
use Exception;
18+
19+
abstract class MessageException extends Exception
20+
{
21+
protected const EXCEPTION_MESSAGE = '';
22+
23+
public function __construct()
24+
{
25+
parent::__construct(static::EXCEPTION_MESSAGE);
26+
}
27+
}

src/Exception/NotFoundStatusException.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@
1414

1515
namespace MultiTheftAuto\Sdk\Exception;
1616

17-
use Exception;
18-
19-
class NotFoundStatusException extends Exception
17+
class NotFoundStatusException extends MessageException
2018
{
2119
protected const EXCEPTION_MESSAGE = 'There was a problem with the request. Ensure that the resource exists and that the name is spelled correctly.';
22-
23-
public function __construct()
24-
{
25-
parent::__construct(self::EXCEPTION_MESSAGE);
26-
}
2720
}

0 commit comments

Comments
 (0)