Fix phpcs

This commit is contained in:
Laurent Destailleur
2023-12-04 10:22:29 +01:00
parent 697c8d14b7
commit b282251fbc
3 changed files with 70 additions and 60 deletions

View File

@@ -34,7 +34,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
exit();
}
error_reporting(E_ALL & ~ E_DEPRECATED);
error_reporting(E_ALL & ~E_DEPRECATED);
define('PRODUCT', "apstats");
define('VERSION', "1.0");
@@ -51,7 +51,7 @@ $outputpath = $argv[1];
$outputdir = dirname($outputpath);
$outputfile = basename($outputpath);
if (! is_dir($outputdir)) {
if (!is_dir($outputdir)) {
print 'Error: dir '.$outputdir.' does not exists or is not writable'."\n";
exit(1);
}
@@ -111,8 +111,8 @@ exec($commandcheck, $output_arrtd, $resexectd);
$arrayoflineofcode = array();
$arraycocomo = array();
$arrayofmetrics = array(
'proj'=>array('Bytes'=>0, 'Files'=>0, 'Lines'=>0, 'Blanks'=>0, 'Comments'=>0, 'Code'=>0, 'Complexity'=>0),
'dep'=>array('Bytes'=>0, 'Files'=>0, 'Lines'=>0, 'Blanks'=>0, 'Comments'=>0, 'Code'=>0, 'Complexity'=>0)
'proj' => array('Bytes' => 0, 'Files' => 0, 'Lines' => 0, 'Blanks' => 0, 'Comments' => 0, 'Code' => 0, 'Complexity' => 0),
'dep' => array('Bytes' => 0, 'Files' => 0, 'Lines' => 0, 'Blanks' => 0, 'Comments' => 0, 'Code' => 0, 'Complexity' => 0)
);
// Analyse $output_arrproj

View File

@@ -37,14 +37,14 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
exit();
}
error_reporting(E_ALL & ~ E_DEPRECATED);
error_reporting(E_ALL & ~E_DEPRECATED);
define('PRODUCT', "pg2mysql");
define('VERSION', "2.0");
// this is the default, it can be overridden here, or specified as the third parameter on the command line
$config['engine'] = "InnoDB";
if (! ($argv[1] && $argv[2])) {
if (!($argv[1] && $argv[2])) {
echo "Usage: php pg2mysql_cli.php <inputfilename> <outputfilename> [engine]\n";
exit();
} else {
@@ -141,7 +141,7 @@ function pg2mysql_large($infilename, $outfilename)
echo "Filesize: " . formatsize($fs) . "\n";
while ($instr = fgets($infp)) {
$linenum ++;
$linenum++;
$memusage = round(memory_get_usage(true) / 1024 / 1024);
$len = strlen($instr);
$pgsqlchunk[] = $instr;
@@ -163,7 +163,7 @@ function pg2mysql_large($infilename, $outfilename)
}
if (strlen($instr) > 3 && ($instr[$len - 3] == ")" && $instr[$len - 2] == ";" && $instr[$len - 1] == "\n") && $inquotes == false) {
$chunkcount ++;
$chunkcount++;
if ($linenum % 10000 == 0) {
$currentpos = ftell($infp);
@@ -302,7 +302,7 @@ function pg2mysql(&$input, &$arrayofprimaryalreadyintabledef, $header = true)
$output .= 'DROP TABLE IF EXISTS `' . $reg2[1] . '`;' . "\n";
}
$output .= $line;
$linenumber ++;
$linenumber++;
continue;
}
@@ -313,7 +313,7 @@ function pg2mysql(&$input, &$arrayofprimaryalreadyintabledef, $header = true)
$output .= $tbl_extra;
$output .= $line;
$linenumber ++;
$linenumber++;
$tbl_extra = "";
continue;
}
@@ -395,10 +395,10 @@ function pg2mysql(&$input, &$arrayofprimaryalreadyintabledef, $header = true)
if (strstr($line, " CONSTRAINT ")) {
$line = "";
// and if the previous output ended with a , remove the ,
$lastchr = substr($output, - 2, 1);
$lastchr = substr($output, -2, 1);
// echo "lastchr=$lastchr";
if ($lastchr == ",") {
$output = substr($output, 0, - 2) . "\n";
$output = substr($output, 0, -2) . "\n";
}
}
@@ -408,9 +408,9 @@ function pg2mysql(&$input, &$arrayofprimaryalreadyintabledef, $header = true)
if (substr($line, 0, 11) == "INSERT INTO") {
$line = str_replace('public.', '', $line);
if (substr($line, - 3, - 1) == ");") {
if (substr($line, -3, -1) == ");") {
// we have a complete insert on one line
list ($before, $after) = explode(" VALUES ", $line, 2);
list($before, $after) = explode(" VALUES ", $line, 2);
// we only replace the " with ` in what comes BEFORE the VALUES
// (ie, field names, like INSERT INTO table ("bla","bla2") VALUES ('s:4:"test"','bladata2');
// should convert to INSERT INTO table (`bla`,`bla2`) VALUES ('s:4:"test"','bladata2');
@@ -424,13 +424,13 @@ function pg2mysql(&$input, &$arrayofprimaryalreadyintabledef, $header = true)
$after = str_replace(", E'", ", '", $after);
$output .= $before . " VALUES " . $after;
$linenumber ++;
$linenumber++;
continue;
} else {
// this insert spans multiple lines, so keep dumping the lines until we reach a line
// that ends with ");"
list ($before, $after) = explode(" VALUES ", $line, 2);
list($before, $after) = explode(" VALUES ", $line, 2);
// we only replace the " with ` in what comes BEFORE the VALUES
// (ie, field names, like INSERT INTO table ("bla","bla2") VALUES ('s:4:"test"','bladata2');
// should convert to INSERT INTO table (`bla`,`bla2`) VALUES ('s:4:"test"','bladata2');
@@ -453,7 +453,7 @@ function pg2mysql(&$input, &$arrayofprimaryalreadyintabledef, $header = true)
$output .= $before . " VALUES " . $after;
do {
$linenumber ++;
$linenumber++;
// in after, we need to watch out for escape format strings, ie (E'escaped \r in a string'), and ('bla',E'escaped \r in a string')
// ugh i guess its possible these strings could exist IN the data as well, but the only way to solve that is to process these lines one character
@@ -477,7 +477,7 @@ function pg2mysql(&$input, &$arrayofprimaryalreadyintabledef, $header = true)
}
// echo "inquotes=$inquotes\n";
}
} while (substr($lines[$linenumber], - 3, - 1) != ");" || $inquotes);
} while (substr($lines[$linenumber], -3, -1) != ");" || $inquotes);
}
}
if (substr($line, 0, 16) == "ALTER TABLE ONLY") {
@@ -486,14 +486,14 @@ function pg2mysql(&$input, &$arrayofprimaryalreadyintabledef, $header = true)
$line = str_replace("public.", "", $line);
$pkey = $line;
$linenumber ++;
$linenumber++;
if (!empty($lines[$linenumber])) {
$line = $lines[$linenumber];
} else {
$line = '';
}
if (strstr($line, " PRIMARY KEY ") && substr($line, - 3, - 1) == ");") {
if (strstr($line, " PRIMARY KEY ") && substr($line, -3, -1) == ");") {
$reg2 = array();
if (preg_match('/ALTER TABLE ([^\s]+)/', $pkey, $reg2)) {
if (empty($arrayofprimaryalreadyintabledef[$reg2[1]])) {
@@ -580,7 +580,7 @@ function pg2mysql(&$input, &$arrayofprimaryalreadyintabledef, $header = true)
}
}
$linenumber ++;
$linenumber++;
}
return array('output' => $output,'outputatend' => $outputatend);

View File

@@ -24,8 +24,8 @@
* - Exclude param optioncss, token, sortfield, sortorder
*/
$crawledLinks=array();
const MAX_DEPTH=2;
$crawledLinks = array();
const MAX_DEPTH = 2;
/**
@@ -36,35 +36,38 @@ const MAX_DEPTH=2;
function followLink($url, $depth = 0)
{
global $crawledLinks;
$crawling=array();
if ($depth>MAX_DEPTH) {
$crawling = array();
if ($depth > MAX_DEPTH) {
echo "<div style='color:red;'>The Crawler is giving up!</div>";
return;
}
$options=array(
'http'=>array(
'method'=>"GET",
'user-agent'=>"gfgBot/0.1\n"
$options = array(
'http' => array(
'method' => "GET",
'user-agent' => "gfgBot/0.1\n"
)
);
$context=stream_context_create($options);
$doc=new DomDocument();
$context = stream_context_create($options);
$doc = new DomDocument();
@$doc->loadHTML(file_get_contents($url, false, $context));
$links=$doc->getElementsByTagName('a');
$pageTitle=getDocTitle($doc, $url);
$metaData=getDocMetaData($doc);
$links = $doc->getElementsByTagName('a');
$pageTitle = getDocTitle($doc, $url);
$metaData = getDocMetaData($doc);
foreach ($links as $i) {
$link=$i->getAttribute('href');
if (ignoreLink($link)) continue;
$link=convertLink($url, $link);
$link = $i->getAttribute('href');
if (ignoreLink($link)) {
continue;
}
$link = convertLink($url, $link);
if (!in_array($link, $crawledLinks)) {
$crawledLinks[]=$link;
$crawling[]=$link;
$crawledLinks[] = $link;
$crawling[] = $link;
insertIntoDatabase($link, $pageTitle, $metaData, $depth);
}
}
foreach ($crawling as $crawlURL)
followLink($crawlURL, $depth+1);
foreach ($crawling as $crawlURL) {
followLink($crawlURL, $depth + 1);
}
}
/**
@@ -74,14 +77,16 @@ function followLink($url, $depth = 0)
*/
function convertLink($site, $path)
{
if (substr_compare($path, "//", 0, 2)==0)
if (substr_compare($path, "//", 0, 2) == 0) {
return parse_url($site)['scheme'].$path;
elseif (substr_compare($path, "http://", 0, 7)==0
or substr_compare($path, "https://", 0, 8)==0
or substr_compare($path, "www.", 0, 4)==0
)
} elseif (substr_compare($path, "http://", 0, 7) == 0
or substr_compare($path, "https://", 0, 8) == 0
or substr_compare($path, "www.", 0, 4) == 0
) {
return $path;
else return $site.'/'.$path;
} else {
return $site.'/'.$path;
}
}
/**
@@ -90,7 +95,7 @@ function convertLink($site, $path)
*/
function ignoreLink($url)
{
return $url[0]=="#" or substr($url, 0, 11) == "javascript:";
return $url[0] == "#" or substr($url, 0, 11) == "javascript:";
}
/**
@@ -116,11 +121,12 @@ function insertIntoDatabase($link, $title, &$metaData, $depth)
*/
function getDocTitle(&$doc, $url)
{
$titleNodes=$doc->getElementsByTagName('title');
if (count($titleNodes)==0 or !isset($titleNodes[0]->nodeValue))
$titleNodes = $doc->getElementsByTagName('title');
if (count($titleNodes) == 0 or !isset($titleNodes[0]->nodeValue)) {
return $url;
$title=str_replace('', '\n', $titleNodes[0]->nodeValue);
return (strlen($title)<1)?$url:$title;
}
$title = str_replace('', '\n', $titleNodes[0]->nodeValue);
return (strlen($title) < 1) ? $url : $title;
}
/**
@@ -129,16 +135,20 @@ function getDocTitle(&$doc, $url)
*/
function getDocMetaData(&$doc)
{
$metaData=array();
$metaNodes=$doc->getElementsByTagName('meta');
foreach ($metaNodes as $node)
$metaData = array();
$metaNodes = $doc->getElementsByTagName('meta');
foreach ($metaNodes as $node) {
$metaData[$node->getAttribute("name")] = $node->getAttribute("content");
if (!isset($metaData['description']))
$metaData['description']='No Description Available';
if (!isset($metaData['keywords'])) $metaData['keywords']='';
}
if (!isset($metaData['description'])) {
$metaData['description'] = 'No Description Available';
}
if (!isset($metaData['keywords'])) {
$metaData['keywords'] = '';
}
return array(
'keywords'=>str_replace('', '\n', $metaData['keywords']),
'description'=>str_replace('', '\n', $metaData['description'])
'keywords' => str_replace('', '\n', $metaData['keywords']),
'description' => str_replace('', '\n', $metaData['description'])
);
}