Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 2c6b444

Browse files
committed
Code Inspection
1 parent 6b7566e commit 2c6b444

25 files changed

+153
-104
lines changed

core/src/core/classes/class.AJXP_Cache.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
*/
2828
class AJXP_Cache
2929
{
30-
private static $instance;
31-
3230
protected $cacheDir;
3331
protected $cacheId;
3432
protected $masterFile;
@@ -39,7 +37,7 @@ class AJXP_Cache
3937
* Create an AJXP_Cache instance
4038
* @param string $pluginId
4139
* @param string $filepath
42-
* @param Function $dataCallback A function to generate the data cache. If no callback provided, will simply use the content of the master item as the cache data
40+
* @param callable $dataCallback A function to generate the data cache. If no callback provided, will simply use the content of the master item as the cache data
4341
* @param string $idComputerCallback A function to generate the ID of the cache. If not provided, will generate a random hash
4442
* @return AJXP_Cache
4543
*/

core/src/core/classes/class.AJXP_Controller.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ public static function runCommandInBackground($cmd, $logFile)
344344
file_put_contents($tmpBat, $cmd);
345345
pclose(popen('start /b "CLI" "'.$tmpBat.'"', 'r'));
346346
}
347+
return null;
347348
} else {
348349
$process = new UnixProcess($cmd, (AJXP_SERVER_DEBUG?$logFile:null));
349350
AJXP_Logger::debug("Starting process and sending output dev null");
@@ -361,7 +362,7 @@ public static function runCommandInBackground($cmd, $logFile)
361362
* @param array $httpVars
362363
* @param array $fileVars
363364
* @param bool $multiple
364-
* @return DOMElement|bool
365+
* @return DOMElement|bool|DOMElement[]
365366
*/
366367
private static function getCallbackNode($xPath, $actionNode, $query ,$actionName, $httpVars, $fileVars, $multiple = true)
367368
{
@@ -387,7 +388,7 @@ private static function getCallbackNode($xPath, $actionNode, $query ,$actionName
387388
* Check in the callback node if an applyCondition XML attribute exists, and eval its content.
388389
* The content must set an $apply boolean as result
389390
* @static
390-
* @param DOMElement $callback
391+
* @param DOMElement|DOMNode $callback
391392
* @param string $actionName
392393
* @param array $httpVars
393394
* @param array $fileVars
@@ -441,6 +442,7 @@ private static function applyCallback($callback, &$actionName, &$httpVars, &$fil
441442
} else {
442443
throw new AJXP_Exception("Cannot find method $methodName for plugin $plugId!");
443444
}
445+
return null;
444446
}
445447

446448
/**
@@ -471,6 +473,9 @@ public static function applyHook($hookName, $args, $forceNonDefer = false)
471473
$callbacks = $xPath->query("hooks/serverCallback[@hookName='$hookName']");
472474
if(!$callbacks->length) return ;
473475
self::$hooksCache[$hookName] = array();
476+
/**
477+
* @var $callback DOMElement
478+
*/
474479
foreach ($callbacks as $callback) {
475480
$defer = ($callback->getAttribute("defer") === "true");
476481
$applyCondition = $callback->getAttribute("applyCondition");

core/src/core/classes/class.AJXP_JSPacker.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ class AJXP_JSPacker
3131
* Static function for packing all js and css into big files
3232
* Auto detect /js/*_list.txt files and /css/*_list.txt files and pack them.
3333
*/
34-
public function pack()
34+
public static function pack()
3535
{
3636
// Make sure that the gui.* plugin is loaded
37-
$plug = AJXP_PluginsService::getInstance()->getPluginsByType("gui");
37+
AJXP_PluginsService::getInstance()->getPluginsByType("gui");
3838

3939
$sList = glob(CLIENT_RESOURCES_FOLDER."/js/*_list.txt");
4040
foreach ($sList as $list) {

core/src/core/classes/class.AJXP_Node.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ public function __get($varName)
533533
* Magic setter for metadata
534534
* @param $metaName
535535
* @param $metaValue
536-
* @return
536+
* @return void
537537
*/
538538
public function __set($metaName, $metaValue)
539539
{

core/src/core/classes/class.AJXP_Plugin.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public function isEnabled()
210210

211211
/**
212212
* Main function for loading all the nodes under registry_contributions.
213-
* @return void
213+
* @param bool $dry
214214
*/
215215
protected function loadRegistryContributions($dry = false)
216216
{
@@ -265,7 +265,7 @@ protected function loadRegistryContributions($dry = false)
265265
* @param string $xmlFile Path to the file from the base install path
266266
* @param array $include XPath query for XML Nodes to include
267267
* @param array $exclude XPath query for XML Nodes to exclude from the included ones.
268-
* @return
268+
* @param bool $dry Dry-run of the inclusion
269269
*/
270270
protected function initXmlContributionFile($xmlFile, $include=array("*"), $exclude=array(), $dry = false)
271271
{
@@ -310,6 +310,7 @@ protected function initXmlContributionFile($xmlFile, $include=array("*"), $exclu
310310
}
311311
if(!count($selected)) return;
312312
$originalRegContrib = $this->xPath->query("registry_contributions")->item(0);
313+
$localRegParent = null;
313314
foreach ($selected as $parentNodeName => $data) {
314315
$node = $data["parent"]->cloneNode(false);
315316
//$newNode = $originalRegContrib->ownerDocument->importNode($node, false);

core/src/core/classes/class.AJXP_PluginsService.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ public function softLoad($pluginId, $pluginOptions)
216216
// Try to get from cache
217217
list($type, $name) = explode(".", $pluginId);
218218
if(!empty($this->registry) && isSet($this->registry[$type][$name])) {
219+
/**
220+
* @var AJXP_Plugin $plugin
221+
*/
219222
$plugin = $this->registry[$type][$name];
220223
$plugin->init($pluginOptions);
221224
return clone $plugin;
@@ -243,6 +246,9 @@ private function instanciatePluginClass($plugin)
243246
$filename = AJXP_INSTALL_PATH."/".$definition["filename"];
244247
$className = $definition["classname"];
245248
if (is_file($filename)) {
249+
/**
250+
* @var AJXP_Plugin $newPlugin
251+
*/
246252
require_once($filename);
247253
$newPlugin = new $className($plugin->getId(), $plugin->getBaseDir());
248254
$newPlugin->loadManifest();
@@ -252,10 +258,10 @@ private function instanciatePluginClass($plugin)
252258
return $plugin;
253259
}
254260
}
261+
255262
/**
256263
* Check that a plugin dependencies are loaded, disable it otherwise.
257-
* @param $arrayToSort
258-
* @return
264+
* @param AJXP_Plugin[] $arrayToSort
259265
*/
260266
private function checkDependencies(&$arrayToSort)
261267
{
@@ -306,7 +312,6 @@ public static function sortByDependencyIds($pluginIdA, $pluginIdB)
306312

307313
public function getOrderByDependency($plugins, $withStatus = true)
308314
{
309-
$orders = array();
310315
$keys = array();
311316
$unkowns = array();
312317
if ($withStatus) {
@@ -397,6 +402,9 @@ public function removePluginById($pluginId)
397402
*/
398403
public function initActivePlugins()
399404
{
405+
/**
406+
* @var AJXP_Plugin $pObject
407+
*/
400408
$detected = $this->getDetectedPlugins();
401409
$toActivate = array();
402410
foreach ($detected as $pType => $pObjects) {
@@ -631,11 +639,12 @@ public static function getXmlRegistry($extendedVersion = true)
631639
}
632640
return $self->xmlRegistry;
633641
}
642+
634643
/**
635644
* Replace the current xml registry
636645
* @static
637646
* @param $registry
638-
* @return void
647+
* @param bool $extendedVersion
639648
*/
640649
public static function updateXmlRegistry($registry, $extendedVersion = true)
641650
{
@@ -677,6 +686,8 @@ public function patchPluginWithMixin(&$plugin, &$manifestDoc, $mixinName)
677686
* @param string $query
678687
* @param string $stringOrNodeFormat
679688
* @param boolean $limitToActivePlugins Whether to search only in active plugins or in all plugins
689+
* @param bool $limitToEnabledPlugins
690+
* @param bool $loadExternalFiles
680691
* @return DOMNode[]
681692
*/
682693
public static function searchAllManifests($query, $stringOrNodeFormat = "string", $limitToActivePlugins = false, $limitToEnabledPlugins = false, $loadExternalFiles = false)
@@ -756,11 +767,11 @@ protected function mergeNodes(&$original, $parentName, $uuidAttr, $childrenNodes
756767
}
757768
}
758769
}
770+
759771
/**
760772
* Utilitary function
761773
* @param $new
762774
* @param $old
763-
* @return
764775
*/
765776
protected function mergeChildByTagName($new, &$old)
766777
{

core/src/core/classes/class.AJXP_ProgressBarCLI.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public function ago($time) {
154154
$remain=$remain%3600;
155155
$mins=intval($remain/60);
156156
$secs=$remain%60;
157+
$timestring = "-";
157158

158159
if ($secs>=0) $timestring = "0m".$secs."s";
159160
if ($mins>0) $timestring = $mins."m".$secs."s";

core/src/core/classes/class.AJXP_Role.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ public function array_merge_recursive2($array1, $array2)
491491
if (!is_array($arrays[$i])) {
492492
// also array_merge_recursive returns nothing in this case
493493
trigger_error('Argument #' . ($i+1) . ' is not an array - trying to merge array with scalar! Returning null!', E_USER_WARNING);
494-
return;
494+
return null;
495495
}
496496
}
497497

core/src/core/classes/class.AJXP_Utils.php

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static function natksort(&$array)
7777
*/
7878
public static function natkrsort(&$array)
7979
{
80-
natksort($array);
80+
AJXP_Utils::natksort($array);
8181
$array = array_reverse($array, TRUE);
8282
return true;
8383
}
@@ -610,6 +610,7 @@ public static function getImageMimeType($fileName)
610610
} else if (preg_match("/\.gif$/i", $fileName)) {
611611
return "image/gif";
612612
}
613+
return "";
613614
}
614615
/**
615616
* Headers to send when streaming
@@ -1047,7 +1048,9 @@ public function prettyPrintJSON($json)
10471048
public static function extractConfStringsFromManifests()
10481049
{
10491050
$plugins = AJXP_PluginsService::getInstance()->getDetectedPlugins();
1050-
$plug = new AJXP_Plugin("", "");
1051+
/**
1052+
* @var AJXP_Plugin $plug
1053+
*/
10511054
foreach ($plugins as $pType => $plugs) {
10521055
foreach ($plugs as $plug) {
10531056
$lib = $plug->getManifestRawContent("//i18n", "nodes");
@@ -1110,7 +1113,6 @@ public static function updateAllI18nLibraries($createLanguage = "")
11101113
* @param $baseDir
11111114
* @param bool $detectLanguages
11121115
* @param string $createLanguage
1113-
* @return
11141116
*/
11151117
public static function updateI18nFiles($baseDir, $detectLanguages = true, $createLanguage = "")
11161118
{
@@ -1128,6 +1130,7 @@ public static function updateI18nFiles($baseDir, $detectLanguages = true, $creat
11281130
$filenames = glob($baseDir . "/*.php");
11291131
}
11301132

1133+
$mess = array();
11311134
include($baseDir . "/en.php");
11321135
$reference = $mess;
11331136

@@ -1141,11 +1144,11 @@ public static function updateI18nFiles($baseDir, $detectLanguages = true, $creat
11411144
* @static
11421145
* @param $filename
11431146
* @param $reference
1144-
* @return
11451147
*/
11461148
public static function updateI18nFromRef($filename, $reference)
11471149
{
11481150
if (!is_file($filename)) return;
1151+
$mess = array();
11491152
include($filename);
11501153
$missing = array();
11511154
foreach ($reference as $messKey => $message) {
@@ -1253,6 +1256,7 @@ public static function runTests(&$outputArray, &$testedParams)
12531256
}
12541257
// PREPARE REPOSITORY LISTS
12551258
$repoList = array();
1259+
$REPOSITORIES = array();
12561260
require_once("../classes/class.ConfService.php");
12571261
require_once("../classes/class.Repository.php");
12581262
include(AJXP_CONF_PATH . "/bootstrap_repositories.php");
@@ -1330,6 +1334,7 @@ public static function isStream($path)
13301334
*
13311335
* @param String $filePath Full path to the file
13321336
* @param Boolean $skipCheck do not test for file existence before opening
1337+
* @param string $format
13331338
* @return Array
13341339
*/
13351340
public static function loadSerialFile($filePath, $skipCheck = false, $format="ser")
@@ -1359,11 +1364,15 @@ public static function loadSerialFile($filePath, $skipCheck = false, $format="se
13591364
* @param Array|Object $value The value to store
13601365
* @param Boolean $createDir Whether to create the parent folder or not, if it does not exist.
13611366
* @param bool $silent Silently write the file, are throw an exception on problem.
1362-
* @param string $format
1367+
* @param string $format "ser" or "json"
1368+
* @param bool $jsonPrettyPrint If json, use pretty printing
13631369
* @throws Exception
13641370
*/
13651371
public static function saveSerialFile($filePath, $value, $createDir = true, $silent = false, $format="ser", $jsonPrettyPrint = false)
13661372
{
1373+
if(!in_array($format, array("ser", "json"))){
1374+
throw new Exception("Unsupported serialization format: ".$format);
1375+
}
13671376
$filePath = AJXP_VarsFilter::filter($filePath);
13681377
if ($createDir && !is_dir(dirname($filePath))) {
13691378
@mkdir(dirname($filePath), 0755, true);
@@ -1375,8 +1384,9 @@ public static function saveSerialFile($filePath, $value, $createDir = true, $sil
13751384
}
13761385
try {
13771386
$fp = fopen($filePath, "w");
1378-
if($format == "ser") $content = serialize($value);
1379-
else if ($format == "json") {
1387+
if($format == "ser") {
1388+
$content = serialize($value);
1389+
} else {
13801390
$content = json_encode($value);
13811391
if($jsonPrettyPrint) $content = self::prettyPrintJSON($content);
13821392
}
@@ -1395,8 +1405,6 @@ public static function saveSerialFile($filePath, $value, $createDir = true, $sil
13951405
*/
13961406
public static function userAgentIsMobile()
13971407
{
1398-
$isMobile = false;
1399-
14001408
$op = strtolower($_SERVER['HTTP_X_OPERAMINI_PHONE'] OR "");
14011409
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
14021410
$ac = strtolower($_SERVER['HTTP_ACCEPT']);
@@ -1445,34 +1453,6 @@ public static function userAgentIsMobile()
14451453
|| strpos($ua, 'vodafone/') !== false
14461454
|| strpos($ua, 'wap1.') !== false
14471455
|| strpos($ua, 'wap2.') !== false;
1448-
/*
1449-
$isBot = false;
1450-
$ip = $_SERVER['REMOTE_ADDR'];
1451-
1452-
$isBot = $ip == '66.249.65.39'
1453-
|| strpos($ua, 'googlebot') !== false
1454-
|| strpos($ua, 'mediapartners') !== false
1455-
|| strpos($ua, 'yahooysmcm') !== false
1456-
|| strpos($ua, 'baiduspider') !== false
1457-
|| strpos($ua, 'msnbot') !== false
1458-
|| strpos($ua, 'slurp') !== false
1459-
|| strpos($ua, 'ask') !== false
1460-
|| strpos($ua, 'teoma') !== false
1461-
|| strpos($ua, 'spider') !== false
1462-
|| strpos($ua, 'heritrix') !== false
1463-
|| strpos($ua, 'attentio') !== false
1464-
|| strpos($ua, 'twiceler') !== false
1465-
|| strpos($ua, 'irlbot') !== false
1466-
|| strpos($ua, 'fast crawler') !== false
1467-
|| strpos($ua, 'fastmobilecrawl') !== false
1468-
|| strpos($ua, 'jumpbot') !== false
1469-
|| strpos($ua, 'googlebot-mobile') !== false
1470-
|| strpos($ua, 'yahooseeker') !== false
1471-
|| strpos($ua, 'motionbot') !== false
1472-
|| strpos($ua, 'mediobot') !== false
1473-
|| strpos($ua, 'chtml generic') !== false
1474-
|| strpos($ua, 'nokia6230i/. fast crawler') !== false;
1475-
*/
14761456
return $isMobile;
14771457
}
14781458
/**
@@ -1756,6 +1736,7 @@ public static function parseStandardFormParameters(&$repDef, &$options, $userId
17561736
}
17571737
// DO SOMETHING WITH REPLICATED PARAMETERS?
17581738
if (count($switchesGroups)) {
1739+
$gValues = array();
17591740
foreach ($switchesGroups as $fieldName => $groupName) {
17601741
if (isSet($options[$fieldName])) {
17611742
$gValues = array();
@@ -2082,11 +2063,11 @@ public static function regexpToLdap($regexp)
20822063
}
20832064
return $left.$regexp.$right;
20842065
}
2066+
20852067
/**
20862068
* Hide file or folder for Windows OS
20872069
* @static
2088-
* @param $path
2089-
* @return void
2070+
* @param $file
20902071
*/
20912072
public static function winSetHidden($file)
20922073
{

0 commit comments

Comments
 (0)