chore: Remove unused classes and fix types.

Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
Rubén D
2022-12-10 12:30:58 +01:00
parent a597d8ae62
commit d5ec816415
9 changed files with 26 additions and 394 deletions

View File

@@ -432,13 +432,4 @@ class AccountAcl
return $this;
}
public function reset(): void
{
foreach (get_class_vars(__CLASS__) as $property => $value) {
if (str_starts_with($property, 'show')) {
$this->{$property} = false;
}
}
}
}

View File

@@ -1,85 +0,0 @@
<?php
/*
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2021, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/
namespace SP\Mvc\Model;
/**
* Class QueryAssignment
*
* @package SP\Mvc\Model
*/
final class QueryAssignment
{
protected array $fields = [];
protected array $values = [];
/**
* @param string $field
* @param $value
*
* @return $this
*/
public function addField(string $field, $value): QueryAssignment
{
if (strpos($field, '=') === false) {
$this->fields[] = $field . ' = ?';
$this->values[] = $value;
}
return $this;
}
public function setFields(array $fields, array $values): QueryAssignment
{
$this->fields = array_map(
static function ($value) {
return strpos($value, '=') === false
? "$value = ?"
: $value;
},
$fields
);
$this->values = array_merge($this->values, $values);
return $this;
}
public function getAssignments(): ?string
{
return $this->hasFields()
? implode(',', $this->fields)
: null;
}
public function hasFields(): bool
{
return count($this->fields) > 0;
}
public function getValues(): array
{
return $this->values;
}
}

View File

@@ -1,69 +0,0 @@
<?php
/*
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2021, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/
namespace SP\Mvc\Model;
/**
* Class QueryJoin
*
* @package SP\Mvc\Model
*/
final class QueryJoin
{
protected array $join = [];
protected array $param = [];
public function addJoin(string $join, ?array $params = null): QueryJoin
{
$this->join[] = $join;
if ($params !== null) {
$this->param = array_merge($this->param, $params);
}
return $this;
}
public function getJoins(): ?string
{
return $this->hasJoins()
? implode(PHP_EOL, $this->join)
: null;
}
public function hasJoins(): bool
{
return count($this->join) !== 0;
}
public function getParams(): array
{
return $this->param;
}
public function getJoinsCount(): int
{
return count($this->join);
}
}

View File

@@ -1,146 +0,0 @@
<?php
/*
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2021, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/
namespace SP\Util;
use SP\Core\Exceptions\SPException;
/**
* Class Connection para crear conexiones TCP o UDP
*
* @package SP\Util
*/
final class Connection implements ConnectionInterface
{
/**
* @var resource|false
*/
protected $socket;
protected string $host;
protected int $port;
protected int $errorno = 0;
protected string $errorstr = '';
/**
* @param $host string El host a conectar
* @param $port int El puerto a conectar
*/
public function __construct(string $host, int $port)
{
$this->host = gethostbyname($host);
$this->port = $port;
}
/**
* Obtener un socket
*
* @param $type int EL tipo de socket TCP/UDP
*
* @return resource
* @throws SPException
*/
public function getSocket(int $type)
{
if ($type === self::TYPE_UDP) {
$this->socket = $this->getUDPSocket();
} else {
$this->socket = $this->getTCPSocket();
}
if ($this->socket === false) {
throw new SPException($this->getSocketError(), SPException::WARNING);
}
stream_set_timeout($this->socket, self::SOCKET_TIMEOUT);
return $this->socket;
}
/**
* Obtener un socket del tipo UDP
*
* @return resource
*/
private function getUDPSocket()
{
return stream_socket_client(
'udp://'.$this->host.':'.$this->port,
$this->errorno,
$this->errorstr,
self::SOCKET_TIMEOUT
);
}
/**
* Obtener un socket del tipo TCP
*
* @return resource
*/
private function getTCPSocket()
{
return stream_socket_client(
'tcp://'.$this->host.':'.$this->port,
$this->errorno,
$this->errorstr,
self::SOCKET_TIMEOUT
);
}
/**
* Obtener el último error del socket
*/
public function getSocketError(): string
{
return sprintf('%s (%d)', $this->errorstr, $this->errorno);
}
/**
* Cerrar el socket
*/
public function closeSocket()
{
fclose($this->socket);
}
/**
* Enviar un mensaje al socket
*
* @throws SPException
*/
public function send(string $message): int
{
if (!is_resource($this->socket)) {
throw new SPException(__u('Socket not initialized'), SPException::WARNING);
}
$nBytes = @fwrite($this->socket, $message);
if ($nBytes === false) {
throw new SPException(__u('Error while sending the data'), SPException::WARNING, $this->getSocketError());
}
return $nBytes;
}
}

View File

@@ -1,59 +0,0 @@
<?php
/*
* sysPass
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2021, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/
namespace SP\Util;
/**
* Class ConnectionInterface
*
* @package SP\Util
*/
interface ConnectionInterface
{
public const TYPE_TCP = 1;
public const TYPE_UDP = 2;
public const SOCKET_TIMEOUT = 10;
/**
* Obtener un socket
*
* @return resource
*/
public function getSocket(int $type);
/**
* Cerrar un socket
*/
public function closeSocket();
/**
* Obtener el último error del socket
*/
public function getSocketError(): string;
/**
* Enviar un mensaje al socket
*/
public function send(string $message);
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2021, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -37,10 +37,10 @@ final class DateUtil
* @param int|string $date
* @param string $format
*
* @return false|string
* @return int|string
*/
public static function getDateFromUnix($date, string $format = 'Y-m-d H:i')
public static function getDateFromUnix(int|string $date, string $format = 'Y-m-d H:i'): int|string
{
return is_numeric($date) ? date($format, $date) : $date;
}
}
}

View File

@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link https://syspass.org
* @copyright 2012-2021, Rubén Domínguez nuxsmin@$syspass.org
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
@@ -32,6 +32,7 @@ use SP\Core\Exceptions\SPException;
use SP\Domain\User\Services\UpdatedMasterPassException;
use SP\Mvc\View\Template;
use SP\Mvc\View\TemplateInterface;
use function SP\processException;
/**
* Class ErrorUtil
@@ -176,4 +177,4 @@ final class ErrorUtil
'hint' => __('Please contact to the administrator'),
];
}
}
}

View File

@@ -24,8 +24,10 @@
namespace SP\Util;
use JetBrains\PhpStorm\NoReturn;
use SP\Infrastructure\File\FileException;
use SP\Infrastructure\File\FileHandler;
use function SP\logger;
defined('APP_ROOT') || die();
@@ -39,12 +41,13 @@ final class Util
*
* @return bool|string
*/
public static function getTempDir()
public static function getTempDir(): bool|string
{
$sysTmp = sys_get_temp_dir();
$file = 'syspass.test';
$checkDir = static function ($dir) use ($file) {
$checkDir = static function ($dir) {
$file = 'syspass.test';
if (file_exists($dir.DIRECTORY_SEPARATOR.$file)) {
return $dir;
}
@@ -70,7 +73,7 @@ final class Util
*
* FIXME
*/
public static function logout(): void
#[NoReturn] public static function logout(): void
{
exit('<script>sysPassApp.actions.main.logout();</script>');
}
@@ -116,7 +119,7 @@ final class Util
* @author Samuel Levy <sam+nospam@samuellevy.com>
*
*/
public static function boolval($in, bool $strict = false): bool
public static function boolval(mixed $in, bool $strict = false): bool
{
$in = is_string($in) ? strtolower($in) : $in;
@@ -240,7 +243,7 @@ final class Util
* @return bool|string
* @throws \JsonException
*/
public static function getAppLock()
public static function getAppLock(): bool|string
{
try {
$file = new FileHandler(LOCK_FILE);
@@ -251,7 +254,7 @@ final class Util
512,
JSON_THROW_ON_ERROR
);
} catch (FileException $e) {
} catch (FileException) {
return false;
}
}

View File

@@ -49,7 +49,7 @@ final class VersionUtil
*
* @return bool True if $currentVersion is lower than $upgradeableVersion
*/
public static function checkVersion(string $currentVersion, $upgradeableVersion): bool
public static function checkVersion(string $currentVersion, array|string $upgradeableVersion): bool
{
if (is_array($upgradeableVersion)) {
$upgradeableVersion = array_pop($upgradeableVersion);
@@ -78,9 +78,11 @@ final class VersionUtil
/**
* Return a normalized version string to be compared
*
* @param string|array $versionIn
* @param array|string $versionIn
*
* @return string
*/
public static function normalizeVersionForCompare($versionIn): string
public static function normalizeVersionForCompare(array|string $versionIn): string
{
if (!empty($versionIn)) {
if (is_string($versionIn)) {
@@ -105,9 +107,11 @@ final class VersionUtil
}
/**
* @param string $version
*
* @return float|int
*/
public static function versionToInteger(string $version)
public static function versionToInteger(string $version): float|int
{
$intVersion = 0;
@@ -139,12 +143,4 @@ final class VersionUtil
return $version;
}
/**
* Devolver versión normalizada en array
*/
public static function getVersionArrayNormalized(): array
{
return [implode('', InstallerService::VERSION), InstallerService::BUILD];
}
}
}