File phpthumb.functions.php
has 962 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
//////////////////////////////////////////////////////////////
// phpThumb() by James Heinrich <info@silisoftware.com> //
// available at http://phpthumb.sourceforge.net //
// and/or https://github.com/JamesHeinrich/phpThumb //
Function gd_info
has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring. Open
function gd_info()
{
static $gd_info = [];
if (empty($gd_info)) {
// based on code by johnschaefer at gmx dot de
- 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
phpthumb_functions
has 46 functions (exceeds 20 allowed). Consider refactoring. Open
class phpthumb_functions
{
public static function is_windows()
{
return (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN');
Function SafeURLread
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
public static function SafeURLread($url, &$error, $timeout = 10, $followredirects = true)
{
$error = '';
$errstr = '';
$rawData = '';
- 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 URLreadFsock
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
public static function URLreadFsock($host, $file, &$errstr, $successonly = true, $port = -1, $timeout = 10)
{
if (!function_exists('fsockopen') || self::FunctionIsDisabled('fsockopen')) {
$errstr = 'URLreadFsock says: function fsockopen() unavailable';
return false;
- 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 SafeURLread
has 76 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function SafeURLread($url, &$error, $timeout = 10, $followredirects = true)
{
$error = '';
$errstr = '';
$rawData = '';
Function EnsureDirectoryExists
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
public static function EnsureDirectoryExists($dirname, $mask = 0755)
{
// https://www.php.net/manual/en/ini.core.php#ini.open-basedir says:
// "Under Windows, separate the directories with a semicolon. On all other systems, separate the directories with a colon."
$config_open_basedir = ini_get('open_basedir');
- 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 gd_info
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
function gd_info()
{
static $gd_info = [];
if (empty($gd_info)) {
// based on code by johnschaefer at gmx dot de
Method version_compare_replacement_sub
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function version_compare_replacement_sub($version1, $version2, $operator = '')
{
// If you specify the third optional operator argument, you can test for a particular relationship.
// The possible operators are: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne respectively.
// Using this argument, the function will return 1 if the relationship is the one specified by the operator, 0 otherwise.
Function GetAllFilesInSubfolders
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public static function GetAllFilesInSubfolders($dirname)
{
$AllFiles = [];
$dirname = rtrim(realpath($dirname), '/\\');
if ($dirhandle = @opendir($dirname)) {
- 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 URLreadFsock
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function URLreadFsock($host, $file, &$errstr, $successonly = true, $port = -1, $timeout = 10)
{
if (!function_exists('fsockopen') || self::FunctionIsDisabled('fsockopen')) {
$errstr = 'URLreadFsock says: function fsockopen() unavailable';
return false;
Method EnsureDirectoryExists
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function EnsureDirectoryExists($dirname, $mask = 0755)
{
// https://www.php.net/manual/en/ini.core.php#ini.open-basedir says:
// "Under Windows, separate the directories with a semicolon. On all other systems, separate the directories with a colon."
$config_open_basedir = ini_get('open_basedir');
Method SafeExec
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function SafeExec($command)
{
static $AllowedExecFunctions = [];
if (empty($AllowedExecFunctions)) {
$AllowedExecFunctions = ['shell_exec' => true, 'passthru' => true, 'system' => true, 'exec' => true];
Method ImageCopyResampleBicubic
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function ImageCopyResampleBicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
// ron at korving dot demon dot nl
// http://www.php.net/imagecopyresampled
Method CleanUpURLencoding
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function CleanUpURLencoding($url, $queryseperator = '&')
{
if (!0 === stripos($url, "http")) {
return $url;
}
Function SafeExec
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public static function SafeExec($command)
{
static $AllowedExecFunctions = [];
if (empty($AllowedExecFunctions)) {
$AllowedExecFunctions = ['shell_exec' => true, 'passthru' => true, 'system' => true, 'exec' => 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
Method ImageCopyResampleBicubic
has 10 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function ImageCopyResampleBicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
Method ImageTypeToMIMEtype
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function ImageTypeToMIMEtype($imagetype)
{
if (function_exists('image_type_to_mime_type') && ($imagetype >= 1) && ($imagetype <= 18)) {
// PHP v4.3.0+
return image_type_to_mime_type($imagetype);
Method ImageCopyRespectAlpha
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function ImageCopyRespectAlpha(&$dst_im, &$src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $opacity_pct = 100)
Function version_compare_replacement_sub
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function version_compare_replacement_sub($version1, $version2, $operator = '')
{
// If you specify the third optional operator argument, you can test for a particular relationship.
// The possible operators are: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne respectively.
// Using this argument, the function will return 1 if the relationship is the one specified by the operator, 0 otherwise.
- 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 exif_info
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function exif_info()
{
static $exif_info = [];
if (empty($exif_info)) {
// based on code by johnschaefer at gmx dot de
- 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 CleanUpURLencoding
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function CleanUpURLencoding($url, $queryseperator = '&')
{
if (!0 === stripos($url, "http")) {
return $url;
}
- 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 GetAllFilesInSubfolders
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function GetAllFilesInSubfolders($dirname)
{
$AllFiles = [];
$dirname = rtrim(realpath($dirname), '/\\');
if ($dirhandle = @opendir($dirname)) {
Function filesize_remote
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function filesize_remote($remotefile, $timeout = 10)
{
$size = false;
$parsed_url = self::ParseURLbetter($remotefile);
if ($fp = @fsockopen($parsed_url['host'], $parsed_url['port'], $errno, $errstr, $timeout)) {
- 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 filedate_remote
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function filedate_remote($remotefile, $timeout = 10)
{
$date = false;
$parsed_url = self::ParseURLbetter($remotefile);
if ($fp = @fsockopen($parsed_url['host'], $parsed_url['port'], $errno, $errstr, $timeout)) {
- 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 deeply nested control flow statements. Open
if ($imagetypes & IMG_JPG) {
$gd_info['JPG Support'] = true;
}
Method ScaleToFitInBox
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function ScaleToFitInBox($width, $height, $maxwidth = null, $maxheight = null, $allow_enlarge = true, $allow_reduce = true)
Avoid deeply nested control flow statements. Open
if ($imagetypes & IMG_WBMP) {
$gd_info['WBMP Support'] = true;
}
Avoid deeply nested control flow statements. Open
if ($tempfilename = phpthumb::phpThumb_tempnam()) {
if ($fp_tempfile = @fopen($tempfilename, 'wb')) {
fwrite($fp_tempfile, base64_decode('R0lGODlhAQABAIAAAH//AP///ywAAAAAAQABAAACAUQAOw==')); // very simple 1px GIF file base64-encoded as string
fclose($fp_tempfile);
$phpthumb_temp = new phpthumb();
Avoid deeply nested control flow statements. Open
switch ($errno) {
case 200:
// great, continue
break;
Avoid deeply nested control flow statements. Open
if ($imagetypes & IMG_PNG) {
$gd_info['PNG Support'] = true;
}
Method URLreadFsock
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function URLreadFsock($host, $file, &$errstr, $successonly = true, $port = -1, $timeout = 10)
Avoid deeply nested control flow statements. Open
if ($imagetypes & IMG_GIF) {
$gd_info['GIF Create Support'] = true;
}
Method ImageColorAllocateAlphaSafe
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function ImageColorAllocateAlphaSafe(&$gdimg_hexcolorallocate, $R, $G, $B, $alpha = false)
Function ProportionalResize
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function ProportionalResize($old_width, $old_height, $new_width = false, $new_height = false)
{
$old_aspect_ratio = $old_width / $old_height;
if (($new_width === false) && ($new_height === false)) {
return false;
- 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 FunctionIsDisabled
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function FunctionIsDisabled($function)
{
static $DisabledFunctions = null;
if (null === $DisabledFunctions) {
$disable_functions_local = explode(',', strtolower(@ini_get('disable_functions')));
- 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 ImageCopyResampleBicubic
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function ImageCopyResampleBicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
// ron at korving dot demon dot nl
// http://www.php.net/imagecopyresampled
- 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
return (int)($version1 != $version2);
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return (int)($version1 == $version2);
Avoid too many return
statements within this method. Open
return 1;
Avoid too many return
statements within this method. Open
return 0;
Avoid too many return
statements within this method. Open
return -1;
Function ApacheLookupURIarray
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function ApacheLookupURIarray($filename)
{
// apache_lookup_uri() only works when PHP is installed as an Apache module.
if (PHP_SAPI == 'apache') {
//$property_exists_exists = function_exists('property_exists');
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
foreach ($phpinfo_array as $line) {
$line = trim(strip_tags($line));
foreach ($gd_info as $key => $value) {
//if (strpos($line, $key) !== false) {
if (strpos($line, $key) === 0) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 92.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
foreach ($phpinfo_array as $line) {
$line = trim(strip_tags($line));
foreach ($exif_info as $key => $value) {
if (strpos($line, $key) === 0) {
$newvalue = trim(str_replace($key, '', $line));
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 92.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76