Skip to content

Commit

Permalink
Update. Get changes from SPBC 2.139
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandergull committed Aug 5, 2024
1 parent 41d4d9a commit bc56ffa
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions HeuristicAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,38 @@ public function __construct($input, $self = null)
$this->evaluations = new Evaluations($this->tokens, $this->variables, $this->includes, $this->sqls);
$this->code_style = new CodeStyle($this->tokens);

if ( isset($input['path']) && version_compare(PHP_VERSION, '8.1', '>=') && extension_loaded('mbstring') ) {
// Do not run entropy analysis on included constructs
$this->entropyAnalyser = new Entropy($input['path']);
$currentMemoryLimit = ini_get('memory_limit');
$currentMemoryLimitBytes = $this->convertToBytes($currentMemoryLimit);
$compareValueBytes = $this->convertToBytes('256M');

if ($currentMemoryLimitBytes >= $compareValueBytes) {
if ( isset($input['path']) && version_compare(PHP_VERSION, '8.1', '>=') && extension_loaded('mbstring') ) {
// Do not run entropy analysis on included constructs
$this->entropyAnalyser = new Entropy($input['path']);
}
}
}

public function convertToBytes($value)
{
if (is_string($value) && $value !== "-1") {
$value = trim($value);
$prefix = strtolower(substr($value, - 1, 1));
$number = substr($value, 0, - 1);
switch ($prefix) {
case 'k':
$value = (int)$number * 1024;
break;
case 'm':
$value = (int)$number * 1024 * 1024;
break;
case 'g':
$value = (int)$number * 1024 * 1024 * 1024;
break;
default:
$value = (int)$value;
}
return $value;
}
}

Expand Down Expand Up @@ -293,7 +322,7 @@ public function processContent()
$this->extension !== 'shtml' &&
$this->extension !== 'js'
) {
$this->code_style->analyseLineLengths($this->file_content);
//$this->code_style->analyseLineLengths($this->file_content);
$this->code_style->analyseHumanUnreadableCode($this->file_content);
$this->code_style->analyseWeightOfNoise($this->file_content);
}
Expand Down

0 comments on commit bc56ffa

Please sign in to comment.