Fix some errors from PHPStan analize
This commit is contained in:
parent
47045e1bef
commit
d5d26b74f8
@ -31,7 +31,7 @@ $_menu['Plugins']->addItem(
|
|||||||
|
|
||||||
class packmanBehaviors
|
class packmanBehaviors
|
||||||
{
|
{
|
||||||
public static function adminDashboardFavorites($core, $favs)
|
public static function adminDashboardFavorites(dcCore $core, dcFavorites $favs): void
|
||||||
{
|
{
|
||||||
$favs->register('pacKman', [
|
$favs->register('pacKman', [
|
||||||
'title' => __('Packages repository'),
|
'title' => __('Packages repository'),
|
||||||
@ -46,7 +46,7 @@ class packmanBehaviors
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function adminDashboardFavoritesActive($request, $params)
|
public static function adminDashboardFavoritesActive(string $request, array $params): bool
|
||||||
{
|
{
|
||||||
return $request == 'plugin.php'
|
return $request == 'plugin.php'
|
||||||
&& isset($params['p'])
|
&& isset($params['p'])
|
||||||
|
@ -35,10 +35,10 @@ if (!empty($_POST['save'])) {
|
|||||||
$packman_pack_nocomment = !empty($_POST['packman_pack_nocomment']);
|
$packman_pack_nocomment = !empty($_POST['packman_pack_nocomment']);
|
||||||
$packman_pack_fixnewline = !empty($_POST['packman_pack_fixnewline']);
|
$packman_pack_fixnewline = !empty($_POST['packman_pack_fixnewline']);
|
||||||
$packman_pack_overwrite = !empty($_POST['packman_pack_overwrite']);
|
$packman_pack_overwrite = !empty($_POST['packman_pack_overwrite']);
|
||||||
$packman_pack_filename = $_POST['packman_pack_filename'];
|
$packman_pack_filename = (string) $_POST['packman_pack_filename'];
|
||||||
$packman_secondpack_filename = $_POST['packman_secondpack_filename'];
|
$packman_secondpack_filename = (string) $_POST['packman_secondpack_filename'];
|
||||||
$packman_pack_repository = path::real($_POST['packman_pack_repository'], false);
|
$packman_pack_repository = (string) path::real($_POST['packman_pack_repository'], false);
|
||||||
$packman_pack_excludefiles = $_POST['packman_pack_excludefiles'];
|
$packman_pack_excludefiles = (string) $_POST['packman_pack_excludefiles'];
|
||||||
|
|
||||||
$check = libPackman::is_configured(
|
$check = libPackman::is_configured(
|
||||||
$core,
|
$core,
|
||||||
|
@ -16,6 +16,7 @@ if (!defined('DC_CONTEXT_ADMIN')) {
|
|||||||
|
|
||||||
class dcPackman
|
class dcPackman
|
||||||
{
|
{
|
||||||
|
/** @var array Excluded files */
|
||||||
public static $exclude = [
|
public static $exclude = [
|
||||||
'.',
|
'.',
|
||||||
'..',
|
'..',
|
||||||
@ -28,7 +29,7 @@ class dcPackman
|
|||||||
'Thumbs.db'
|
'Thumbs.db'
|
||||||
];
|
];
|
||||||
|
|
||||||
public static function quote_exclude($exclude)
|
public static function quote_exclude(array $exclude): array
|
||||||
{
|
{
|
||||||
foreach ($exclude as $k => $v) {
|
foreach ($exclude as $k => $v) {
|
||||||
$exclude[$k] = '#(^|/)(' . str_replace(
|
$exclude[$k] = '#(^|/)(' . str_replace(
|
||||||
@ -41,7 +42,7 @@ class dcPackman
|
|||||||
return $exclude;
|
return $exclude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPackages($core, $root)
|
public static function getPackages(dcCore $core, string $root): array
|
||||||
{
|
{
|
||||||
$res = [];
|
$res = [];
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ class dcPackman
|
|||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function pack($info, $root, $files, $overwrite = false, $exclude = [], $nocomment = false, $fixnewline = false)
|
public static function pack(array $info, string $root, array $files, bool $overwrite = false, array $exclude = [], bool $nocomment = false, bool $fixnewline = false): bool
|
||||||
{
|
{
|
||||||
if (!($info = self::getInfo($info))
|
if (!($info = self::getInfo($info))
|
||||||
|| !($root = self::getRoot($root))
|
|| !($root = self::getRoot($root))
|
||||||
@ -147,9 +148,9 @@ class dcPackman
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getRoot($root)
|
private static function getRoot(string $root): string
|
||||||
{
|
{
|
||||||
$root = path::real($root);
|
$root = (string) path::real($root);
|
||||||
if (!is_dir($root) || !is_writable($root)) {
|
if (!is_dir($root) || !is_writable($root)) {
|
||||||
throw new Exception('Directory is not writable');
|
throw new Exception('Directory is not writable');
|
||||||
}
|
}
|
||||||
@ -157,7 +158,7 @@ class dcPackman
|
|||||||
return $root;
|
return $root;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getInfo($info)
|
private static function getInfo(array $info): array
|
||||||
{
|
{
|
||||||
if (!isset($info['root'])
|
if (!isset($info['root'])
|
||||||
|| !isset($info['id'])
|
|| !isset($info['id'])
|
||||||
@ -169,14 +170,14 @@ class dcPackman
|
|||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getExclude($exclude)
|
private static function getExclude(array $exclude): array
|
||||||
{
|
{
|
||||||
$exclude = array_merge(self::$exclude, $exclude);
|
$exclude = array_merge(self::$exclude, $exclude);
|
||||||
|
|
||||||
return self::quote_exclude($exclude);
|
return self::quote_exclude($exclude);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getFile($file, $info)
|
private static function getFile(string $file, array $info): ?string
|
||||||
{
|
{
|
||||||
if (empty($file) || empty($info)) {
|
if (empty($file) || empty($info)) {
|
||||||
return null;
|
return null;
|
||||||
@ -207,7 +208,7 @@ class dcPackman
|
|||||||
return implode('/', $parts) . '.zip';
|
return implode('/', $parts) . '.zip';
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getOverwrite($overwrite, $root, $file)
|
private static function getOverwrite(bool $overwrite, string $root, string$file): ?string
|
||||||
{
|
{
|
||||||
$path = $root . '/' . $file;
|
$path = $root . '/' . $file;
|
||||||
if (file_exists($path) && !$overwrite) {
|
if (file_exists($path) && !$overwrite) {
|
||||||
@ -219,7 +220,7 @@ class dcPackman
|
|||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getCache()
|
private static function getCache(): string
|
||||||
{
|
{
|
||||||
$c = DC_TPL_CACHE . '/packman';
|
$c = DC_TPL_CACHE . '/packman';
|
||||||
if (!file_exists($c)) {
|
if (!file_exists($c)) {
|
||||||
|
@ -12,9 +12,22 @@
|
|||||||
*/
|
*/
|
||||||
class packmanFileZip extends fileZip
|
class packmanFileZip extends fileZip
|
||||||
{
|
{
|
||||||
|
/** @var boolean Remove comments from files content */
|
||||||
public static $remove_comment = false;
|
public static $remove_comment = false;
|
||||||
public static $fix_newline = false;
|
|
||||||
|
|
||||||
|
/** @var boolean Fix newline from files content */
|
||||||
|
public static $fix_newline = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace clearbricks fileZip::writeFile
|
||||||
|
*
|
||||||
|
* @param string $name Name
|
||||||
|
* @param string $file File
|
||||||
|
* @param int $size Size
|
||||||
|
* @param int $mtime Mtime
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
protected function writeFile($name, $file, $size, $mtime)
|
protected function writeFile($name, $file, $size, $mtime)
|
||||||
{
|
{
|
||||||
if (!isset($this->entries[$name])) {
|
if (!isset($this->entries[$name])) {
|
||||||
@ -24,7 +37,7 @@ class packmanFileZip extends fileZip
|
|||||||
$size = filesize($file);
|
$size = filesize($file);
|
||||||
$this->memoryAllocate($size * 3);
|
$this->memoryAllocate($size * 3);
|
||||||
|
|
||||||
$content = file_get_contents($file);
|
$content = (string) file_get_contents($file);
|
||||||
|
|
||||||
//cleanup file contents
|
//cleanup file contents
|
||||||
// at this time only php files
|
// at this time only php files
|
||||||
@ -37,7 +50,7 @@ class packmanFileZip extends fileZip
|
|||||||
|
|
||||||
$unc_len = strlen($content);
|
$unc_len = strlen($content);
|
||||||
$crc = crc32($content);
|
$crc = crc32($content);
|
||||||
$zdata = gzdeflate($content);
|
$zdata = (string) gzdeflate($content);
|
||||||
$c_len = strlen($zdata);
|
$c_len = strlen($zdata);
|
||||||
|
|
||||||
unset($content);
|
unset($content);
|
||||||
@ -92,7 +105,7 @@ class packmanFileZip extends fileZip
|
|||||||
$this->ctrl_dir[] = $cdrec;
|
$this->ctrl_dir[] = $cdrec;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function removePHPComment($content)
|
protected static function removePHPComment(string $content): string
|
||||||
{
|
{
|
||||||
$comment = [T_COMMENT];
|
$comment = [T_COMMENT];
|
||||||
if (defined('T_DOC_COMMENT')) {
|
if (defined('T_DOC_COMMENT')) {
|
||||||
@ -120,7 +133,7 @@ class packmanFileZip extends fileZip
|
|||||||
return $newStr;
|
return $newStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function fixNewline($content)
|
protected static function fixNewline(string $content): string
|
||||||
{
|
{
|
||||||
return str_replace("\r\n", "\n", $content);
|
return str_replace("\r\n", "\n", $content);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ if (!defined('DC_CONTEXT_ADMIN')) {
|
|||||||
|
|
||||||
class libPackman
|
class libPackman
|
||||||
{
|
{
|
||||||
public static function is_configured($core, $repo, $file_a, $file_b)
|
public static function is_configured(dcCore $core, string $repo, string $file_a, string $file_b): bool
|
||||||
{
|
{
|
||||||
if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
|
if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
|
||||||
$core->error->add(
|
$core->error->add(
|
||||||
@ -50,14 +50,14 @@ class libPackman
|
|||||||
return !$core->error->flag();
|
return !$core->error->flag();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function is_writable($path, $file)
|
public static function is_writable(string $path, string $file): bool
|
||||||
{
|
{
|
||||||
return !(empty($path) || empty($file) || !is_writable(dirname($path . '/' . $file)));
|
return !(empty($path) || empty($file) || !is_writable(dirname($path . '/' . $file)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function modules($core, $modules, $type, $title)
|
public static function modules(dcCore $core, array $modules, string $type, string $title): ?bool
|
||||||
{
|
{
|
||||||
if (empty($modules) && !is_array($modules)) {
|
if (empty($modules) || !is_array($modules)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ class libPackman
|
|||||||
__(html::escapeHTML($module['name'])) .
|
__(html::escapeHTML($module['name'])) .
|
||||||
'</td>' .
|
'</td>' .
|
||||||
'<td class="nowrap">' .
|
'<td class="nowrap">' .
|
||||||
dirname(path::real($module['root'], false)) .
|
dirname((string) path::real($module['root'], false)) .
|
||||||
'</td>' .
|
'</td>' .
|
||||||
'</tr>';
|
'</tr>';
|
||||||
}
|
}
|
||||||
@ -114,9 +114,11 @@ class libPackman
|
|||||||
'</form>' .
|
'</form>' .
|
||||||
|
|
||||||
'</div>';
|
'</div>';
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function repository($core, $modules, $type, $title)
|
public static function repository(dcCore $core, array $modules, string $type, string $title): ?bool
|
||||||
{
|
{
|
||||||
if (empty($modules) || !is_array($modules)) {
|
if (empty($modules) || !is_array($modules)) {
|
||||||
return null;
|
return null;
|
||||||
@ -201,9 +203,11 @@ class libPackman
|
|||||||
'</div>' .
|
'</div>' .
|
||||||
'</form>' .
|
'</form>' .
|
||||||
'</div>';
|
'</div>';
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function sort($modules)
|
protected static function sort(array $modules): array
|
||||||
{
|
{
|
||||||
$key = $ver = [];
|
$key = $ver = [];
|
||||||
foreach ($modules as $i => $module) {
|
foreach ($modules as $i => $module) {
|
||||||
|
@ -35,7 +35,7 @@ $plugins = $core->plugins;
|
|||||||
# Paths
|
# Paths
|
||||||
$ppexp = explode(PATH_SEPARATOR, DC_PLUGINS_ROOT);
|
$ppexp = explode(PATH_SEPARATOR, DC_PLUGINS_ROOT);
|
||||||
$pppop = array_pop($ppexp);
|
$pppop = array_pop($ppexp);
|
||||||
$plugins_path = path::real($pppop);
|
$plugins_path = (string) path::real($pppop);
|
||||||
$themes_path = $core->blog->themes_path;
|
$themes_path = $core->blog->themes_path;
|
||||||
$repo_path = $s->packman_pack_repository;
|
$repo_path = $s->packman_pack_repository;
|
||||||
|
|
||||||
@ -188,12 +188,11 @@ try {
|
|||||||
|
|
||||||
# Copy
|
# Copy
|
||||||
} elseif (strpos($action, 'copy_to_') !== false) {
|
} elseif (strpos($action, 'copy_to_') !== false) {
|
||||||
|
$dest = $repo_path;
|
||||||
if ($action == 'copy_to_plugins') {
|
if ($action == 'copy_to_plugins') {
|
||||||
$dest = $plugins_path;
|
$dest = $plugins_path;
|
||||||
} elseif ($action == 'copy_to_themes') {
|
} elseif ($action == 'copy_to_themes') {
|
||||||
$dest = $themes_path;
|
$dest = $themes_path;
|
||||||
} elseif ($action == 'copy_to_repository') {
|
|
||||||
$dest = $repo_path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($_POST['modules'] as $root => $id) {
|
foreach ($_POST['modules'] as $root => $id) {
|
||||||
@ -215,12 +214,11 @@ try {
|
|||||||
|
|
||||||
# Move
|
# Move
|
||||||
} elseif (strpos($action, 'move_to_') !== false) {
|
} elseif (strpos($action, 'move_to_') !== false) {
|
||||||
|
$dest = $repo_path;
|
||||||
if ($action == 'move_to_plugins') {
|
if ($action == 'move_to_plugins') {
|
||||||
$dest = $plugins_path;
|
$dest = $plugins_path;
|
||||||
} elseif ($action == 'move_to_themes') {
|
} elseif ($action == 'move_to_themes') {
|
||||||
$dest = $themes_path;
|
$dest = $themes_path;
|
||||||
} elseif ($action == 'move_to_repository') {
|
|
||||||
$dest = $repo_path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($_POST['modules'] as $root => $id) {
|
foreach ($_POST['modules'] as $root => $id) {
|
||||||
|
Loading…
Reference in New Issue
Block a user