From 73f3eb8178ff00f283046e928bb825bcee111f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Pie=C5=82a?= Date: Tue, 27 Apr 2021 00:04:19 +0200 Subject: [PATCH] Fix --- classes/core.php | 4 ++-- classes/webhook.php | 4 ++-- classes/xmpp.php | 14 +++++++------- includes/app.php | 42 +++++++++++++++++++----------------------- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/classes/core.php b/classes/core.php index 201aab9..54f572c 100644 --- a/classes/core.php +++ b/classes/core.php @@ -11,10 +11,10 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -namespace Classes; +namespace classes; -use Config\Config; +use config\config; class core { diff --git a/classes/webhook.php b/classes/webhook.php index cf702be..c1afa9b 100644 --- a/classes/webhook.php +++ b/classes/webhook.php @@ -1,7 +1,7 @@ xmpp_options = new Options(); } - public function start() + public function start(): void { $this->xmpp_options->setHost($this->config->xmpp_server); $this->xmpp_options->setUseTls($this->config->xmpp_tls); @@ -23,12 +23,12 @@ class Xmpp extends Core{ $this->xmpp_client = new XmppClient($this->xmpp_options); } - public function connect() + public function connect(): void { $this->xmpp_client->connect(); } - public function sendMessage(string $text) + public function sendMessage(string $text): void { foreach($this->config->xmpp_recipients as $receipient) { @@ -42,7 +42,7 @@ class Xmpp extends Core{ } } - private function getChatType(int $type) + private function getChatType(int $type): string { if($type === 1) { @@ -60,7 +60,7 @@ class Xmpp extends Core{ return $return_type; } - public function disconnect() + public function disconnect(): void { $this->xmpp_client->disconnect(); } diff --git a/includes/app.php b/includes/app.php index 08e104a..c371288 100644 --- a/includes/app.php +++ b/includes/app.php @@ -1,27 +1,28 @@ config = new Config(); + $this->config = new config(); } /** * Main application loop */ - public function start(){ + public function start(): void + { if($this->checkIfRequestMethodIsPost() && $this->checkAuthorization() && $this->checkIfIpOnWhitelistAndWhitelistEnabled()) { $this->handleIncomingData(); } @@ -31,43 +32,38 @@ class App * Check if client is authorized to post via this gate * @return bool */ - private function checkAuthorization() + private function checkAuthorization(): ?bool { if(isset($_GET['apikey']) && $_GET['apikey'] === $this->config->api_key) { return true; } - else - { - die("ERROR: Client not authenticated to use this application"); - } - return false; + + die("ERROR: Client not authenticated to use this application"); } /** * Check if whitelist and ip address is in whitelist */ - private function checkIfIpOnWhitelistAndWhitelistEnabled(){ + private function checkIfIpOnWhitelistAndWhitelistEnabled(): bool + { if($this->config->ip_whitelist) { if(in_array($this->getRealIPAddr(),$this->config->ips_whitelist_list)) { return true; - }else - { - return false; } + + return false; } - else - { - return true; - } + + return true; } /** * Check if request method is post * @return bool */ - private function checkIfRequestMethodIsPost() + private function checkIfRequestMethodIsPost(): bool { if($_SERVER["REQUEST_METHOD"]) { @@ -78,7 +74,7 @@ class App } - private function handleIncomingData() + private function handleIncomingData(): void { $post = file_get_contents("php://input"); $wh = new Webhook($post);