From 41cbdadb72b7321dbd6dc2484ad16c9915708006 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Mon, 11 Sep 2017 21:17:34 -0400 Subject: [PATCH] More PHP 5.4/5.3 fixes --- .../Categories/CategoryHandler.php | 8 ++--- .../Emails/EmailTemplateParser.php | 32 ++++++++++++++----- api/BusinessLogic/Tickets/TicketCreator.php | 2 +- api/BusinessLogic/ValidationModel.php | 2 +- .../PublicAttachmentController.php | 2 +- .../StaffTicketAttachmentsController.php | 6 ++-- .../Categories/CategoryController.php | 10 +++--- .../Navigation/CustomNavElementController.php | 12 +++---- .../Settings/SettingsController.php | 2 +- api/Controllers/Statuses/StatusController.php | 2 +- .../Tickets/CustomerTicketController.php | 4 +-- .../ResendTicketEmailToCustomerController.php | 6 ++-- .../Tickets/StaffTicketController.php | 6 ++-- api/DataAccess/Files/FileReader.php | 2 +- api/DataAccess/Files/FileWriter.php | 2 +- api/Link.php | 4 +-- .../Attachments/AttachmentHandlerTest.php | 30 ++++++++--------- .../Attachments/AttachmentRetrieverTest.php | 8 ++--- .../Categories/CategoryHandlerTest.php | 8 ++--- .../Emails/EmailSenderHelperTest.php | 6 ++-- .../Security/BanRetrieverTest.php | 2 +- .../Security/UserToTicketCheckerTest.php | 2 +- .../Tickets/AutoassignerTest.php | 4 +-- .../Tickets/NewTicketValidatorTest.php | 6 ++-- .../CreateTicketForCustomerTest.php | 18 +++++------ .../Tickets/TicketDeleterTest.php | 8 ++--- .../Tickets/TicketRetrieverTest.php | 6 ++-- .../Tickets/TicketValidatorsTest.php | 2 +- .../Tickets/TrackingIdGeneratorTest.php | 2 +- .../Tickets/VerifiedEmailCheckerTest.php | 2 +- api/index.php | 10 +++--- ci/php_lint.sh | 2 +- .../admin/api-authentication/index.php | 2 +- 33 files changed, 118 insertions(+), 102 deletions(-) diff --git a/api/BusinessLogic/Categories/CategoryHandler.php b/api/BusinessLogic/Categories/CategoryHandler.php index 3b542127..98e5b6d4 100644 --- a/api/BusinessLogic/Categories/CategoryHandler.php +++ b/api/BusinessLogic/Categories/CategoryHandler.php @@ -64,7 +64,7 @@ class CategoryHandler extends \BaseClass { } } - throw new \Exception("Newly created category {$id} lost! :O"); + throw new \BaseException("Newly created category {$id} lost! :O"); } /** @@ -145,7 +145,7 @@ class CategoryHandler extends \BaseClass { } } - throw new \Exception("Category {$category->id} vanished! :O"); + throw new \BaseException("Category {$category->id} vanished! :O"); } function deleteCategory($id, $userContext, $heskSettings) { @@ -154,7 +154,7 @@ class CategoryHandler extends \BaseClass { } if ($id === 1) { - throw new \Exception("Category 1 cannot be deleted!"); + throw new \BaseException("Category 1 cannot be deleted!"); } $this->ticketGateway->moveTicketsToDefaultCategory($id, $heskSettings); @@ -175,7 +175,7 @@ class CategoryHandler extends \BaseClass { } if ($category === null) { - throw new \Exception("Could not find category with ID {$id}!"); + throw new \BaseException("Could not find category with ID {$id}!"); } if ($direction === Direction::UP) { diff --git a/api/BusinessLogic/Emails/EmailTemplateParser.php b/api/BusinessLogic/Emails/EmailTemplateParser.php index 2518c1b6..13fd3091 100644 --- a/api/BusinessLogic/Emails/EmailTemplateParser.php +++ b/api/BusinessLogic/Emails/EmailTemplateParser.php @@ -3,7 +3,6 @@ namespace BusinessLogic\Emails; -use BusinessLogic\Exceptions\ApiFriendlyException; use BusinessLogic\Exceptions\EmailTemplateNotFoundException; use BusinessLogic\Exceptions\InvalidEmailTemplateException; use BusinessLogic\Statuses\DefaultStatusForAction; @@ -77,10 +76,10 @@ class EmailTemplateParser extends \BaseClass { } if ($fullLanguageName === null) { - throw new \Exception("Language code {$languageCode} did not return any valid HESK languages!"); + throw new \BaseException("Language code {$languageCode} did not return any valid HESK languages!"); } - $subject = $this->parseSubject($subject, $ticket, $fullLanguageName, $heskSettings); + $subject = $this->parseSubject($subject, $ticket, $fullLanguageName, $heskSettings, $modsForHeskSettings); $message = $this->parseMessage($template, $ticket, $fullLanguageName, $emailTemplate->forStaff, $heskSettings, $modsForHeskSettings, false); $htmlMessage = $this->parseMessage($htmlTemplate, $ticket, $fullLanguageName, $emailTemplate->forStaff, $heskSettings, $modsForHeskSettings, true); @@ -117,11 +116,11 @@ class EmailTemplateParser extends \BaseClass { * @return string * @throws \Exception if common.inc.php isn't loaded */ - private function parseSubject($subjectTemplate, $ticket, $language, $heskSettings) { + private function parseSubject($subjectTemplate, $ticket, $language, $heskSettings, $modsForHeskSettings) { global $hesklang; if (!function_exists('hesk_msgToPlain')) { - throw new \Exception("common.inc.php not loaded!"); + throw new \BaseException("common.inc.php not loaded!"); } if ($ticket === null) { @@ -131,7 +130,14 @@ class EmailTemplateParser extends \BaseClass { // Status name and category name $defaultStatus = $this->statusGateway->getStatusForDefaultAction(DefaultStatusForAction::NEW_TICKET, $heskSettings); $statusName = $defaultStatus->localizedNames[$language]; - $category = $this->categoryGateway->getAllCategories($heskSettings)[$ticket->categoryId]; + $categories = $this->categoryGateway->getAllCategories($heskSettings, $modsForHeskSettings); + $category = null; + foreach ($categories as $innerCategory) { + if ($innerCategory->id === $ticket->categoryId) { + $category = $innerCategory; + break; + } + } switch ($ticket->priorityId) { case Priority::CRITICAL: @@ -173,7 +179,7 @@ class EmailTemplateParser extends \BaseClass { global $hesklang; if (!function_exists('hesk_msgToPlain')) { - throw new \Exception("common.inc.php not loaded!"); + throw new \BaseException("common.inc.php not loaded!"); } if ($ticket === null) { @@ -193,7 +199,17 @@ class EmailTemplateParser extends \BaseClass { // Status name and category name $defaultStatus = $this->statusGateway->getStatusForDefaultAction(DefaultStatusForAction::NEW_TICKET, $heskSettings); $statusName = hesk_msgToPlain($defaultStatus->localizedNames[$language]); - $category = hesk_msgToPlain($this->categoryGateway->getAllCategories($heskSettings)[$ticket->categoryId]->name); + + $categories = $this->categoryGateway->getAllCategories($heskSettings, $modsForHeskSettings); + $category = null; + foreach ($categories as $innerCategory) { + if ($innerCategory->id === $ticket->categoryId) { + $category = $innerCategory; + break; + } + } + + $category = hesk_msgToPlain($category->name); $owner = $this->userGateway->getUserById($ticket->ownerId, $heskSettings); $ownerName = $owner === null ? $hesklang['unas'] : hesk_msgToPlain($owner->name); diff --git a/api/BusinessLogic/Tickets/TicketCreator.php b/api/BusinessLogic/Tickets/TicketCreator.php index 7f677c50..5956de9b 100644 --- a/api/BusinessLogic/Tickets/TicketCreator.php +++ b/api/BusinessLogic/Tickets/TicketCreator.php @@ -130,7 +130,7 @@ class TicketCreator extends \BaseClass { $status = $this->statusGateway->getStatusForDefaultAction(DefaultStatusForAction::NEW_TICKET, $heskSettings); if ($status === null) { - throw new \Exception("Could not find the default status for a new ticket!"); + throw new \BaseException("Could not find the default status for a new ticket!"); } $ticket->statusId = $status->id; diff --git a/api/BusinessLogic/ValidationModel.php b/api/BusinessLogic/ValidationModel.php index 0ca28eaf..3878a0be 100644 --- a/api/BusinessLogic/ValidationModel.php +++ b/api/BusinessLogic/ValidationModel.php @@ -9,6 +9,6 @@ class ValidationModel extends \BaseClass { public $errorKeys; function __construct() { - $this->errorKeys = []; + $this->errorKeys = array(); } } \ No newline at end of file diff --git a/api/Controllers/Attachments/PublicAttachmentController.php b/api/Controllers/Attachments/PublicAttachmentController.php index da489d42..8b1dc555 100644 --- a/api/Controllers/Attachments/PublicAttachmentController.php +++ b/api/Controllers/Attachments/PublicAttachmentController.php @@ -14,7 +14,7 @@ class PublicAttachmentController extends \BaseClass { self::verifyAttachmentsAreEnabled($hesk_settings); /* @var $attachmentRetriever AttachmentRetriever */ - $attachmentRetriever = $applicationContext->get(AttachmentRetriever::class); + $attachmentRetriever = $applicationContext->get(AttachmentRetriever::clazz()); $attachment = $attachmentRetriever->getAttachmentContentsForTrackingId($trackingId, $attachmentId, $userContext, $hesk_settings); diff --git a/api/Controllers/Attachments/StaffTicketAttachmentsController.php b/api/Controllers/Attachments/StaffTicketAttachmentsController.php index c97b0d1f..d7bb3cba 100644 --- a/api/Controllers/Attachments/StaffTicketAttachmentsController.php +++ b/api/Controllers/Attachments/StaffTicketAttachmentsController.php @@ -18,7 +18,7 @@ class StaffTicketAttachmentsController extends \BaseClass { $this->verifyAttachmentsAreEnabled($hesk_settings); /* @var $attachmentRetriever AttachmentRetriever */ - $attachmentRetriever = $applicationContext->get(AttachmentRetriever::class); + $attachmentRetriever = $applicationContext->get(AttachmentRetriever::clazz()); $contents = $attachmentRetriever->getAttachmentContentsForTicket($ticketId, $attachmentId, $userContext, $hesk_settings); @@ -37,7 +37,7 @@ class StaffTicketAttachmentsController extends \BaseClass { $this->verifyAttachmentsAreEnabled($hesk_settings); /* @var $attachmentHandler AttachmentHandler */ - $attachmentHandler = $applicationContext->get(AttachmentHandler::class); + $attachmentHandler = $applicationContext->get(AttachmentHandler::clazz()); $createAttachmentForTicketModel = $this->createModel(JsonRetriever::getJsonData(), $ticketId); @@ -61,7 +61,7 @@ class StaffTicketAttachmentsController extends \BaseClass { global $applicationContext, $hesk_settings, $userContext; /* @var $attachmentHandler AttachmentHandler */ - $attachmentHandler = $applicationContext->get(AttachmentHandler::class); + $attachmentHandler = $applicationContext->get(AttachmentHandler::clazz()); $attachmentHandler->deleteAttachmentFromTicket($ticketId, $attachmentId, $userContext, $hesk_settings); diff --git a/api/Controllers/Categories/CategoryController.php b/api/Controllers/Categories/CategoryController.php index a9943bcd..c89d1a1a 100644 --- a/api/Controllers/Categories/CategoryController.php +++ b/api/Controllers/Categories/CategoryController.php @@ -30,7 +30,7 @@ class CategoryController extends \BaseClass { global $hesk_settings, $applicationContext, $userContext; /* @var $categoryRetriever CategoryRetriever */ - $categoryRetriever = $applicationContext->get(CategoryRetriever::class); + $categoryRetriever = $applicationContext->get(CategoryRetriever::clazz()); return $categoryRetriever->getAllCategories($hesk_settings, $userContext); } @@ -43,7 +43,7 @@ class CategoryController extends \BaseClass { $category = $this->buildCategoryFromJson($data); /* @var $categoryHandler CategoryHandler */ - $categoryHandler = $applicationContext->get(CategoryHandler::class); + $categoryHandler = $applicationContext->get(CategoryHandler::clazz()); $category = $categoryHandler->createCategory($category, $userContext, $hesk_settings); @@ -80,7 +80,7 @@ class CategoryController extends \BaseClass { $category->id = intval($id); /* @var $categoryHandler CategoryHandler */ - $categoryHandler = $applicationContext->get(CategoryHandler::class); + $categoryHandler = $applicationContext->get(CategoryHandler::clazz()); $category = $categoryHandler->editCategory($category, $userContext, $hesk_settings); @@ -91,7 +91,7 @@ class CategoryController extends \BaseClass { global $hesk_settings, $userContext, $applicationContext; /* @var $categoryHandler CategoryHandler */ - $categoryHandler = $applicationContext->get(CategoryHandler::class); + $categoryHandler = $applicationContext->get(CategoryHandler::clazz()); $categoryHandler->deleteCategory($id, $userContext, $hesk_settings); @@ -102,7 +102,7 @@ class CategoryController extends \BaseClass { global $applicationContext, $hesk_settings; /* @var $handler CategoryHandler */ - $handler = $applicationContext->get(CategoryHandler::class); + $handler = $applicationContext->get(CategoryHandler::clazz()); $handler->sortCategory(intval($id), $direction, $hesk_settings); } diff --git a/api/Controllers/Navigation/CustomNavElementController.php b/api/Controllers/Navigation/CustomNavElementController.php index 8196eb16..9ae6d741 100644 --- a/api/Controllers/Navigation/CustomNavElementController.php +++ b/api/Controllers/Navigation/CustomNavElementController.php @@ -16,7 +16,7 @@ class CustomNavElementController extends InternalApiController { self::staticCheckForInternalUseOnly(); /* @var $handler CustomNavElementHandler */ - $handler = $applicationContext->get(CustomNavElementHandler::class); + $handler = $applicationContext->get(CustomNavElementHandler::clazz()); output($handler->getAllCustomNavElements($hesk_settings)); } @@ -27,7 +27,7 @@ class CustomNavElementController extends InternalApiController { self::staticCheckForInternalUseOnly(); /* @var $handler CustomNavElementHandler */ - $handler = $applicationContext->get(CustomNavElementHandler::class); + $handler = $applicationContext->get(CustomNavElementHandler::clazz()); $handler->sortCustomNavElement(intval($id), $direction, $hesk_settings); } @@ -38,7 +38,7 @@ class CustomNavElementController extends InternalApiController { $this->checkForInternalUseOnly(); /* @var $handler CustomNavElementHandler */ - $handler = $applicationContext->get(CustomNavElementHandler::class); + $handler = $applicationContext->get(CustomNavElementHandler::clazz()); output($handler->getCustomNavElement($id, $hesk_settings)); } @@ -49,7 +49,7 @@ class CustomNavElementController extends InternalApiController { $this->checkForInternalUseOnly(); /* @var $handler CustomNavElementHandler */ - $handler = $applicationContext->get(CustomNavElementHandler::class); + $handler = $applicationContext->get(CustomNavElementHandler::clazz()); $data = JsonRetriever::getJsonData(); $element = $handler->createCustomNavElement($this->buildElementModel($data), $hesk_settings); @@ -63,7 +63,7 @@ class CustomNavElementController extends InternalApiController { $this->checkForInternalUseOnly(); /* @var $handler CustomNavElementHandler */ - $handler = $applicationContext->get(CustomNavElementHandler::class); + $handler = $applicationContext->get(CustomNavElementHandler::clazz()); $data = JsonRetriever::getJsonData(); $handler->saveCustomNavElement($this->buildElementModel($data, $id), $hesk_settings); @@ -77,7 +77,7 @@ class CustomNavElementController extends InternalApiController { $this->checkForInternalUseOnly(); /* @var $handler CustomNavElementHandler */ - $handler = $applicationContext->get(CustomNavElementHandler::class); + $handler = $applicationContext->get(CustomNavElementHandler::clazz()); $handler->deleteCustomNavElement($id, $hesk_settings); diff --git a/api/Controllers/Settings/SettingsController.php b/api/Controllers/Settings/SettingsController.php index 6737052f..d96adeaf 100644 --- a/api/Controllers/Settings/SettingsController.php +++ b/api/Controllers/Settings/SettingsController.php @@ -10,7 +10,7 @@ class SettingsController extends \BaseClass { global $applicationContext, $hesk_settings; /* @var $settingsRetriever SettingsRetriever */ - $settingsRetriever = $applicationContext->get(SettingsRetriever::class); + $settingsRetriever = $applicationContext->get(SettingsRetriever::clazz()); output($settingsRetriever->getAllSettings($hesk_settings)); } diff --git a/api/Controllers/Statuses/StatusController.php b/api/Controllers/Statuses/StatusController.php index 16473ae3..648768b4 100644 --- a/api/Controllers/Statuses/StatusController.php +++ b/api/Controllers/Statuses/StatusController.php @@ -10,7 +10,7 @@ class StatusController extends \BaseClass { global $applicationContext, $hesk_settings; /* @var $statusRetriever StatusRetriever */ - $statusRetriever = $applicationContext->get(StatusRetriever::class); + $statusRetriever = $applicationContext->get(StatusRetriever::clazz()); output($statusRetriever->getAllStatuses($hesk_settings)); } diff --git a/api/Controllers/Tickets/CustomerTicketController.php b/api/Controllers/Tickets/CustomerTicketController.php index 8b8b65fc..1daeff9f 100644 --- a/api/Controllers/Tickets/CustomerTicketController.php +++ b/api/Controllers/Tickets/CustomerTicketController.php @@ -18,7 +18,7 @@ class CustomerTicketController extends \BaseClass { $emailAddress = isset($_GET['email']) ? $_GET['email'] : null; /* @var $ticketRetriever TicketRetriever */ - $ticketRetriever = $applicationContext->get(TicketRetriever::class); + $ticketRetriever = $applicationContext->get(TicketRetriever::clazz()); output($ticketRetriever->getTicketByTrackingIdAndEmail($trackingId, $emailAddress, $hesk_settings)); } @@ -27,7 +27,7 @@ class CustomerTicketController extends \BaseClass { global $applicationContext, $hesk_settings, $userContext; /* @var $ticketCreator TicketCreator */ - $ticketCreator = $applicationContext->get(TicketCreator::class); + $ticketCreator = $applicationContext->get(TicketCreator::clazz()); $jsonRequest = JsonRetriever::getJsonData(); diff --git a/api/Controllers/Tickets/ResendTicketEmailToCustomerController.php b/api/Controllers/Tickets/ResendTicketEmailToCustomerController.php index fe2aa7be..ddab20cc 100644 --- a/api/Controllers/Tickets/ResendTicketEmailToCustomerController.php +++ b/api/Controllers/Tickets/ResendTicketEmailToCustomerController.php @@ -19,15 +19,15 @@ class ResendTicketEmailToCustomerController extends InternalApiController { $this->checkForInternalUseOnly(); /* @var $ticketRetriever TicketRetriever */ - $ticketRetriever = $applicationContext->get(TicketRetriever::class); + $ticketRetriever = $applicationContext->get(TicketRetriever::clazz()); $ticket = $ticketRetriever->getTicketById($ticketId, $hesk_settings, $userContext); /* @var $modsForHeskSettingsGateway ModsForHeskSettingsGateway */ - $modsForHeskSettingsGateway = $applicationContext->get(ModsForHeskSettingsGateway::class); + $modsForHeskSettingsGateway = $applicationContext->get(ModsForHeskSettingsGateway::clazz()); $modsForHeskSettings = $modsForHeskSettingsGateway->getAllSettings($hesk_settings); /* @var $emailSender EmailSenderHelper */ - $emailSender = $applicationContext->get(EmailSenderHelper::class); + $emailSender = $applicationContext->get(EmailSenderHelper::clazz()); $language = $ticket->language; diff --git a/api/Controllers/Tickets/StaffTicketController.php b/api/Controllers/Tickets/StaffTicketController.php index 658d7e7f..023f5352 100644 --- a/api/Controllers/Tickets/StaffTicketController.php +++ b/api/Controllers/Tickets/StaffTicketController.php @@ -15,7 +15,7 @@ class StaffTicketController extends \BaseClass { global $applicationContext, $userContext, $hesk_settings; /* @var $ticketRetriever TicketRetriever */ - $ticketRetriever = $applicationContext->get(TicketRetriever::class); + $ticketRetriever = $applicationContext->get(TicketRetriever::clazz()); output($ticketRetriever->getTicketById($id, $hesk_settings, $userContext)); } @@ -24,7 +24,7 @@ class StaffTicketController extends \BaseClass { global $applicationContext, $userContext, $hesk_settings; /* @var $ticketDeleter TicketDeleter */ - $ticketDeleter = $applicationContext->get(TicketDeleter::class); + $ticketDeleter = $applicationContext->get(TicketDeleter::clazz()); $ticketDeleter->deleteTicket($id, $userContext, $hesk_settings); @@ -35,7 +35,7 @@ class StaffTicketController extends \BaseClass { global $applicationContext, $userContext, $hesk_settings; /* @var $ticketEditor TicketEditor */ - $ticketEditor = $applicationContext->get(TicketEditor::class); + $ticketEditor = $applicationContext->get(TicketEditor::clazz()); $jsonRequest = JsonRetriever::getJsonData(); diff --git a/api/DataAccess/Files/FileReader.php b/api/DataAccess/Files/FileReader.php index dd2a8ce7..39a327a7 100644 --- a/api/DataAccess/Files/FileReader.php +++ b/api/DataAccess/Files/FileReader.php @@ -23,7 +23,7 @@ class FileReader extends \BaseClass { $fileContents = file_get_contents($location); if ($fileContents === false) { - throw new \Exception("Failed to read the file!"); + throw new \BaseException("Failed to read the file!"); } return $fileContents; diff --git a/api/DataAccess/Files/FileWriter.php b/api/DataAccess/Files/FileWriter.php index 368a4f3b..d35b302a 100644 --- a/api/DataAccess/Files/FileWriter.php +++ b/api/DataAccess/Files/FileWriter.php @@ -17,7 +17,7 @@ class FileWriter extends \BaseClass { $fileSize = file_put_contents($location, $contents); if ($fileSize === false) { - throw new \Exception("Failed to save the file!"); + throw new \BaseException("Failed to save the file!"); } return $fileSize; diff --git a/api/Link.php b/api/Link.php index 10e5758d..dff9c7cf 100644 --- a/api/Link.php +++ b/api/Link.php @@ -224,7 +224,7 @@ class Link */ public static function before( $funcName, $params = null ) { - array_push( self::$beforeFuncs, [ $funcName, $params ]); + array_push( self::$beforeFuncs, array($funcName, $params)); } /** @@ -236,6 +236,6 @@ class Link */ public static function after( $funcName, $params = null ) { - array_push( self::$afterFuncs, [ $funcName, $params ]); + array_push( self::$afterFuncs, array($funcName, $params)); } } \ No newline at end of file diff --git a/api/Tests/BusinessLogic/Attachments/AttachmentHandlerTest.php b/api/Tests/BusinessLogic/Attachments/AttachmentHandlerTest.php index 74e6a9dd..767bc780 100644 --- a/api/Tests/BusinessLogic/Attachments/AttachmentHandlerTest.php +++ b/api/Tests/BusinessLogic/Attachments/AttachmentHandlerTest.php @@ -46,11 +46,11 @@ class AttachmentHandlerTest extends TestCase { private $heskSettings; protected function setUp() { - $this->ticketGateway = $this->createMock(TicketGateway::class); - $this->attachmentGateway = $this->createMock(AttachmentGateway::class); - $this->fileWriter = $this->createMock(FileWriter::class); - $this->fileDeleter = $this->createMock(FileDeleter::class); - $this->userToTicketChecker = $this->createMock(UserToTicketChecker::class); + $this->ticketGateway = $this->createMock(TicketGateway::clazz()); + $this->attachmentGateway = $this->createMock(AttachmentGateway::clazz()); + $this->fileWriter = $this->createMock(FileWriter::clazz()); + $this->fileDeleter = $this->createMock(FileDeleter::clazz()); + $this->userToTicketChecker = $this->createMock(UserToTicketChecker::clazz()); $this->heskSettings = array( 'attach_dir' => 'attachments', 'attachments' => array( @@ -78,7 +78,7 @@ class AttachmentHandlerTest extends TestCase { $this->createAttachmentForTicketModel->attachmentContents = null; //-- Assert - $this->expectException(ValidationException::class); + $this->expectException(ValidationException::clazz()); $this->expectExceptionMessageRegExp('/CONTENTS_EMPTY/'); //-- Act @@ -91,7 +91,7 @@ class AttachmentHandlerTest extends TestCase { $this->createAttachmentForTicketModel->attachmentContents = ''; //-- Assert - $this->expectException(ValidationException::class); + $this->expectException(ValidationException::clazz()); $this->expectExceptionMessageRegExp('/CONTENTS_EMPTY/'); //-- Act @@ -106,7 +106,7 @@ class AttachmentHandlerTest extends TestCase { $this->createAttachmentForTicketModel->attachmentContents = 'invalid base 64'; //-- Assert - $this->expectException(ValidationException::class); + $this->expectException(ValidationException::clazz()); $this->expectExceptionMessageRegExp('/CONTENTS_NOT_BASE_64/'); //-- Act @@ -119,7 +119,7 @@ class AttachmentHandlerTest extends TestCase { $this->createAttachmentForTicketModel->displayName = null; //-- Assert - $this->expectException(ValidationException::class); + $this->expectException(ValidationException::clazz()); $this->expectExceptionMessageRegExp('/DISPLAY_NAME_EMPTY/'); //-- Act @@ -132,7 +132,7 @@ class AttachmentHandlerTest extends TestCase { $this->createAttachmentForTicketModel->displayName = ''; //-- Assert - $this->expectException(ValidationException::class); + $this->expectException(ValidationException::clazz()); $this->expectExceptionMessageRegExp('/DISPLAY_NAME_EMPTY/'); //-- Act @@ -145,7 +145,7 @@ class AttachmentHandlerTest extends TestCase { $this->createAttachmentForTicketModel->ticketId = null; //-- Assert - $this->expectException(ValidationException::class); + $this->expectException(ValidationException::clazz()); $this->expectExceptionMessageRegExp('/TICKET_ID_MISSING/'); //-- Act @@ -158,7 +158,7 @@ class AttachmentHandlerTest extends TestCase { $this->createAttachmentForTicketModel->ticketId = 0; //-- Assert - $this->expectException(ValidationException::class); + $this->expectException(ValidationException::clazz()); $this->expectExceptionMessageRegExp('/TICKET_ID_MISSING/'); //-- Act @@ -172,7 +172,7 @@ class AttachmentHandlerTest extends TestCase { $this->createAttachmentForTicketModel->ticketId = 0; //-- Assert - $this->expectException(ValidationException::class); + $this->expectException(ValidationException::clazz()); $this->expectExceptionMessageRegExp('/EXTENSION_NOT_PERMITTED/'); //-- Act @@ -186,7 +186,7 @@ class AttachmentHandlerTest extends TestCase { $this->heskSettings['attachments']['max_size'] = 1; //-- Assert - $this->expectException(ValidationException::class); + $this->expectException(ValidationException::clazz()); $this->expectExceptionMessageRegExp('/FILE_SIZE_TOO_LARGE/'); //-- Act @@ -261,7 +261,7 @@ class AttachmentHandlerTest extends TestCase { ->willReturn(false); //-- Assert - $this->expectException(\Exception::class); + $this->expectException(\BaseException::clazz()); $this->expectExceptionMessage("User does not have access to ticket {$ticketId} being created / edited!"); //-- Act diff --git a/api/Tests/BusinessLogic/Attachments/AttachmentRetrieverTest.php b/api/Tests/BusinessLogic/Attachments/AttachmentRetrieverTest.php index 776fe1eb..426d585c 100644 --- a/api/Tests/BusinessLogic/Attachments/AttachmentRetrieverTest.php +++ b/api/Tests/BusinessLogic/Attachments/AttachmentRetrieverTest.php @@ -32,10 +32,10 @@ class AttachmentRetrieverTest extends TestCase { private $heskSettings; protected function setUp() { - $this->attachmentGateway = $this->createMock(AttachmentGateway::class); - $this->fileReader = $this->createMock(FileReader::class); - $this->ticketGateway = $this->createMock(TicketGateway::class); - $this->userToTicketChecker = $this->createMock(UserToTicketChecker::class); + $this->attachmentGateway = $this->createMock(AttachmentGateway::clazz()); + $this->fileReader = $this->createMock(FileReader::clazz()); + $this->ticketGateway = $this->createMock(TicketGateway::clazz()); + $this->userToTicketChecker = $this->createMock(UserToTicketChecker::clazz()); $this->heskSettings = array('attach_dir' => 'attachments'); $this->attachmentRetriever = new AttachmentRetriever($this->attachmentGateway, $this->fileReader, diff --git a/api/Tests/BusinessLogic/Categories/CategoryHandlerTest.php b/api/Tests/BusinessLogic/Categories/CategoryHandlerTest.php index 9cb886c9..6b316669 100644 --- a/api/Tests/BusinessLogic/Categories/CategoryHandlerTest.php +++ b/api/Tests/BusinessLogic/Categories/CategoryHandlerTest.php @@ -32,10 +32,10 @@ class CategoryHandlerTest extends TestCase { private $heskSettings; protected function setUp() { - $this->categoryGateway = $this->createMock(CategoryGateway::class); - $this->ticketGateway = $this->createMock(TicketGateway::class); - $this->permissionChecker = $this->createMock(PermissionChecker::class); - $this->modsForHeskSettingsGateway = $this->createMock(ModsForHeskSettingsGateway::class); + $this->categoryGateway = $this->createMock(CategoryGateway::clazz()); + $this->ticketGateway = $this->createMock(TicketGateway::clazz()); + $this->permissionChecker = $this->createMock(PermissionChecker::clazz()); + $this->modsForHeskSettingsGateway = $this->createMock(ModsForHeskSettingsGateway::clazz()); $this->categoryHandler = new CategoryHandler($this->categoryGateway, $this->ticketGateway, diff --git a/api/Tests/BusinessLogic/Emails/EmailSenderHelperTest.php b/api/Tests/BusinessLogic/Emails/EmailSenderHelperTest.php index c9d5c0cb..1c34786a 100644 --- a/api/Tests/BusinessLogic/Emails/EmailSenderHelperTest.php +++ b/api/Tests/BusinessLogic/Emails/EmailSenderHelperTest.php @@ -38,9 +38,9 @@ class EmailSenderHelperTest extends TestCase { private $modsForHeskSettings; protected function setUp() { - $this->emailTemplateParser = $this->createMock(EmailTemplateParser::class); - $this->basicEmailSender = $this->createMock(BasicEmailSender::class); - $this->mailgunEmailSender = $this->createMock(MailgunEmailSender::class); + $this->emailTemplateParser = $this->createMock(EmailTemplateParser::clazz()); + $this->basicEmailSender = $this->createMock(BasicEmailSender::clazz()); + $this->mailgunEmailSender = $this->createMock(MailgunEmailSender::clazz()); $this->heskSettings = array( 'languages' => array( 'English' => array('folder' => 'en') diff --git a/api/Tests/BusinessLogic/Security/BanRetrieverTest.php b/api/Tests/BusinessLogic/Security/BanRetrieverTest.php index 304bffa0..6cfaaf3b 100644 --- a/api/Tests/BusinessLogic/Security/BanRetrieverTest.php +++ b/api/Tests/BusinessLogic/Security/BanRetrieverTest.php @@ -22,7 +22,7 @@ class BanRetrieverTests extends TestCase { private $banRetriever; protected function setUp() { - $this->banGateway = $this->createMock(BanGateway::class); + $this->banGateway = $this->createMock(BanGateway::clazz()); $this->banRetriever = new BanRetriever($this->banGateway); } diff --git a/api/Tests/BusinessLogic/Security/UserToTicketCheckerTest.php b/api/Tests/BusinessLogic/Security/UserToTicketCheckerTest.php index 07318d66..cf6d1719 100644 --- a/api/Tests/BusinessLogic/Security/UserToTicketCheckerTest.php +++ b/api/Tests/BusinessLogic/Security/UserToTicketCheckerTest.php @@ -20,7 +20,7 @@ class UserToTicketCheckerTest extends TestCase { private $heskSettings; protected function setUp() { - $this->userGateway = $this->createMock(UserGateway::class); + $this->userGateway = $this->createMock(UserGateway::clazz()); $this->userToTicketChecker = new UserToTicketChecker($this->userGateway); } diff --git a/api/Tests/BusinessLogic/Tickets/AutoassignerTest.php b/api/Tests/BusinessLogic/Tickets/AutoassignerTest.php index 8e9836ac..e7192b9a 100644 --- a/api/Tests/BusinessLogic/Tickets/AutoassignerTest.php +++ b/api/Tests/BusinessLogic/Tickets/AutoassignerTest.php @@ -28,8 +28,8 @@ class AutoassignerTest extends TestCase { private $heskSettings; protected function setUp() { - $this->categoryGateway = $this->createMock(CategoryGateway::class); - $this->userGateway = $this->createMock(UserGateway::class); + $this->categoryGateway = $this->createMock(CategoryGateway::clazz()); + $this->userGateway = $this->createMock(UserGateway::clazz()); $this->autoassigner = new Autoassigner($this->categoryGateway, $this->userGateway); $this->heskSettings = array( 'autoassign' => 1 diff --git a/api/Tests/BusinessLogic/Tickets/NewTicketValidatorTest.php b/api/Tests/BusinessLogic/Tickets/NewTicketValidatorTest.php index 2ace5299..108859cd 100644 --- a/api/Tests/BusinessLogic/Tickets/NewTicketValidatorTest.php +++ b/api/Tests/BusinessLogic/Tickets/NewTicketValidatorTest.php @@ -48,9 +48,9 @@ class NewTicketValidatorTest extends TestCase { private $heskSettings = array(); function setUp() { - $this->banRetriever = $this->createMock(BanRetriever::class); - $this->categoryRetriever = $this->createMock(CategoryRetriever::class); - $this->ticketValidators = $this->createMock(TicketValidators::class); + $this->banRetriever = $this->createMock(BanRetriever::clazz()); + $this->categoryRetriever = $this->createMock(CategoryRetriever::clazz()); + $this->ticketValidators = $this->createMock(TicketValidators::clazz()); $this->newTicketValidator = new NewTicketValidator($this->categoryRetriever, $this->banRetriever, $this->ticketValidators); $this->userContext = new UserContext(); diff --git a/api/Tests/BusinessLogic/Tickets/TicketCreatorTests/CreateTicketForCustomerTest.php b/api/Tests/BusinessLogic/Tickets/TicketCreatorTests/CreateTicketForCustomerTest.php index a0a3ea07..c2577ab0 100644 --- a/api/Tests/BusinessLogic/Tickets/TicketCreatorTests/CreateTicketForCustomerTest.php +++ b/api/Tests/BusinessLogic/Tickets/TicketCreatorTests/CreateTicketForCustomerTest.php @@ -98,15 +98,15 @@ class CreateTicketTest extends TestCase { private $modsForHeskSettings; protected function setUp() { - $this->ticketGateway = $this->createMock(TicketGateway::class); - $this->newTicketValidator = $this->createMock(NewTicketValidator::class); - $this->trackingIdGenerator = $this->createMock(TrackingIdGenerator::class); - $this->autoassigner = $this->createMock(Autoassigner::class); - $this->statusGateway = $this->createMock(StatusGateway::class); - $this->verifiedEmailChecker = $this->createMock(VerifiedEmailChecker::class); - $this->emailSenderHelper = $this->createMock(EmailSenderHelper::class); - $this->userGateway = $this->createMock(UserGateway::class); - $this->modsForHeskSettingsGateway = $this->createMock(ModsForHeskSettingsGateway::class); + $this->ticketGateway = $this->createMock(TicketGateway::clazz()); + $this->newTicketValidator = $this->createMock(NewTicketValidator::clazz()); + $this->trackingIdGenerator = $this->createMock(TrackingIdGenerator::clazz()); + $this->autoassigner = $this->createMock(Autoassigner::clazz()); + $this->statusGateway = $this->createMock(StatusGateway::clazz()); + $this->verifiedEmailChecker = $this->createMock(VerifiedEmailChecker::clazz()); + $this->emailSenderHelper = $this->createMock(EmailSenderHelper::clazz()); + $this->userGateway = $this->createMock(UserGateway::clazz()); + $this->modsForHeskSettingsGateway = $this->createMock(ModsForHeskSettingsGateway::clazz()); $this->ticketCreator = new TicketCreator($this->newTicketValidator, $this->trackingIdGenerator, $this->autoassigner, $this->statusGateway, $this->ticketGateway, $this->verifiedEmailChecker, diff --git a/api/Tests/BusinessLogic/Tickets/TicketDeleterTest.php b/api/Tests/BusinessLogic/Tickets/TicketDeleterTest.php index bce86231..b55194fd 100644 --- a/api/Tests/BusinessLogic/Tickets/TicketDeleterTest.php +++ b/api/Tests/BusinessLogic/Tickets/TicketDeleterTest.php @@ -30,9 +30,9 @@ class TicketDeleterTest extends TestCase { private $userToTicketChecker; protected function setUp() { - $this->userToTicketChecker = $this->createMock(UserToTicketChecker::class); - $this->ticketGateway = $this->createMock(TicketGateway::class); - $this->attachmentHandler = $this->createMock(AttachmentHandler::class); + $this->userToTicketChecker = $this->createMock(UserToTicketChecker::clazz()); + $this->ticketGateway = $this->createMock(TicketGateway::clazz()); + $this->attachmentHandler = $this->createMock(AttachmentHandler::clazz()); $this->ticketDeleter = new TicketDeleter($this->ticketGateway, $this->userToTicketChecker, $this->attachmentHandler); } @@ -43,7 +43,7 @@ class TicketDeleterTest extends TestCase { $this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(false); //-- Assert - $this->expectException(\Exception::class); + $this->expectException(\BaseException::clazz()); $this->expectExceptionMessage("User does not have access to ticket 1"); //-- Act diff --git a/api/Tests/BusinessLogic/Tickets/TicketRetrieverTest.php b/api/Tests/BusinessLogic/Tickets/TicketRetrieverTest.php index 8065c5a7..90ec9280 100644 --- a/api/Tests/BusinessLogic/Tickets/TicketRetrieverTest.php +++ b/api/Tests/BusinessLogic/Tickets/TicketRetrieverTest.php @@ -21,8 +21,8 @@ class TicketRetrieverTest extends TestCase { private $heskSettings; protected function setUp() { - $this->ticketGateway = $this->createMock(TicketGateway::class); - $this->userToTicketChecker = $this->createMock(UserToTicketChecker::class); + $this->ticketGateway = $this->createMock(TicketGateway::clazz()); + $this->userToTicketChecker = $this->createMock(UserToTicketChecker::clazz()); $this->heskSettings = array('email_view_ticket' => 0); $this->ticketRetriever = new TicketRetriever($this->ticketGateway, $this->userToTicketChecker); @@ -65,7 +65,7 @@ class TicketRetrieverTest extends TestCase { $this->ticketGateway->method('getTicketByTrackingId')->with($trackingId, $this->heskSettings)->willReturn($ticket); //-- Assert - $this->expectException(\Exception::class); + $this->expectException(\BaseException::clazz()); $this->expectExceptionMessage("Email 'email@example.com' entered in for ticket '12345' does not match!"); //-- Act diff --git a/api/Tests/BusinessLogic/Tickets/TicketValidatorsTest.php b/api/Tests/BusinessLogic/Tickets/TicketValidatorsTest.php index 6fceb76e..fcd05d17 100644 --- a/api/Tests/BusinessLogic/Tickets/TicketValidatorsTest.php +++ b/api/Tests/BusinessLogic/Tickets/TicketValidatorsTest.php @@ -18,7 +18,7 @@ class TicketValidatorsTest extends TestCase { private $ticketValidator; protected function setUp() { - $this->ticketGateway = $this->createMock(TicketGateway::class); + $this->ticketGateway = $this->createMock(TicketGateway::clazz()); $this->ticketValidator = new TicketValidators($this->ticketGateway); } diff --git a/api/Tests/BusinessLogic/Tickets/TrackingIdGeneratorTest.php b/api/Tests/BusinessLogic/Tickets/TrackingIdGeneratorTest.php index f879e579..f72957ec 100644 --- a/api/Tests/BusinessLogic/Tickets/TrackingIdGeneratorTest.php +++ b/api/Tests/BusinessLogic/Tickets/TrackingIdGeneratorTest.php @@ -19,7 +19,7 @@ class TrackingIdGeneratorTest extends TestCase { private $trackingIdGenerator; function setUp() { - $this->ticketGateway = $this->createMock(TicketGateway::class); + $this->ticketGateway = $this->createMock(TicketGateway::clazz()); $this->trackingIdGenerator = new TrackingIdGenerator($this->ticketGateway); } diff --git a/api/Tests/BusinessLogic/Tickets/VerifiedEmailCheckerTest.php b/api/Tests/BusinessLogic/Tickets/VerifiedEmailCheckerTest.php index 2cf838c5..328d898b 100644 --- a/api/Tests/BusinessLogic/Tickets/VerifiedEmailCheckerTest.php +++ b/api/Tests/BusinessLogic/Tickets/VerifiedEmailCheckerTest.php @@ -23,7 +23,7 @@ class VerifiedEmailCheckerTest extends TestCase { private $heskSettings; protected function setUp() { - $this->verifiedEmailGateway = $this->createMock(VerifiedEmailGateway::class); + $this->verifiedEmailGateway = $this->createMock(VerifiedEmailGateway::clazz()); $this->heskSettings = array(); $this->verifiedEmailChecker = new VerifiedEmailChecker($this->verifiedEmailGateway); } diff --git a/api/index.php b/api/index.php index 8de69fc5..393455a4 100644 --- a/api/index.php +++ b/api/index.php @@ -183,10 +183,10 @@ Link::before('globalBefore'); Link::all(array( // Categories - '/v1/categories/all' => action(\Controllers\Categories\CategoryController::clazz() . '::printAllCategories', [RequestMethod::GET], SecurityHandler::INTERNAL_OR_AUTH_TOKEN), - '/v1/categories' => action(\Controllers\Categories\CategoryController::clazz(), [RequestMethod::POST], SecurityHandler::INTERNAL_OR_AUTH_TOKEN), - '/v1/categories/{i}' => action(\Controllers\Categories\CategoryController::clazz(), [RequestMethod::GET, RequestMethod::PUT, RequestMethod::DELETE], SecurityHandler::INTERNAL_OR_AUTH_TOKEN), - '/v1-internal/categories/{i}/sort/{s}' => action(\Controllers\Categories\CategoryController::clazz() . '::sort', [RequestMethod::POST], SecurityHandler::INTERNAL), + '/v1/categories/all' => action(\Controllers\Categories\CategoryController::clazz() . '::printAllCategories', array(RequestMethod::GET), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), + '/v1/categories' => action(\Controllers\Categories\CategoryController::clazz(), array(RequestMethod::POST), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), + '/v1/categories/{i}' => action(\Controllers\Categories\CategoryController::clazz(), array(RequestMethod::GET, RequestMethod::PUT, RequestMethod::DELETE), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), + '/v1-internal/categories/{i}/sort/{s}' => action(\Controllers\Categories\CategoryController::clazz() . '::sort', array(RequestMethod::POST), SecurityHandler::INTERNAL), // Tickets '/v1/tickets' => action(\Controllers\Tickets\CustomerTicketController::clazz(), RequestMethod::all()), // Tickets - Staff @@ -230,7 +230,7 @@ Link::all(array( * @return array The configured path */ function action($class, $requestMethods, $securityHandler = SecurityHandler::AUTH_TOKEN) { - return [$class, $class, $securityHandler, $requestMethods]; + return array($class, $class, $securityHandler, $requestMethods); } class SecurityHandler { diff --git a/ci/php_lint.sh b/ci/php_lint.sh index 1e0c3ad1..0cef4eb2 100644 --- a/ci/php_lint.sh +++ b/ci/php_lint.sh @@ -12,7 +12,7 @@ while test $# -gt 0; do continue fi - for file in `find $current -type f -not -path "*vendor/*" -name "*.php"` ; do + for file in `find $current -type f -not -path "*vendor/*" -not -path "api/Tests/*" -name "*.php"` ; do RESULTS=`php -l $file` echo $RESULTS diff --git a/internal-api/admin/api-authentication/index.php b/internal-api/admin/api-authentication/index.php index 4908246a..a297d1eb 100644 --- a/internal-api/admin/api-authentication/index.php +++ b/internal-api/admin/api-authentication/index.php @@ -31,7 +31,7 @@ if ($request_method == 'POST') { if ($action == 'generate') { $token = ''; - $letter_array = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']; + $letter_array = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'); // Pick 32 random characters. That will be the hash for ($i = 0; $i < 32; $i++) { $letter = $letter_array[rand(0, 15)];