NikolaGavric94/laravel-square

View on GitHub

Showing 41 of 41 total issues

Function buildOrderFromOrderCopy has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
Open

    public function buildOrderFromOrderCopy(Model $order, stdClass $orderCopy): Model
    {
        // Order namespace
        $orderClass = config('nikolag.connections.square.order.namespace');
        // Set payment type to square
Severity: Minor
Found in src/builders/OrderBuilder.php - About 7 hrs 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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

            if (($parent && ! $parent->hasTax($tax)) || ! Arr::has($tax, 'id')) {
                $tempTax = new Tax($tax);
            } else {
                // Load tax with pivot
                if (Arr::has($tax, 'pivot')) {
Severity: Major
Found in src/builders/TaxesBuilder.php and 1 other location - About 4 hrs to fix
src/builders/DiscountBuilder.php on lines 47..59

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 171.

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

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

            if (($parent && ! $parent->hasDiscount($discount)) || ! Arr::has($discount, 'id')) {
                $tempDiscount = new Discount($discount);
            } else {
                // Load discount with pivot
                if (Arr::has($discount, 'pivot')) {
Severity: Major
Found in src/builders/DiscountBuilder.php and 1 other location - About 4 hrs to fix
src/builders/TaxesBuilder.php on lines 37..49

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 171.

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

Further Reading

Function buildDiscounts has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

    public function buildDiscounts(Collection $discounts, string $currency): array
    {
        $temp = [];
        if ($discounts->isNotEmpty()) {
            foreach ($discounts as $discount) {
Severity: Minor
Found in src/builders/SquareRequestBuilder.php - About 4 hrs 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 createDiscounts has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

    public function createDiscounts(array $discounts, string $scope, Model $parent = null): Collection
    {
        $temp = collect([]);
        foreach ($discounts as $discount) {
            //If discount doesn't have amount AND percentage in discounts table
Severity: Minor
Found in src/builders/DiscountBuilder.php - About 3 hrs 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 buildOrderCopyFromArray has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    public function buildOrderCopyFromArray(array $order): stdClass
    {
        try {
            $orderCopy = new stdClass();
            // Create taxes Collection
Severity: Minor
Found in src/builders/OrderBuilder.php - About 3 hrs 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

File SquareService.php has 284 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Nikolag\Square;

use Nikolag\Core\Abstracts\CorePaymentService;
Severity: Minor
Found in src/SquareService.php - About 2 hrs to fix

Function buildOrderCopyFromModel has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    public function buildOrderCopyFromModel(Model $order): stdClass
    {
        try {
            $orderCopy = new stdClass();
            // Create taxes Collection
Severity: Minor
Found in src/builders/OrderBuilder.php - About 2 hrs 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 68 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function charge(array $options): Transaction
    {
        $location_id = array_key_exists('location_id', $options) ? $options['location_id'] : null;
        $currency = array_key_exists('currency', $options) ? $options['currency'] : 'USD';
        $prepData = [
Severity: Major
Found in src/SquareService.php - About 2 hrs to fix

Function createTaxes has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    public function createTaxes(array $taxes, string $scope, Model $parent = null): Collection
    {
        $temp = collect([]);
        foreach ($taxes as $tax) {
            //If percentage doesn't exist on a taxes table
Severity: Minor
Found in src/builders/TaxesBuilder.php - About 2 hrs 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 buildOrderFromOrderCopy has 61 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function buildOrderFromOrderCopy(Model $order, stdClass $orderCopy): Model
    {
        // Order namespace
        $orderClass = config('nikolag.connections.square.order.namespace');
        // Set payment type to square
Severity: Major
Found in src/builders/OrderBuilder.php - About 2 hrs to fix

Function charge has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    public function charge(array $options): Transaction
    {
        $location_id = array_key_exists('location_id', $options) ? $options['location_id'] : null;
        $currency = array_key_exists('currency', $options) ? $options['currency'] : 'USD';
        $prepData = [
Severity: Minor
Found in src/SquareService.php - About 2 hrs 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 buildTaxes has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    public function buildTaxes(Collection $taxes): array
    {
        $temp = [];
        if ($taxes->isNotEmpty()) {
            foreach ($taxes as $tax) {
Severity: Minor
Found in src/builders/SquareRequestBuilder.php - About 1 hr 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 buildOrderCopyFromModel has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function buildOrderCopyFromModel(Model $order): stdClass
    {
        try {
            $orderCopy = new stdClass();
            // Create taxes Collection
Severity: Minor
Found in src/builders/OrderBuilder.php - About 1 hr to fix

Method buildOrderCopyFromArray has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function buildOrderCopyFromArray(array $order): stdClass
    {
        try {
            $orderCopy = new stdClass();
            // Create taxes Collection
Severity: Minor
Found in src/builders/OrderBuilder.php - About 1 hr to fix

Method buildDiscounts has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function buildDiscounts(Collection $discounts, string $currency): array
    {
        $temp = [];
        if ($discounts->isNotEmpty()) {
            foreach ($discounts as $discount) {
Severity: Minor
Found in src/builders/SquareRequestBuilder.php - About 1 hr to fix

Similar blocks of code found in 2 locations. Consider refactoring.
Open

                    if ($product->pivot->taxes->isNotEmpty()) {
                        $productTemp->taxes = $this->taxesBuilder->createTaxes($product->pivot->taxes->toArray(), Constants::DEDUCTIBLE_SCOPE_ORDER, $productTemp->productPivot);

                        // Check for any taxes that are missing on order level
                        $missingTaxes = $productTemp->taxes->reject(function ($tax) use ($orderCopy) {
Severity: Major
Found in src/builders/OrderBuilder.php and 1 other location - About 1 hr to fix
src/builders/OrderBuilder.php on lines 204..216

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 109.

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

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

                    if ($product->pivot->discounts->isNotEmpty()) {
                        $productTemp->discounts = $this->discountBuilder->createDiscounts($product->pivot->discounts->toArray(), Constants::DEDUCTIBLE_SCOPE_PRODUCT, $productTemp->pivot);

                        // Check for any discounts that are missing on order level
                        $missingDiscounts = $productTemp->discounts->reject(function ($discount) use ($orderCopy) {
Severity: Major
Found in src/builders/OrderBuilder.php and 1 other location - About 1 hr to fix
src/builders/OrderBuilder.php on lines 188..200

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 109.

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

Further Reading

Method addProductFromArray has 35 lines of code (exceeds 25 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 1 hr to fix

Method createDiscounts has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function createDiscounts(array $discounts, string $scope, Model $parent = null): Collection
    {
        $temp = collect([]);
        foreach ($discounts as $discount) {
            //If discount doesn't have amount AND percentage in discounts table
Severity: Minor
Found in src/builders/DiscountBuilder.php - About 1 hr to fix
Severity
Category
Status
Source
Language