Retailer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TarfinLabs\Iys;
4
5
class Retailer
6
{
7
    protected $endpoint;
8
    protected $config;
9
10
    public function __construct()
11
    {
12
        $this->config = config('laravel-iys');
13
        $this->endpoint = "/sps/{$this->config['iys_code']}/brands/{$this->config['brand_code']}/retailers";
14
    }
15
16
    /**
17
     * Hizmet sağlayıcı markasının altına bayi ekler.
18
     *
19
     * Doc: https://dev.iys.org.tr/api-metotlar/bayi-yonetimi/bayi-ekleme/
20
     *
21
     * @param array $params
22
     * @return array|mixed
23
     */
24
    public function create(array $params)
25
    {
26
        return app(Client::class)->postJson($this->endpoint, $params);
27
    }
28
29
    /**
30
     * Hizmet sağlayıcı markasının altındaki tüm bayileri listeler.
31
     *
32
     * Doc: https://dev.iys.org.tr/api-metotlar/bayi-yonetimi/bayi-sorgulama-listeleme/
33
     *
34
     * @param int|null $offset
35
     * @param int|null $limit
36
     * @return array|mixed
37
     */
38
    public function all(int $offset = null, int $limit = null)
39
    {
40
        $params = [];
41
42
        if ($offset && $limit) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $offset of type null|integer is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
Bug Best Practice introduced by
The expression $limit of type null|integer is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
43
            $params = [
44
                'offset' => $offset,
45
                'limit' => $limit,
46
            ];
47
        }
48
49
        return app(Client::class)->getJson($this->endpoint, $params);
50
    }
51
52
    /**
53
     * İys numarası verilen bayinin bilgilerini getirir.
54
     *
55
     * @param int $retailerCode
56
     * @return array|mixed
57
     */
58
    public function find(int $retailerCode)
59
    {
60
        return app(Client::class)->getJson($this->endpoint . '/' . $retailerCode);
61
    }
62
63
    /**
64
     * Hizmet sağlayıcı markasının altındaki bayiyi siler.
65
     *
66
     * Doc: https://dev.iys.org.tr/api-metotlar/bayi-yonetimi/bayi-silme/
67
     *
68
     * @param int $retailerCode
69
     * @return array|mixed
70
     */
71
    public function delete(int $retailerCode)
72
    {
73
        return app(Client::class)->deleteJson($this->endpoint . '/' . $retailerCode);
74
    }
75
}
76