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