File Bitmap.php
has 593 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace COREPOS\pos\lib;
use \Exception;
Function load
has a Cognitive Complexity of 53 (exceeds 5 allowed). Consider refactoring. Open
public function load($filename, $filedata=null)
{
$data = "";
if ($filename === true) {
$data = $filedata;
- 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 load
has 168 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function load($filename, $filedata=null)
{
$data = "";
if ($filename === true) {
$data = $filedata;
Bitmap
has 23 functions (exceeds 20 allowed). Consider refactoring. Open
class Bitmap
{
private $DIB1 = 12;
private $DIB2 = 64;
private $DIB3 = 40;
Method save
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function save($filename) {
// prepare the image
$rowBytes = (int)((($this->width * $this->bpp) + 7) / 8);
$rowDataSize = (int)((($this->width * $this->bpp) + 31) / 32) * 4;
if ($rowBytes > $rowDataSize) {
Method setPixelValue
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function setPixelValue($x, $y, $val)
{
// validate coordinates
if ($x < 0) {
$x += $this->width;
Method drawLine
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function drawLine($pt1, $pt2, $val)
{
// validate coordinates
try {
$pt1[0] = $this->validateCoord($pt1[0], $this->width);
Function drawLine
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function drawLine($pt1, $pt2, $val)
{
// validate coordinates
try {
$pt1[0] = $this->validateCoord($pt1[0], $this->width);
- 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 getPixelValue
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getPixelValue($x, $y)
{
// validate coordinates
if ($x < 0) {
$x += $this->width;
Method parseInt
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function parseInt($data, $left=0, $right=-1, $signed=false, $bigEndian=false)
{
if (is_string($data)) {
$isarray = false;
if ($right < 0) {
Function parseInt
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private function parseInt($data, $left=0, $right=-1, $signed=false, $bigEndian=false)
{
if (is_string($data)) {
$isarray = false;
if ($right < 0) {
- 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 renderBitmap
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
static private function renderBitmap($arg)
{
global $PRINT_OBJ;
$slip = "";
Function setPixelValue
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function setPixelValue($x, $y, $val)
{
// validate coordinates
if ($x < 0) {
$x += $this->width;
- 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 __construct
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __construct($width=1, $height=1, $bpp=1, $dpi=72)
{
$this->error = null;
if (!is_numeric($width) || (int)$width < 1) {
Function save
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function save($filename) {
// prepare the image
$rowBytes = (int)((($this->width * $this->bpp) + 7) / 8);
$rowDataSize = (int)((($this->width * $this->bpp) + 31) / 32) * 4;
if ($rowBytes > $rowDataSize) {
- 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
Consider simplifying this complex logical expression. Open
if ($bpp != 1 && $bpp != 4 && $bpp != 8 && $bpp != 16 && $bpp != 24 && $bpp != 32) {
return $this->returnError("load(): invalid bits-per-pixel ".$bpp);
}
Method parseInt
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private function parseInt($data, $left=0, $right=-1, $signed=false, $bigEndian=false)
Function renderBitmap
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
static private function renderBitmap($arg)
{
global $PRINT_OBJ;
$slip = "";
- 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 $this->returnError("load(): ".$bpp." bits-per-pixel invalid in V1 header");
Avoid too many return
statements within this method. Open
return $this->returnError("save(): failed writing file \"".$filename."\" (".$bytes." of ".strlen($data)." bytes written)");
Avoid too many return
statements within this method. Open
return $this->returnError("load(): incomplete DIB header (file is ".$datasize." bytes)");
Avoid too many return
statements within this method. Open
return $this->returnError("load(): invalid image height ".$height);
Avoid too many return
statements within this method. Open
return $data;
Avoid too many return
statements within this method. Open
return $this->returnError("load(): invalid horizontal pixels-per-meter ".$hppm);
Avoid too many return
statements within this method. Open
return $this->parseInt($this->image, $byte, $byte + 1);
Avoid too many return
statements within this method. Open
return $this->returnError("load(): invalid image width ".$width);
Avoid too many return
statements within this method. Open
return $this->returnError("load(): invalid color plane count ".$colorPlanes);
Avoid too many return
statements within this method. Open
return $this->returnError("load(): invalid bits-per-pixel ".$bpp);
Avoid too many return
statements within this method. Open
return $this->returnError("load(): incomplete image (file is ".$datasize." bytes)");
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 ord($this->image[$byte]);
Avoid too many return
statements within this method. Open
return $this->returnError("load(): image data compression not supported");
Avoid too many return
statements within this method. Open
return $this->returnError("load(): consistency error (calculated byte width ".$rowBytes.", data width ".$rowDataSize.")");
Avoid too many return
statements within this method. Open
return $this->returnError("save(): consistency error (calculated DIB size ".$this->dibVersion.", prepared ".strlen($dibHead).")");
Avoid too many return
statements within this method. Open
return $this->returnError("load(): invalid compression code ".$compression);
Avoid too many return
statements within this method. Open
return $this->returnError("load(): incorrect image data size (".$imgDataSize." reported, ".(abs($height) * $rowDataSize)." expected)");
Avoid too many return
statements within this method. Open
return $this->returnError("load(): invalid vertical pixels-per-meter ".$hppm);
Avoid too many return
statements within this method. Open
return $this->returnError("load(): incomplete palette (file is ".$datasize." bytes)");
Avoid too many return
statements within this method. Open
return $this->returnError("load(): unknown DIB header size (".$headerSize." bytes)");
Avoid too many return
statements within this method. Open
return null;
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 null;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return ((ord($this->image[$byte]) >> $shift) & 0x0F);
Avoid too many return
statements within this method. Open
return ((ord($this->image[$byte]) >> $shift) & 0x01);
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return true;