Commit 74a5a5f1 authored by Felix Flor's avatar Felix Flor

Merge branch '7-additional-cli-output' into 'master'

Resolve "Additional CLI Output"

Closes #7

See merge request code-mesa/aphpbreakdown!6
parents 73c0f8d5 adb78ac5
# PHP Storm Directory
.idea
......@@ -24,6 +24,9 @@ switch($argv[2]){
case "--console-full":
fullConsoleOutput($filesToCheck);
break;
case "--console-makefile":
makefileConsoleOutput($filesToCheck);
break;
case "--testfile":
createTestfileFromTemplate($filesToCheck, $argv[3], $argv[4]);
break;
......
......@@ -39,6 +39,8 @@ require_once __DIR__ . '/inc/func/isModuleForConstantInstalled.func.php';
require_once __DIR__ . '/inc/func/isModuleForConstantInstalledAsString.func.php';
require_once __DIR__ . '/inc/func/matchConstantToModule.func.php';
require_once __DIR__ . '/inc/func/isConstantInArray.func.php';
require_once __DIR__ . '/inc/func/getNeededModules.func.php';
require_once __DIR__ . '/inc/func/getModulesInstalledStatus.func.php';
/********************/
/* output functions */
......@@ -46,4 +48,5 @@ require_once __DIR__ . '/inc/func/isConstantInArray.func.php';
require_once __DIR__ . '/inc/output/basicConsoleOutput.func.php';
require_once __DIR__ . '/inc/output/fullConsoleOutput.func.php';
require_once __DIR__ . '/inc/output/makefileConsoleOutput.func.php';
require_once __DIR__ . '/inc/output/createTestfileFromTemplate.func.php';
......@@ -18,13 +18,13 @@ function checkGivenArguments($argv) {
if(!is_array($argv))
throw new \Exception ("APHPBreakdown: Invalid parameter type! Must: array, Is: " . gettype($argv));
$acceptedOutputArguments = array("--console-basic","--console-full", "--testfile");
$acceptedOutputArguments = array("--console-basic","--console-full", "--console-makefile", "--testfile");
$acceptedTemplateArguments = array("--basic", "--advanced");
$path = realpath($argv[1]);
if(!isset($path) || !isset($argv[2]))
exitWithErrorMessage("APHPBreakdown: Not enough arguments given!\n\t\t aphpbreakdown <PATH> <OPTIONS> [--testfile <TEMPLATE>] [--testfile <EXPORT_FILENAME>]\n\t\t <PATH> /path/to/dir\n\t\t <OPTIONS> --console-basic | --console-full | --testfile\n\t\t [--testfile <TEMPLATE>] --basic | --advanced\n\t\t [<EXPORT_FILENAME>] optional, no path, don't forget file extension\n");
exitWithErrorMessage("APHPBreakdown: Not enough arguments given!\n\t\t aphpbreakdown <PATH> <OPTIONS> [--testfile <TEMPLATE>] [--testfile <EXPORT_FILENAME>]\n\t\t <PATH> /path/to/dir\n\t\t <OPTIONS> --console-basic | --console-full | --console-makefile | --testfile\n\t\t [--testfile <TEMPLATE>] --basic | --advanced\n\t\t [<EXPORT_FILENAME>] optional, no path, don't forget file extension\n");
if(!is_dir($path))
exitWithErrorMessage("APHPBreakdown: There is no directory found on path \"$path\"\n");
......@@ -48,10 +48,10 @@ function checkGivenArguments($argv) {
exitWithErrorMessage("APHPBreakdown: There are sone or more Files which are not readable. Check the Output above for Details.\nChange the file Permissions. To do that use this command \"$ chmod u+r <FILE>\"\n");
if(!isset($argv[2]))
exitWithErrorMessage("APHPBreakdown: You have to give argument for output. ( aphpanalyse <PATH> <OUTPUT> [ --console-full | --testfile ] ).\n");
exitWithErrorMessage("APHPBreakdown: You have to give argument for output. ( aphpbreakdown <PATH> <OUTPUT> [ --console-basic | --console-full | --console-makefile | --testfile ] ).\n");
if(!in_array($argv[2], $acceptedOutputArguments))
exitWithErrorMessage("APHPBreakdown: The Argument you have given is not valid. Avaible Options: <OUTPUT> [ --console-basic | --console-full | --testfile ].\n");
exitWithErrorMessage("APHPBreakdown: The Argument you have given is not valid. Avaible Options: <OUTPUT> [ --console-basic | --console-full | --console-makefile | --testfile ].\n");
if($argv[2] == "--testfile" && !isset($argv[3]))
exitWithErrorMessage("APHPBreakdown: Missing Argument for --testfile. Avaible Options: [<TEMPLATE>] [ --basic | --advanced ].\n");
......
<?php
namespace APHPBreakdown;
/**
* @return mixed[] $neddedModulesInstallStatus
*
* @param mixed[] $neededModules
*
* @throws \Exception - if $filesToCheck is not of type array
*
* this function chechs the install status of the needed modules
*
**/
function getModulesInstalledStatus($neededModules){
if(!is_array($neededModules))
throw new \Exception ("Invalid parameter type for \$neededModules! Must: array, Is: " . gettype($neededModules));
$neddedModulesInstallStatus = array();
echo "APHPBreakdown: Checking Modul Status ... ";
foreach ($neededModules as $neededModule) {
if($neededModule != "Core"){
if(!extension_loaded($neededModule)){
$neddedModulesInstallStatus[$neededModule] = false;
} else {
$neddedModulesInstallStatus[$neededModule] = true;
}
}
}
echo "Finished!\n\n";
return $neddedModulesInstallStatus;
}
<?php
namespace APHPBreakdown;
/**
* @return mixed[] $neededModules - a aplphabetical sorted array if all needed modules
*
* @param mixed[] $filesToCheck - contains all paths to files, one path per field
*
* @throws \Exception - if $filesToCheck is not of type array
*
* this functions checks all given files for functions, constants and classes which
* needed for the project you analize.
*
**/
function getNeededModules($filesToCheck){
if(!is_array($filesToCheck))
throw new \Exception ("Invalid parameter type for \$filesToCheck! Must: array, Is: " . gettype($filesToCheck));
$neededModules = array();
$countAllFiles = count($filesToCheck);
$i = 0;
foreach($filesToCheck as $fileToCheck){
system("clear");
echo "APHPBreakdown: Analyzing File [ ".++$i." / $countAllFiles ] \n";
$tokens = token_get_all(file_get_contents($fileToCheck['fullpath']));
foreach($tokens as $token){
if(is_array($token) && T_STRING == $token[0] && isset($token[1])){
/* check function */
if(in_array($token[1], $GLOBALS['php71_functions_list'])){
$functionToModule = matchFunctionToModule($token[1]);
if(null == $functionToModule)
$functionToModule = "UNKNOWN";
if(!in_array($functionToModule ,$neededModules))
$neededModules[] = $functionToModule;
}
/* check class */
if(in_array($token[1], $GLOBALS['php71_classes_list'])){
$classToModule = matchClassToModule($token[1]);
if(null == $classToModule)
$classToModule = "UNKNOWN";
if(!in_array($classToModule ,$neededModules))
$neededModules[] = $classToModule;
}
/* check constants */
if(isConstantInArray($token[1])){
$constantToModule = matchConstantToModule($token[1]);
if(null == $constantToModule)
$constantToModule = "UNKNOWN";
if(!in_array($constantToModule ,$neededModules))
$neededModules[] = $constantToModule;
}
}
}
}
sort($neededModules, SORT_STRING | SORT_FLAG_CASE);
return $neededModules;
}
......@@ -18,84 +18,15 @@ function basicConsoleOutput($filesToCheck){
if(!is_array($filesToCheck))
throw new \Exception ("Invalid parameter type for \$filesToCheck! Must: array, Is: " . gettype($filesToCheck));
$neededModules = array();
$neddedModulesInstallStatus = array();
$startTime = time();
$countAllFiles = count($filesToCheck);
$i = 0;
foreach($filesToCheck as $fileToCheck){
system("clear");
echo "APHPBreakdown: Analyzing File [ ".++$i." / $countAllFiles ] \n";
$tokens = token_get_all(file_get_contents($fileToCheck['fullpath']));
foreach($tokens as $token){
if(is_array($token) && T_STRING == $token[0] && isset($token[1])){
/* check function */
if(in_array($token[1], $GLOBALS['php71_functions_list'])){
$functionToModule = matchFunctionToModule($token[1]);
if(null == $functionToModule)
$functionToModule = "UNKNOWN";
if(!in_array($functionToModule ,$neededModules))
$neededModules[] = $functionToModule;
}
/* check class */
if(in_array($token[1], $GLOBALS['php71_classes_list'])){
$classToModule = matchClassToModule($token[1]);
if(null == $classToModule)
$classToModule = "UNKNOWN";
if(!in_array($classToModule ,$neededModules))
$neededModules[] = $classToModule;
$neededModules = getNeededModules($filesToCheck);
}
/* check constants */
if(isConstantInArray($token[1])){
$constantToModule = matchConstantToModule($token[1]);
if(null == $constantToModule)
$constantToModule = "UNKNOWN";
if(!in_array($constantToModule ,$neededModules))
$neededModules[] = $constantToModule;
}
}
}
}
$neddedModulesInstallStatus = getModulesInstalledStatus($neededModules);
$countAllFiles = count($filesToCheck);
$countAllModules = count($neededModules);
echo "APHPBreakdown: Checking Modul Status ... ";
foreach ($neededModules as $neededModule) {
if(!extension_loaded($neededModule) && $neededModule != "Core"){
$neddedModulesInstallStatus[$neededModule] = false;
} else {
$neddedModulesInstallStatus[$neededModule] = true;
}
}
echo "Finished!\n\n";
$endTime = time();
$time = $endTime - $startTime;
......
......@@ -4,91 +4,50 @@ namespace APHPBreakdown;
/**
*
* @param mixed[] $filesToCheck - contains all paths to files, one path per field
* @param mixed[] $filesToCheck - contains all paths to files, one path per field
*
* @const T_STRING - same as 319. function, class, constant names are found as T_STRING by tokenizer.
* @throws \Exception - if $filesToCheck is not of type array
*
* @throws \Exception - if the given argument is not of type array
*
* this function gets an array of paths to files and performes on every file in
* the array an checkup and output. it prints you on console if the class, constant,
* function and module are defined / installed or not and in which row and file in the
* project it is used.
*
* $token[0] : number of token
* $token[1] : name of the function
* $token[2] : the row of the file where function is found
* this function gives you the output for the analyse
*
**/
function fullConsoleOutput($filesToCheck) {
function fullConsoleOutput($filesToCheck){
if(!is_array($filesToCheck))
throw new \Exception ("Invalid parameter type! Must: array, Is: " . gettype($filesToCheck));
foreach($filesToCheck as $fileToCheck){
$filesAsString = file_get_contents($fileToCheck['fullpath']);
$tokens = token_get_all($filesAsString);
foreach ($tokens as $token) {
if(is_array($token)){
$numberOfToken = $token[0];
} else {
$numberOfToken = null;
}
throw new \Exception ("Invalid parameter type for \$filesToCheck! Must: array, Is: " . gettype($filesToCheck));
if($numberOfToken == T_STRING) {
$startTime = time();
if(isset($token[1])){
$neededModules = getNeededModules($filesToCheck);
/* part for functions checkup */
if(in_array($token[1], $GLOBALS['php71_functions_list'])){
$neddedModulesInstallStatus = getModulesInstalledStatus($neededModules);
$moduleOfFunction = matchFunctionToModule($token[1]);
$installStatus = isModuleForFunctionInstalledAsString($token[1]);
$countAllFiles = count($filesToCheck);
$countAllModules = count($neededModules)-2;
if(null == $moduleOfFunction){
$moduleOfFunction = "UNKNOWN MODULE - Update lists of Modules for Functions";
echo "$moduleOfFunction [ Function: \"$token[1]\" ]\n";
} else {
echo "MODUL \"$moduleOfFunction\" $installStatus [ Function \"$token[1]\" found in file ".$fileToCheck['relpath']." in Row $token[2]\n";
}
}
$endTime = time();
$time = $endTime - $startTime;
/* part of classes checkup */
if(in_array($token[1], $GLOBALS['php71_classes_list'])){
system("clear");
$moduleOfClass = matchClassToModule($token[1]);
$installStatus = isModuleForClassInstalledAsString($token[1]);
echo "\n APHPBreakdown : Results\n";
echo "======================================================\n\n";
echo " Checked Files: $countAllFiles\n";
echo " Needed Modules: $countAllModules\n\n";
if(null == $moduleOfClass){
$moduleOfClass = "UNKNOWN MODULE - Update lists of Modules for Classes";
echo "$moduleOfClass [ Class: \"$token[1]\" ]\n";
} else {
echo "MODUL \"$moduleOfClass\" $installStatus [ Class \"$token[1]\" found in file ".$fileToCheck['relpath']." in Row $token[2]\n";
}
}
/* port of constants checkup */
if(isConstantInArray($token[1])){
$moduleOfConstant = matchConstantToModule($token[1]);
$installStatus = isModuleForConstantInstalledAsString($token[1]);
if(null == $moduleOfConstant){
$moduleOfConstant = "UNKNOWN MODULE - Update lists of Modules for Constants";
echo "$moduleOfClass [ Class: \"$token[1]\" ]\n";
} else {
echo "MODUL \"$moduleOfConstant\" $installStatus [ Constant \"$token[1]\" found in file ".$fileToCheck['relpath']." in Row $token[2]\n";
}
}
}
echo " List of all Modules [ \033[0;31m missing \033[0m | \033[0;32m installed \033[0m ] :\n";
foreach($neddedModulesInstallStatus as $module => $moduleStatus){
if($module != "Core" && $module != "standard"){
if(!$moduleStatus){
echo " - \033[0;31m$module\033[0m\n";
} else {
echo " - \033[0;32m$module\033[0m\n";
}
}
}
}
echo "\n======================================================\n";
echo " Time to perform the test: $time sec.\n\n";
}
<?php
namespace APHPBreakdown;
/**
*
* @param mixed[] $filesToCheck - contains all paths to files, one path per field
*
* @throws \Exception - if $filesToCheck is not of type array
*
* this function gives you the output for the analyse
*
**/
function makefileConsoleOutput($filesToCheck){
if(!is_array($filesToCheck))
throw new \Exception ("Invalid parameter type for \$filesToCheck! Must: array, Is: " . gettype($filesToCheck));
$startTime = time();
$neededModules = getNeededModules($filesToCheck);
$neddedModulesInstallStatus = getModulesInstalledStatus($neededModules);
$countAllFiles = count($filesToCheck);
$countAllModules = count($neededModules)-2;
$endTime = time();
$time = $endTime - $startTime;
system("clear");
echo "\n APHPBreakdown : Results\n";
echo "======================================================\n\n";
echo " Checked Files: $countAllFiles\n";
echo " Needed Modules: $countAllModules\n\n";
echo " Modules for Makefile Dependencies:\n\n";
$row = "";
echo "USE_PHP=\t";
foreach($neddedModulesInstallStatus as $module => $moduleStatus){
$module = strtolower($module);
$filter = array("zend ");
$module = str_replace($filter, "", $module);
if($module != "core" && $module != "standard"){
$row = $row.$module." ";
if(strlen($row) < 78){
echo $module." ";
} else {
echo $module." \\\n\t\t";
$row = "";
}
}
}
echo "\n\n======================================================\n";
echo " Time to perform the test: $time sec.\n\n";
}
......@@ -42,10 +42,10 @@ here are some different examples for different results:
## Hot To install
# download the aphpbreakdown.phar
wget http://phar.code-mesa.com/aphpbreakdown-1.0.0.phar
wget http://phar.code-mesa.com/aphpbreakdown-2.0.0.phar
# alternativ download way
fetch http://phar.code-mesa.com/aphpbreakdown-1.0.0.phar
fetch http://phar.code-mesa.com/aphpbreakdown-2.0.0.phar
# make it executable
chmod +x aphpbreakdown.phar
......@@ -100,15 +100,14 @@ available options
--console-full
performs a full output on your console. for every found function, constant or class
it prints you our a lines like this:
...
MODUL "pcntl" NOT INSTALLED [ Function "pcntl_wait" found in file testanalysefile.php in Row 9
MODUL "sockets" INSTALLED [ Function "socket_create" found in file subdir/testanalysefilesubdir.php in Row 9
MODUL "sysvmsg" NOT INSTALLED [ Function "msg_set_queue" found in file subdir/subsubdir/testanalysesubsubdir.php in Row 9
...
this can help you to analyse a specific part of a project or a module you want to load
into the project.
performs the same check as the --console-basic but gives you a full list of modules
you need for your project. For a better overview the list marks all results in green
and red. green it the module is installed and red if it't not.
--console-makefile
this is special output to check your project required php modules for the makefile e.g.
used by FreeBSD Portstree
--testfile [--testfile <TEMPLATE>]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment