Skip to content

Commit

Permalink
feature: Refactored for PHP8 standards
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Sep 28, 2022
1 parent 5a916b2 commit 0452bb5
Show file tree
Hide file tree
Showing 77 changed files with 488 additions and 596 deletions.
28 changes: 11 additions & 17 deletions app/Connectors/GenericConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,43 @@

class GenericConnector
{
public $server;

public $user;

public function __construct(\App\Models\Server $server = null, $user = null)
public function __construct(public $server = null, public $user = null)
{
$this->server = $server;
$this->user = $user;
}

public function execute($command)
public function execute($command): string
{
return trim(
self::request('command', [
(string) self::request('command', [
'command' => $command,
])
);
}

public function sendFile($localPath, $remotePath, $permissions = 0644)
public function sendFile($localPath, $remotePath, $permissions = 0644): string
{
return trim(
self::request('putFile', [
(string) self::request('putFile', [
'local_path' => $localPath,
'remote_path' => $remotePath,
])
);
}

public function receiveFile($localPath, $remotePath)
public function receiveFile($localPath, $remotePath): string
{
return trim(
self::request('getFile', [
(string) self::request('getFile', [
'local_path' => $localPath,
'remote_path' => $remotePath,
])
);
}

public function verify($ip_address, $username, $password, $port, $type)
public function verify($ip_address, $username, $password, $port, $type): string
{
return trim(
self::request('verify', [
(string) self::request('verify', [
'ip_address' => $ip_address,
'username' => $username,
'password' => $password,
Expand Down Expand Up @@ -102,14 +96,14 @@ public function request($url, $params, $retry = 3)
if ($exception->getResponse() && $exception->getResponse()->getStatusCode() >= 400) {
$code = $exception->getResponse()->getStatusCode();

$message = json_decode($exception->getResponse()->getBody()->getContents())->message;
$message = json_decode((string) $exception->getResponse()->getBody()->getContents())->message;
if ($message == '') {
$message = $exception->getMessage();
}
} else {
$message = $exception->getMessage();
}
} catch (\Throwable $e) {
} catch (\Throwable) {
$message = $exception->getMessage();
}

Expand Down
21 changes: 7 additions & 14 deletions app/Connectors/SNMPConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class SNMPConnector implements Connector
*/
protected $connection;

protected $server;

protected $ssh;

protected $key;
Expand All @@ -22,13 +20,13 @@ class SNMPConnector implements Connector

protected $username;

protected $securityLevel;
protected $securityLevel = 'authPriv';

protected $authProtocol;
protected $authProtocol = 'SHA';

protected $authPassword;

protected $privacyProtocol;
protected $privacyProtocol = 'AES';

protected $privacyPassword;

Expand All @@ -40,19 +38,15 @@ class SNMPConnector implements Connector
* @param \App\Models\Server $server
* @param null $user_id
*/
public function __construct(\App\Models\Server $server, $user_id)
public function __construct(protected \App\Models\Server $server, $user_id)
{
[$username, $password, $port] = self::retrieveCredentials();
$this->server = $server;
$this->username = $username;
$this->securityLevel = 'authPriv';
$this->authProtocol = 'SHA';
$this->authPassword = $password;
$this->privacyProtocol = 'AES';
$this->privacyPassword = $password;
}

public function execute($command, $flag = true)
public function execute($command, $flag = true): string|bool
{
return snmp3_get(
$this->server->ip_address,
Expand All @@ -75,7 +69,6 @@ public function receiveFile($localPath, $remotePath)
}

/**
* @param \App\Models\Server $server
* @param $username
* @param $password
* @param $user_id
Expand All @@ -96,7 +89,7 @@ public static function verify($ip_address, $username, $password, $port)
{
}

public static function createSnmp()
public static function createSnmp(): bool
{
return true;
}
Expand Down Expand Up @@ -135,7 +128,7 @@ public static function retrieveCredentials()
'Bu sunucu için SNMP anahtarınız yok. Kasa üzerinden bir anahtar ekleyebilirsiniz.'
);
}
$data = json_decode(server()->key()->data, true);
$data = json_decode((string) server()->key()->data, true);

return [
lDecrypt($data['clientUsername']),
Expand Down
3 changes: 1 addition & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class Kernel extends ConsoleKernel
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
Expand Down Expand Up @@ -87,7 +86,7 @@ protected function schedule(Schedule $schedule)
$response = $client->post(
env('MARKET_URL').'/api/users/me'
);
} catch (\Exception $e) {
} catch (\Exception) {
return;
}
$array = $controller->checkMarketUpdates(true);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function validateLogin(Request $request)
}
}

protected function sendFailedLoginResponse(Request $request)
protected function sendFailedLoginResponse(Request $request): never
{
$credientials = (object) $this->credentials($request);
hook('login_failed', [
Expand Down
5 changes: 1 addition & 4 deletions app/Http/Controllers/Auth/LogoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
*/
class LogoutController extends Controller
{
/**
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response
*/
public function logout()
public function logout(): \Illuminate\Http\RedirectResponse
{
system_log(7, 'LOGOUT_SUCCESS');
hook('logout_attempt', [
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/Certificate/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function verifyCert()
// Check If Certificate Already Added or not.
if (
Certificate::where([
'server_hostname' => strtolower(request('server_hostname')),
'server_hostname' => strtolower((string) request('server_hostname')),
'origin' => request('origin'),
])->exists()
) {
Expand All @@ -38,7 +38,7 @@ public function verifyCert()
}

[$flag, $message] = retrieveCertificate(
strtolower(request('server_hostname')),
strtolower((string) request('server_hostname')),
request('origin')
);

Expand All @@ -51,7 +51,7 @@ public function verifyCert()

// Create Certificate Object.
$certificate = Certificate::create([
'server_hostname' => strtolower(request('server_hostname')),
'server_hostname' => strtolower((string) request('server_hostname')),
'origin' => request('origin'),
]);

Expand Down Expand Up @@ -109,7 +109,7 @@ public function getCertificateInfo(Request $request)
'authorityKeyIdentifier',
$certinfo['extensions']
)
? substr($certinfo['extensions']['authorityKeyIdentifier'], 6)
? substr((string) $certinfo['extensions']['authorityKeyIdentifier'], 6)
: '';
$certinfo['validFrom_time_t'] = Carbon::createFromTimestamp(
$certinfo['validFrom_time_t']
Expand Down
18 changes: 9 additions & 9 deletions app/Http/Controllers/CronMail/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MainController extends Controller
{
public function getMailTags()
{
$path = '/liman/extensions/'.strtolower(extension()->name).'/db.json';
$path = '/liman/extensions/'.strtolower((string) extension()->name).'/db.json';
if (! is_file($path)) {
return respond('Bu eklentinin bir veritabanı yok!', 201);
}
Expand Down Expand Up @@ -82,7 +82,7 @@ public function deleteCronMail()
private function getTagText($key, $extension_name)
{
if (! array_key_exists($extension_name, $this->tagTexts)) {
$file = file_get_contents('/liman/extensions/'.strtolower($extension_name).'/db.json');
$file = file_get_contents('/liman/extensions/'.strtolower((string) $extension_name).'/db.json');
$json = json_decode($file, true);
if (json_last_error() != JSON_ERROR_NONE) {
return $key;
Expand All @@ -108,7 +108,7 @@ public function getCronMail()
$ext = Extension::find($obj->extension_id);
if ($ext) {
$obj->extension_name = $ext->display_name;
$target_list = json_decode($obj->target);
$target_list = json_decode((string) $obj->target);
foreach ($target_list as &$target) {
$target = $this->getTagText($target, $ext->name);
}
Expand All @@ -125,20 +125,20 @@ public function getCronMail()
$obj->server_name = 'Bu sunucu silinmiş!';
}

$user_ids = json_decode($obj->user_id);
$user_ids = json_decode((string) $obj->user_id);
$users = [];
foreach ($user_ids as $usr) {
try {
$user = User::find($usr);
} catch (\Throwable $e) {
} catch (\Throwable) {
continue;
}
$users[] = $user->name;
}

$obj->username = implode(', ', $users);

$obj->to = implode(', ', json_decode($obj->to));
$obj->to = implode(', ', json_decode((string) $obj->to));

return $obj;
});
Expand Down Expand Up @@ -179,11 +179,11 @@ public function editView()

$cron_mail = CronMail::findOrFail($id);

$users = json_decode($cron_mail->user_id);
$users = json_decode((string) $cron_mail->user_id);
$users = User::find($users);

$to = json_decode($cron_mail->to);
$target = json_decode($cron_mail->target);
$to = json_decode((string) $cron_mail->to);
$target = json_decode((string) $cron_mail->target);

return view('settings.edit_mail', compact(['cron_mail', 'users', 'to', 'target']));
}
Expand Down
Loading

0 comments on commit 0452bb5

Please sign in to comment.