Function balance_file
has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring. Open
private function balance_file($file, $share, $share_options, $source_drive, &$pool_drives_avail_space, $balance_direction_asc, &$file_too_large_warnings) {
$num_total_drives = count($pool_drives_avail_space);
$current_avail_space = $pool_drives_avail_space[$source_drive];
$target_avail_space = array_sum($pool_drives_avail_space) / count($pool_drives_avail_space);
$delta_needed = $target_avail_space - $current_avail_space;
- 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 balance_file
has 119 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function balance_file($file, $share, $share_options, $source_drive, &$pool_drives_avail_space, $balance_direction_asc, &$file_too_large_warnings) {
$num_total_drives = count($pool_drives_avail_space);
$current_avail_space = $pool_drives_avail_space[$source_drive];
$target_avail_space = array_sum($pool_drives_avail_space) / count($pool_drives_avail_space);
$delta_needed = $target_avail_space - $current_avail_space;
Function execute
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
public function execute() {
Log::info("Starting available space balancing");
// Start with shares that have sticky files, so that subsequent shares will be used to try to balance what moving files into stick_into drives could debalance...
// Then start with the shares for which we keep the most # copies;
- 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
File BalanceTask.php
has 254 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/*
Copyright 2009-2020 Guillaume Boudreau
This file is part of Greyhole.
Function balance_share
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private function balance_share($share, $share_options, $min_file_size) {
Log::debug("├┐ Balancing share: $share ({$min_file_size}MB or + files)");
/** @var $drives_selectors PoolDriveSelector[] */
$drives_selectors = Config::get(CONFIG_DRIVE_SELECTION_ALGORITHM);
- 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 execute
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function execute() {
Log::info("Starting available space balancing");
// Start with shares that have sticky files, so that subsequent shares will be used to try to balance what moving files into stick_into drives could debalance...
// Then start with the shares for which we keep the most # copies;
Method balance_share
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function balance_share($share, $share_options, $min_file_size) {
Log::debug("├┐ Balancing share: $share ({$min_file_size}MB or + files)");
/** @var $drives_selectors PoolDriveSelector[] */
$drives_selectors = Config::get(CONFIG_DRIVE_SELECTION_ALGORITHM);
Method balance_drive
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function balance_drive($share, $share_options, $source_drive, &$pool_drives_avail_space, $balance_direction_asc, $min_file_size) {
$current_avail_space = $pool_drives_avail_space[$source_drive];
$target_avail_space = array_sum($pool_drives_avail_space) / count($pool_drives_avail_space);
$delta_needed = $target_avail_space - $current_avail_space;
if ($delta_needed <= 10*1024 || $delta_needed < $min_file_size*1024) {
Function balance_drive
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private function balance_drive($share, $share_options, $source_drive, &$pool_drives_avail_space, $balance_direction_asc, $min_file_size) {
$current_avail_space = $pool_drives_avail_space[$source_drive];
$target_avail_space = array_sum($pool_drives_avail_space) / count($pool_drives_avail_space);
$delta_needed = $target_avail_space - $current_avail_space;
if ($delta_needed <= 10*1024 || $delta_needed < $min_file_size*1024) {
- 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 balance_file
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
private function balance_file($file, $share, $share_options, $source_drive, &$pool_drives_avail_space, $balance_direction_asc, &$file_too_large_warnings) {
Method balance_drive
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
private function balance_drive($share, $share_options, $source_drive, &$pool_drives_avail_space, $balance_direction_asc, $min_file_size) {
Avoid too many return
statements within this method. Open
return TRUE;
Avoid too many return
statements within this method. Open
return TRUE;
Avoid too many return
statements within this method. Open
return TRUE;
Avoid too many return
statements within this method. Open
return $this->execute();
Avoid too many return
statements within this method. Open
return FALSE;
Avoid too many return
statements within this method. Open
return TRUE;
Avoid too many return
statements within this method. Open
return TRUE;
Avoid too many return
statements within this method. Open
return TRUE;
Avoid too many return
statements within this method. Open
return TRUE;
Function is_share_sticky
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static function is_share_sticky($share_name) {
$sticky_files = Config::get(CONFIG_STICKY_FILES);
if (!empty($sticky_files)) {
foreach ($sticky_files as $share_dir => $stick_into) {
if (string_starts_with($share_dir, $share_name)) {
- 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"