mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-23 06:48:41 +00:00
Code optimizations
This commit is contained in:
parent
3442d1d817
commit
e85164c986
|
|
@ -560,7 +560,7 @@ class Account implements ArrayableInterface, \JsonSerializable
|
|||
*/
|
||||
public function generatePassword(string $password) /* : void */
|
||||
{
|
||||
$this->password = password_hash($password, PASSWORD_DEFAULT);
|
||||
$this->password = \password_hash($password, \PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -60,32 +60,11 @@ class MysqlConnection extends ConnectionAbstract
|
|||
{
|
||||
$this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata;
|
||||
|
||||
if (!isset($this->dbdata['db'])) {
|
||||
throw new InvalidConnectionConfigException('db');
|
||||
}
|
||||
|
||||
if (!isset($this->dbdata['host'])) {
|
||||
throw new InvalidConnectionConfigException('host');
|
||||
}
|
||||
|
||||
if (!isset($this->dbdata['port'])) {
|
||||
throw new InvalidConnectionConfigException('port');
|
||||
}
|
||||
|
||||
if (!isset($this->dbdata['database'])) {
|
||||
throw new InvalidConnectionConfigException('database');
|
||||
}
|
||||
|
||||
if (!isset($this->dbdata['login'])) {
|
||||
throw new InvalidConnectionConfigException('login');
|
||||
}
|
||||
|
||||
if (!isset($this->dbdata['password'])) {
|
||||
throw new InvalidConnectionConfigException('password');
|
||||
if (!isset($this->dbdata['db'], $this->dbdata['host'], $this->dbdata['port'], $this->dbdata['database'], $this->dbdata['login'], $this->dbdata['password'])) {
|
||||
throw new InvalidConnectionConfigException(json_encode($this->dbdata));
|
||||
}
|
||||
|
||||
$this->close();
|
||||
|
||||
$this->prefix = $dbdata['prefix'] ?? '';
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
/**
|
||||
* Highest mapper to know when to clear initialized objects
|
||||
*
|
||||
* @var DataMapperAbstract
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static $parentMapper = null;
|
||||
|
|
|
|||
|
|
@ -133,7 +133,6 @@ class Grammar extends GrammarAbstract
|
|||
break;
|
||||
case QueryType::RAW:
|
||||
return [$query->raw];
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Unknown query type.');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@ abstract class RequestAbstract implements MessageInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract function getOrigin() : string;
|
||||
abstract public function getOrigin() : string;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
|||
|
|
@ -156,27 +156,23 @@ class Directory extends FileAbstract implements DirectoryInterface
|
|||
*/
|
||||
public static function size(string $dir, bool $recursive = true) : int
|
||||
{
|
||||
if (!file_exists($dir)) {
|
||||
if (!file_exists($dir) || !is_readable($dir)) {
|
||||
throw new PathException($dir);
|
||||
}
|
||||
|
||||
$countSize = 0;
|
||||
$count = 0;
|
||||
$dir_array = scandir($dir);
|
||||
|
||||
if (is_readable($dir)) {
|
||||
$dir_array = scandir($dir);
|
||||
foreach ($dir_array as $key => $filename) {
|
||||
if ($filename === ".." || $filename === ".") {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($dir_array as $key => $filename) {
|
||||
if ($filename != ".." && $filename != ".") {
|
||||
if (is_dir($dir . "/" . $filename) && $recursive) {
|
||||
$countSize += self::size($dir . "/" . $filename, $recursive);
|
||||
} else {
|
||||
if (is_file($dir . "/" . $filename)) {
|
||||
$countSize += filesize($dir . "/" . $filename);
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
$path = $dir . "/" . $filename;
|
||||
if (is_dir($path) && $recursive) {
|
||||
$countSize += self::size($path, $recursive);
|
||||
} elseif (is_file($path)) {
|
||||
$countSize += filesize($path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -312,14 +308,12 @@ class Directory extends FileAbstract implements DirectoryInterface
|
|||
throw new PathException($from);
|
||||
}
|
||||
|
||||
if (!$overwrite && file_exists($to)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!file_exists($to)) {
|
||||
self::create($to, 0644, true);
|
||||
} elseif ($overwrite && file_exists($to)) {
|
||||
self::delete($to);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($iterator = new \RecursiveIteratorIterator(
|
||||
|
|
|
|||
|
|
@ -72,120 +72,120 @@ abstract class StorageAbstract
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function created(string $path) : \DateTime;
|
||||
abstract public static function created(string $path) : \DateTime;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function changed(string $path) : \DateTime;
|
||||
abstract public static function changed(string $path) : \DateTime;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function owner(string $path) : int;
|
||||
abstract public static function owner(string $path) : int;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function permission(string $path) : int;
|
||||
abstract public static function permission(string $path) : int;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function parent(string $path) : string;
|
||||
abstract public static function parent(string $path) : string;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function create(string $path) : bool;
|
||||
abstract public static function create(string $path) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function delete(string $path) : bool;
|
||||
abstract public static function delete(string $path) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function copy(string $from, string $to, bool $overwrite = false) : bool;
|
||||
abstract public static function copy(string $from, string $to, bool $overwrite = false) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function move(string $from, string $to, bool $overwrite = false) : bool;
|
||||
abstract public static function move(string $from, string $to, bool $overwrite = false) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function size(string $path, bool $recursive = true) : int;
|
||||
abstract public static function size(string $path, bool $recursive = true) : int;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function exists(string $path) : bool;
|
||||
abstract public static function exists(string $path) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function name(string $path) : string;
|
||||
abstract public static function name(string $path) : string;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function basename(string $path) : string;
|
||||
abstract public static function basename(string $path) : string;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function dirname(string $path) : string;
|
||||
abstract public static function dirname(string $path) : string;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function dirpath(string $path) : string;
|
||||
abstract public static function dirpath(string $path) : string;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function list(string $path, string $filter = '*') : array;
|
||||
abstract public static function list(string $path, string $filter = '*') : array;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function count(string $path, bool $recursive = true, array $ignore = []) : int;
|
||||
abstract public static function count(string $path, bool $recursive = true, array $ignore = []) : int;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function put(string $path, string $content, int $mode = 0) : bool;
|
||||
abstract public static function put(string $path, string $content, int $mode = 0) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function get(string $path) : string;
|
||||
abstract public static function get(string $path) : string;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function sanitize(string $path, string $replace = '') : string;
|
||||
abstract public static function sanitize(string $path, string $replace = '') : string;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function set(string $path, string $content) : bool;
|
||||
abstract public static function set(string $path, string $content) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function append(string $path, string $content) : bool;
|
||||
abstract public static function append(string $path, string $content) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function prepend(string $path, string $content) : bool;
|
||||
abstract public static function prepend(string $path, string $content) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function extension(string $path) : string;
|
||||
abstract public static function extension(string $path) : string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,16 +97,14 @@ class ArrayUtils
|
|||
|
||||
if ($overwrite) {
|
||||
$current = $value;
|
||||
} elseif (is_array($current) && !is_array($value)) {
|
||||
$current[] = $value;
|
||||
} elseif (is_array($current) && is_array($value)) {
|
||||
$current += $value;
|
||||
} elseif (is_scalar($current) && $current !== null) {
|
||||
$current = [$current, $value];
|
||||
} else {
|
||||
if (is_array($current) && !is_array($value)) {
|
||||
$current[] = $value;
|
||||
} elseif (is_array($current) && is_array($value)) {
|
||||
$current += $value;
|
||||
} elseif (is_scalar($current) && $current !== null) {
|
||||
$current = [$current, $value];
|
||||
} else {
|
||||
$current = $value;
|
||||
}
|
||||
$current = $value;
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
|
@ -156,7 +154,7 @@ class ArrayUtils
|
|||
$found = self::inArrayRecursive($needle, $item);
|
||||
|
||||
if ($found) {
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user