1
0
mirror of https://github.com/nerzhul/ocsms.git synced 2025-07-17 15:05:56 +00:00

Code cleanup + some PHPDoc

This commit is contained in:
Loic Blot 2016-05-19 08:03:27 +02:00
parent 339f76cf01
commit f05d5562b8
3 changed files with 36 additions and 6 deletions

View File

@ -74,9 +74,12 @@ class ApiController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @NoCSRFRequired * @NoCSRFRequired
* @param $smsCount
* @param $smsDatas
* @return JSONResponse
*/ */
public function push ($smsCount, $smsDatas) { public function push ($smsCount, $smsDatas) {
if ($this->checkPushStructure($smsCount, $smsDatas, true) === false) { if ($this->checkPushStructure($smsCount, $smsDatas) === false) {
return new JSONResponse(array("status" => false, "msg" => $this->errorMsg)); return new JSONResponse(array("status" => false, "msg" => $this->errorMsg));
} }
@ -86,9 +89,12 @@ class ApiController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @param $smsCount
* @param $smsDatas
* @return JSONResponse
*/ */
public function replace($smsCount, $smsDatas) { public function replace($smsCount, $smsDatas) {
if ($this->checkPushStructure($smsCount, $smsDatas, true) === false) { if ($this->checkPushStructure($smsCount, $smsDatas) === false) {
return new JSONResponse(array("status" => false, "msg" => $this->errorMsg)); return new JSONResponse(array("status" => false, "msg" => $this->errorMsg));
} }
@ -96,6 +102,11 @@ class ApiController extends Controller {
return new JSONResponse(array("status" => true, "msg" => "OK")); return new JSONResponse(array("status" => true, "msg" => "OK"));
} }
/**
* @param $smsCount
* @param $smsDatas
* @return bool
*/
private function checkPushStructure ($smsCount, $smsDatas) { private function checkPushStructure ($smsCount, $smsDatas) {
if ($smsCount != count($smsDatas)) { if ($smsCount != count($smsDatas)) {
$this->errorMsg = "Error: sms count invalid"; $this->errorMsg = "Error: sms count invalid";
@ -163,6 +174,9 @@ class ApiController extends Controller {
* @NoCSRFRequired * @NoCSRFRequired
* *
* APIv2 * APIv2
* @param $start
* @param $limit
* @return JSONResponse
*/ */
public function fetchMessages($start, $limit) { public function fetchMessages($start, $limit) {
if (!is_numeric($start) || !is_numeric($limit) || $start < 0 || $limit <= 0) { if (!is_numeric($start) || !is_numeric($limit) || $start < 0 || $limit <= 0) {
@ -183,6 +197,10 @@ class ApiController extends Controller {
* @NoCSRFRequired * @NoCSRFRequired
* *
* APIv2 * APIv2
* @param $phoneNumber
* @param $start
* @param $limit
* @return JSONResponse
*/ */
public function fetchMessagesForNumber($phoneNumber, $start, $limit) { public function fetchMessagesForNumber($phoneNumber, $start, $limit) {
if (!is_numeric($start) || !is_numeric($limit) || $start < 0 || $limit <= 0) { if (!is_numeric($start) || !is_numeric($limit) || $start < 0 || $limit <= 0) {

View File

@ -52,6 +52,8 @@ class SettingsController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @param $country
* @return JSONResponse
*/ */
function setCountry($country) { function setCountry($country) {
if (!array_key_exists($country, CountryCodes::$codes)) { if (!array_key_exists($country, CountryCodes::$codes)) {
@ -63,6 +65,8 @@ class SettingsController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @param $limit
* @return JSONResponse
*/ */
function setMessageLimit($limit) { function setMessageLimit($limit) {
$this->configMapper->set("message_limit", $limit); $this->configMapper->set("message_limit", $limit);
@ -71,6 +75,8 @@ class SettingsController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @param $notification
* @return JSONResponse
*/ */
function setNotificationState($notification) { function setNotificationState($notification) {
if (!is_numeric($notification) || $notification < 0 || $notification > 2) { if (!is_numeric($notification) || $notification < 0 || $notification > 2) {

View File

@ -24,7 +24,6 @@ use \OCA\OcSms\Db\ConfigMapper;
use \OCA\OcSms\Db\SmsMapper; use \OCA\OcSms\Db\SmsMapper;
use \OCA\OcSms\Lib\ContactCache; use \OCA\OcSms\Lib\ContactCache;
use \OCA\OcSms\Lib\CountryCodes;
use \OCA\OcSms\Lib\PhoneNumberFormatter; use \OCA\OcSms\Lib\PhoneNumberFormatter;
class SmsController extends Controller { class SmsController extends Controller {
@ -33,7 +32,6 @@ class SmsController extends Controller {
private $userId; private $userId;
private $configMapper; private $configMapper;
private $smsMapper; private $smsMapper;
private $errorMsg;
private $urlGenerator; private $urlGenerator;
private $contactCache; private $contactCache;
@ -84,7 +82,6 @@ class SmsController extends Controller {
// Cache country because of loops // Cache country because of loops
$configuredCountry = $this->configMapper->getCountry(); $configuredCountry = $this->configMapper->getCountry();
$countPhone = count($phoneList);
foreach ($phoneList as $number => $ts) { foreach ($phoneList as $number => $ts) {
$fmtPN = PhoneNumberFormatter::format($configuredCountry, $number); $fmtPN = PhoneNumberFormatter::format($configuredCountry, $number);
if (isset($contactsSrc[$number])) { if (isset($contactsSrc[$number])) {
@ -110,6 +107,9 @@ class SmsController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @NoCSRFRequired * @NoCSRFRequired
* @param $phoneNumber
* @param int $lastDate
* @return JSONResponse
*/ */
public function getConversation ($phoneNumber, $lastDate = 0) { public function getConversation ($phoneNumber, $lastDate = 0) {
$contacts = $this->contactCache->getContacts(); $contacts = $this->contactCache->getContacts();
@ -163,6 +163,8 @@ class SmsController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @NoCSRFRequired * @NoCSRFRequired
* @param $contact
* @return JSONResponse
*/ */
public function deleteConversation ($contact) { public function deleteConversation ($contact) {
$contacts = $this->contactCache->getContacts(); $contacts = $this->contactCache->getContacts();
@ -193,6 +195,8 @@ class SmsController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @NoCSRFRequired * @NoCSRFRequired
* @param $lastDate
* @return JSONResponse
*/ */
public function checkNewMessages($lastDate) { public function checkNewMessages($lastDate) {
$phoneList = $this->smsMapper->getNewMessagesCountForAllPhonesNumbers($this->userId, $lastDate); $phoneList = $this->smsMapper->getNewMessagesCountForAllPhonesNumbers($this->userId, $lastDate);
@ -201,7 +205,6 @@ class SmsController extends Controller {
$contacts = array(); $contacts = array();
$photos = array(); $photos = array();
$countPhone = count($phoneList);
foreach ($phoneList as $number => $ts) { foreach ($phoneList as $number => $ts) {
$fmtPN = preg_replace("#[ ]#","/", $number); $fmtPN = preg_replace("#[ ]#","/", $number);
if (isset($contactsSrc[$fmtPN])) { if (isset($contactsSrc[$fmtPN])) {
@ -225,6 +228,9 @@ class SmsController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @NoCSRFRequired * @NoCSRFRequired
* @param $messageId
* @param $phoneNumber
* @return JSONResponse
*/ */
public function deleteMessage ($messageId, $phoneNumber) { public function deleteMessage ($messageId, $phoneNumber) {
if (!preg_match('#^[0-9]+$#',$messageId)) { if (!preg_match('#^[0-9]+$#',$messageId)) {