NikolaGavric94/laravel-square

View on GitHub

Showing 36 of 46 total issues

Consider simplifying this complex logical expression.
Open

                if ((! $discount->pivot && $discount->scope === Constants::DEDUCTIBLE_SCOPE_PRODUCT) ||
                    ($discount->pivot && $discount->pivot->scope === Constants::DEDUCTIBLE_SCOPE_PRODUCT)) {
                    return self::_calculateProductDiscounts($products, $discount);
                } elseif ((! $discount->pivot && $discount->scope === Constants::DEDUCTIBLE_SCOPE_ORDER) ||
                        ($discount->pivot && $discount->pivot->scope === Constants::DEDUCTIBLE_SCOPE_ORDER)) {
Severity: Major
Found in src/utils/Util.php - About 1 hr to fix

Function _saveCustomer has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    private function _saveCustomer(): void
    {
        if (! $this->getCustomer()->payment_service_id) {
            $response = $this->config->customersAPI()->createCustomer($this->getCreateCustomerRequest());

Severity: Minor
Found in src/SquareService.php - About 55 mins to fix

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 charge has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function charge(float $amount, string $nonce, string $location_id, mixed $merchant, array $options = [], mixed $customer = null, string $currency = 'USD'): Transaction
Severity: Major
Found in src/traits/HasProducts.php - About 50 mins to fix

Method charge has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function charge(float $amount, string $nonce, string $location_id, array $options = [], mixed $customer = null, string $currency = 'USD'): Transaction
Severity: Minor
Found in src/traits/HasCustomers.php - About 45 mins to fix

Function createProductFromArray has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function createProductFromArray(array $product, Model $order = null): Product|stdClass
    {
        $productObj = new stdClass();
        //If product doesn't have quantity in pivot table
        //throw new exception because every product should
Severity: Minor
Found in src/builders/ProductBuilder.php - About 45 mins to fix

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 ((! isset($discount['amount']) || $discount['amount'] == null || $discount['amount'] == 0) &&
                (! isset($discount['percentage']) || $discount['percentage'] == null || $discount['percentage'] == '')) {
                throw new MissingPropertyException('Both $amount and $percentage property for object Discount are missing, 1 is required', 500);
            }
Severity: Major
Found in src/builders/DiscountBuilder.php - About 40 mins to fix

Consider simplifying this complex logical expression.
Open

            if ((isset($discount['amount']) && ($discount['amount'] != null || $discount['amount'] != 0)) &&
                (isset($discount['percentage']) && ($discount['percentage'] != null || $discount['percentage'] != 0.0))
            ) {
                throw new InvalidSquareOrderException('Both $amount and $percentage exist for object Discount, only 1 is allowed', 500);
            }
Severity: Major
Found in src/builders/DiscountBuilder.php - About 40 mins to fix

Function buildProducts has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function buildProducts(Collection $products, string $currency): array
    {
        $temp = [];
        if ($products->isNotEmpty()) {
            foreach ($products as $product) {
Severity: Minor
Found in src/builders/SquareRequestBuilder.php - About 35 mins to fix

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 addProductFromArray has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function addProductFromArray(stdClass $orderCopy, Model $order, array $product, int $quantity): Product|stdClass
    {
        try {
            // Get quantity
            $tempQuantity = null;
Severity: Minor
Found in src/builders/ProductBuilder.php - About 35 mins to fix

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 $total->sum();
Severity: Major
Found in src/utils/Util.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return $totalDiscount;
Severity: Major
Found in src/utils/Util.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return false;
Severity: Major
Found in src/utils/Util.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return $totalTaxes;
Severity: Major
Found in src/utils/Util.php - About 30 mins to fix

Function addProductFromModel has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function addProductFromModel(Model $order, Model $product, int $quantity): Product|stdClass
    {
        try {
            // If quantity is null or 0
            if ($quantity == null || $quantity == 0) {
Severity: Minor
Found in src/builders/ProductBuilder.php - About 25 mins to fix

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 hasProduct has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public static function hasProduct(\Illuminate\Database\Eloquent\Collection|Collection $source, Product|int|array|null $product): bool
    {
        // Check if $product is either int, Model or array
        if (is_a($product, Product::class)) {
            return $source->contains($product);
Severity: Minor
Found in src/utils/Util.php - About 25 mins to fix

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 _saveOrder has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    private function _saveOrder(bool $saveToSquare = false): void
    {
        $this->order = $this->orderBuilder->buildOrderFromOrderCopy($this->getOrder(), $this->orderCopy);
        //If property locationId doesn't exist throw error
        if (! $this->locationId) {
Severity: Minor
Found in src/SquareService.php - About 25 mins to fix

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

Severity
Category
Status
Source
Language