File ConfigHelper.php
has 649 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/*
Copyright 2014-2017 Guillaume Boudreau
This file is part of Greyhole.
Function init
has a Cognitive Complexity of 70 (exceeds 5 allowed). Consider refactoring. Open
private static function init() {
Log::setLevel(Config::get(CONFIG_LOG_LEVEL));
self::$df_command = "df -k";
foreach (Config::storagePoolDrives() as $sp_drive) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method init
has 123 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function init() {
Log::setLevel(Config::get(CONFIG_LOG_LEVEL));
self::$df_command = "df -k";
foreach (Config::storagePoolDrives() as $sp_drive) {
Function parse
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
public static function parse() {
if (!ini_get('date.timezone')) {
// To prevent warnings that would be logged if something gets logged before the timezone setting is parsed and applied.
date_default_timezone_set('UTC');
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parse_line_pool_drive
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
private static function parse_line_pool_drive($name, $value) {
if ($name == CONFIG_STORAGE_POOL_DRIVE) {
if (preg_match("/(.*) ?, ?min_free ?: ?([0-9]+) ?([gmk])b?/i", $value, $regs)) {
$sp_drive = '/' . trim(trim($regs[1]), '/');
Config::add(CONFIG_STORAGE_POOL_DRIVE, $sp_drive);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method parse_line_share_option
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function parse_line_share_option($name, $value) {
if (!string_starts_with($name, [CONFIG_NUM_COPIES, CONFIG_DELETE_MOVES_TO_TRASH, CONFIG_MODIFIED_MOVES_TO_TRASH, CONFIG_DRIVE_SELECTION_GROUPS, CONFIG_DRIVE_SELECTION_ALGORITHM])) {
return FALSE;
}
if (!preg_match('/^(.*)\[\s*(.*)\s*]$/', $name, $matches)) {
Function parse_line
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private static function parse_line($name, $value) {
if ($name[0] == '#') {
return;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parse_line_share_option
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
private static function parse_line_share_option($name, $value) {
if (!string_starts_with($name, [CONFIG_NUM_COPIES, CONFIG_DELETE_MOVES_TO_TRASH, CONFIG_MODIFIED_MOVES_TO_TRASH, CONFIG_DRIVE_SELECTION_GROUPS, CONFIG_DRIVE_SELECTION_ALGORITHM])) {
return FALSE;
}
if (!preg_match('/^(.*)\[\s*(.*)\s*]$/', $name, $matches)) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function getShareOptionsFromDrive
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public static function getShareOptionsFromDrive($full_path, $sp_drive) {
$landing_zone = '';
$share = FALSE;
foreach (SharesConfig::getShares() as $share_name => $share_options) {
$lz = $share_options[CONFIG_LANDING_ZONE];
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method parse
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function parse() {
if (!ini_get('date.timezone')) {
// To prevent warnings that would be logged if something gets logged before the timezone setting is parsed and applied.
date_default_timezone_set('UTC');
}
Function recursive_include_parser
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
function recursive_include_parser($file) {
$regex = '/^[ \t]*include[ \t]*=[ \t]*([^#\r\n]+)/im';
$ok_to_execute = FALSE;
if (is_array($file) && count($file) > 1) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parse_line_hook
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static function parse_line_hook($name, $value) {
if (string_starts_with($name, CONFIG_HOOK)) {
if (!preg_match('/hook\[([^]]+)]/', $name, $re)) {
Log::warn("Can't parse the following config line: $name; ignoring.", Log::EVENT_CODE_CONFIG_UNPARSEABLE_LINE);
return TRUE;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
if (self::parse_line_log($name, $value)) return;
Avoid too many return
statements within this method. Open
if (self::parse_line_pool_drive($name, $value)) return;
Avoid too many return
statements within this method. Open
if (self::parse_line_drive_selection($name, $value)) return;
Avoid too many return
statements within this method. Open
if (self::parse_line_share_option($name, $value)) return;
Avoid too many return
statements within this method. Open
if (self::parse_line_hook($name, $value)) return;
Avoid too many return
statements within this method. Open
if (self::parse_line_sticky($name, $value)) return;
Avoid too many return
statements within this method. Open
if (self::parse_line_ignore($name, $value)) return;
Avoid too many return
statements within this method. Open
if (self::parse_line_frozen($name, $value)) return;
Function getNumCopies
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function getNumCopies($share) {
$num_copies = static::get($share, CONFIG_NUM_COPIES);
if (!$num_copies) {
Log::warn("Found a task on a share ($share) that disappeared from " . ConfigHelper::$config_file . ". Skipping.", Log::EVENT_CODE_TASK_FOR_UNKNOWN_SHARE);
return -1;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"