Issues (21)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Traits/Taxable.php (8 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace FeiMx\Tax\Traits;
4
5
use FeiMx\Tax\Exceptions\TaxErrorException;
6
use FeiMx\Tax\Models\TaxGroup;
7
use Illuminate\Database\Eloquent\Relations\MorphToMany;
8
9
trait Taxable
10
{
11
    /**
12
     * Column name used for get the price of the model.
13
     *
14
     * @return string Column name
15
     */
16
    public static function priceColumn()
17
    {
18
        return 'price';
19
    }
20
21
    /**
22
     * [taxGroups description].
23
     *
24
     * @return [type] [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
25
     */
26
    public function taxGroups(): MorphToMany
27
    {
28
        return $this->morphToMany(
0 ignored issues
show
It seems like morphToMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
29
            TaxGroup::class,
30
            'model',
31
            'model_has_tax_groups',
32
            'model_id',
33
            'tax_group_id'
34
        );
35
    }
36
37
    public function hasTaxGroups()
38
    {
39
        return (bool) $this->taxGroups->count();
0 ignored issues
show
The property taxGroups does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
40
    }
41
42
    /**
43
     * Determine if the model has (one of) the given tax group(s).
44
     *
45
     * @param string|array|\FeiMx\Tax\Models\TaxGroup|\Illuminate\Support\Collection $taxGroups
46
     *
47
     * @return bool
48
     */
49
    public function hasTaxGroup($taxGroups)
50
    {
51
        if (is_string($taxGroups)) {
52
            return $this->taxGroups->contains('name', $taxGroups);
53
        }
54
        if ($taxGroups instanceof TaxGroup) {
55
            return $this->taxGroups->contains('id', $taxGroups->id);
56
        }
57
        if (is_array($taxGroups)) {
58
            foreach ($taxGroups as $taxGroup) {
59
                if ($this->hasTaxGroup($taxGroup)) {
60
                    return true;
61
                }
62
            }
63
64
            return false;
65
        }
66
67
        return $taxGroups->intersect($this->taxGroups)->isNotEmpty();
68
    }
69
70
    /**
71
     * Assign the given taxGroup to the model.
72
     *
73
     * @param array|string|\FeiMx\Tax\Models\TaxGroup ...$taxGroups
74
     *
75
     * @return $this
76
     */
77
    public function assignTaxGroup(...$taxGroups)
78
    {
79
        if (0 == count($taxGroups)) {
80
            throw new TaxErrorException('You must pass a valid TaxGroup');
81
        }
82
83
        $taxGroups = collect($taxGroups)
84
            ->flatten()
85
            ->map(function ($taxGroup) {
86
                return $this->getStoredTaxGroup($taxGroup);
87
            })
88
            ->all();
89
90
        $this->taxGroups()->saveMany($taxGroups);
91
92
        return $this;
93
    }
94
95
    /**
96
     * Revoke the given role from the model.
97
     *
98
     * @param string|\FeiMx\Tax\Models\TaxGroup $taxGroup
99
     */
100
    public function removeTaxGroup($taxGroup)
101
    {
102
        $this->taxGroups()->detach($this->getStoredTaxGroup($taxGroup));
103
    }
104
105
    /**
106
     * Remove all current tax groups and set the given ones.
107
     *
108
     * @param array|\FeiMx\Tax\Models\TaxGroup|string ...$taxGroups
109
     *
110
     * @return $this
111
     */
112
    public function syncTaxGroups(...$taxGroups)
113
    {
114
        $this->taxGroups()->detach();
115
116
        return $this->assignTaxGroup($taxGroups);
117
    }
118
119
    /**
120
     * Get total amount for current TaxGroup.
121
     *
122
     * @param \FeiMx\Tax\Models\TaxGroup|string $taxGroup
123
     *
124
     * @return $total
0 ignored issues
show
The doc-type $total could not be parsed: Unknown type name "$total" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
125
     */
126 View Code Duplication
    public function total($taxGroup = null)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
127
    {
128
        if (null === $taxGroup) {
129
            throw new TaxErrorException('You must pass a valid TaxGroup');
130
        }
131
132
        $taxGroup = $this->getStoredTaxGroup($taxGroup);
133
        $column = self::priceColumn();
134
135
        return $total = $taxGroup->taxManager($this->{$column})
0 ignored issues
show
$total is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
136
            ->addTaxes(
137
                $taxGroup->taxes->map(function ($tax) {
138
                    return $tax->info();
139
                })
140
                ->all()
141
            )
142
            ->total();
143
    }
144
145
    /**
146
     * Get a list of taxes with amount calculated for the given TaxGroup.
147
     *
148
     * @param \FeiMx\Tax\Models\TaxGroup|string $taxGroup
149
     *
150
     * @return $total
0 ignored issues
show
The doc-type $total could not be parsed: Unknown type name "$total" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
151
     */
152 View Code Duplication
    public function getAmounts($taxGroup = null)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
153
    {
154
        if (null === $taxGroup) {
155
            throw new TaxErrorException('You must pass a valid TaxGroup');
156
        }
157
158
        $taxGroup = $this->getStoredTaxGroup($taxGroup);
159
        $column = self::priceColumn();
160
161
        return $taxGroup->taxManager($this->{$column})
162
            ->addTaxes(
163
                $taxGroup->taxes->map(function ($tax) {
164
                    return $tax->info();
165
                })
166
                ->all()
167
            )
168
            ->get();
169
    }
170
171
    protected function getStoredTaxGroup($taxGroup): TaxGroup
172
    {
173
        if (is_numeric($taxGroup)) {
174
            return TaxGroup::find($taxGroup);
175
        }
176
        if (is_string($taxGroup)) {
177
            return TaxGroup::whereName($taxGroup)->first();
178
        }
179
180
        return $taxGroup;
181
    }
182
}
183