ClientRepository::selectAllByBillClientAddress()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php 
2
3
namespace Hideyo\Ecommerce\Framework\Services\Client\Entity;
4
5
use Hideyo\Ecommerce\Framework\Services\Client\Entity\Client;
6
use Hideyo\Ecommerce\Framework\Services\Client\Entity\ClientAddressRepository;
7
use Hideyo\Ecommerce\Framework\Services\BaseRepository;
8
9
class ClientRepository extends BaseRepository 
10
{
11
    protected $model;
12
13
    public function __construct(Client $model, ClientAddressRepository $clientAddress)
14
    {
15
        $this->model = $model;
16
        $this->clientAddress = $clientAddress;
0 ignored issues
show
Bug Best Practice introduced by
The property clientAddress does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
17
    }
18
19
    public function selectAll()
20
    {
21
        return $this->model->where('shop_id', auth('hideyobackend')->user()->selected_shop_id)->get();
0 ignored issues
show
Bug introduced by
Accessing selected_shop_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
22
    }
23
24
    public function selectAllByBillClientAddress()
25
    {
26
        return $this->model->selectRaw('CONCAT(client_address.firstname, " ", client_address.lastname) as fullname, client_address.*, client.id')
27
        ->leftJoin('client_address', 'client.bill_client_address_id', '=', 'client_address.id')->where('shop_id', auth('hideyobackend')->user()->selected_shop_id)
0 ignored issues
show
Bug introduced by
Accessing selected_shop_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
28
        ->get();
29
    }
30
31
    public function findByEmail($email, $shopId)
32
    {
33
        return $this->model->where('shop_id', $shopId)->where('email', '=', $email)->get()->first();
34
    }
35
36
    public function checkEmailByShopIdAndNoAccountCreated($email, $shopId) {
37
        return $this->model->where('shop_id', $shopId)->whereNotNull('account_created')->where('email', '=', $email)->get()->first();
38
    }
39
40
    public function checkEmailByShopId($email, $shopId)
41
    {
42
        return $this->model->where('shop_id', $shopId)->where('email', '=', $email)->get()->first();
43
    }
44
45
    public function validateRegisterNoAccount(array $attributes, $shopId)
46
    {
47
        $client = $this->model->where('shop_id', $shopId)->where('email', '=', $attributes['email'])->get()->first();
48
49
        if ($client) {
50
            return false;
51
        }
52
53
        return true;
54
    }
55
56
    public function selectOneByShopIdAndId($shopId, $clientId)
57
    {
58
        return $this->model->with(array('clientAddress', 'clientDeliveryAddress', 'clientBillAddress'))->where('shop_id', $shopId)->where('active', 1)->where('id', '=', $clientId)->first();
59
    }
60
61
    public function selectOneById($clientId)
62
    {
63
        return $this->model->with(array('clientAddress', 'clientDeliveryAddress', 'clientBillAddress'))->where('shop_id', auth('hideyobackend')->user()->selected_shop_id)->where('active', 1)->where('id', '=', $clientId)->first();
0 ignored issues
show
Bug introduced by
Accessing selected_shop_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
64
    }
65
66
    public function getClientByConfirmationCode($shopId, $email, $confirmationCode)
67
    {
68
        return $this->model->where('shop_id', $shopId)->where('email', '=', $email)->where('confirmation_code', '=', $confirmationCode)->get()->first();
69
    }
70
71
    public function validateConfirmationCodeByConfirmationCodeAndEmail($confirmationCode, $email, $shopId)
72
    {
73
        return $this->model
74
        ->where('shop_id', $shopId)
75
        ->where('email', '=', $email)
76
        ->whereNotNull('account_created')
77
        ->where('confirmation_code', '=', $confirmationCode)
78
        ->get()->first();
79
    }
80
81
    public function validateConfirmationCodeByConfirmationCodeAndNewEmail($confirmationCode, $newEmail, $shopId)
82
    {
83
        return $this->model
84
        ->where('shop_id', $shopId)
85
        ->where('new_email', '=', $newEmail)
86
        ->whereNotNull('account_created')
87
        ->where('confirmation_code', '=', $confirmationCode)
88
        ->get()->first();
89
    }
90
91
    public function selectAllExport()
92
    {
93
        return $this->model->with(array('clientAddress', 'clientDeliveryAddress', 'clientBillAddress'))->whereNotNull('account_created')->where('active', 1)->where('shop_id', auth('hideyobackend')->user()->selected_shop_id)->get();
0 ignored issues
show
Bug introduced by
Accessing selected_shop_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
94
    }
95
96
    public function editAddress($shopId, $clientId, $addressId, $attributes)
97
    {
98
        return $this->clientAddress->updateByIdAndShopId($shopId, $attributes, $clientId, $addressId);
0 ignored issues
show
Bug introduced by
The method updateByIdAndShopId() does not exist on Hideyo\Ecommerce\Framewo...ClientAddressRepository. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

98
        return $this->clientAddress->/** @scrutinizer ignore-call */ updateByIdAndShopId($shopId, $attributes, $clientId, $addressId);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
99
    }
100
}
101