Model::boot()   B
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 5
nop 0
dl 0
loc 27
rs 8.8657
c 0
b 0
f 0
1
<?php
2
3
namespace Transmissor\Models;
4
5
use Illuminate\Database\Eloquent\Model as EloquentModel;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Support\Facades\Hash;
8
use App\Sitec\Business;
9
use Auth;
10
11
class Model extends EloquentModel
12
{
13
    /**
14
     * Provides public access to get the raw attribute value from the model.
15
     * Used in areas where no mutations are required but performance is critical.
16
     *
17
     * @param  $key
18
     * @return mixed
19
     */
20
    public function getRawAttribute($key)
21
    {
22
        return parent::getAttributeFromArray($key);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getAttributeFromArray() instead of getRawAttribute()). Are you sure this is correct? If so, you might want to change this to $this->getAttributeFromArray().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
23
    }
24
25
    public static function boot()
26
    {
27
        parent::boot();
28
29
        if (isset(self::$organizationPerspective) && self::$organizationPerspective) {
30
31
            if(!$user = Auth::user()) {
32
                $user = Business::getViaParamsToken();
33
            }
34
35
            // Reduz o nivel global a nivel de Business
36
            if (!$user->isAdmin() || !Auth::check()) {
37
                static::addGlobalScope(
38
                    'user', function (Builder $builder) use ($user) {
39
                        $builder->where(self::getTableName().'.user_id', '=', $user->id);
40
                    }
41
                );
42
            }
43
44
            // Reduz o nivel de business a nivel de cliente da compania 
45
            // @todo
46
47
            // Reduz a nivel de Pessoa ()
48
            // @todo
49
        }
50
51
    }
52
}