Completed
Push — master ( f16f73...9ec25c )
by Giovanni
10:08
created

SpreadSheets::append()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace REverse\GSheets;
4
5
use REverse\GSheets\Operation\Append;
6
use REverse\GSheets\Operation\Clear;
7
use REverse\GSheets\Operation\Update;
8
9
class SpreadSheets
10
{
11
    /**
12
     * @var Client
13
     */
14
    private $client;
15
16
    /**
17
     * @var string
18
     */
19
    private $spreadSheetId;
20
21
    /**
22
     * @var string
23
     */
24
    private $range;
25
26
    /**
27
     * @param Client $client
28
     * @param string $spreadSheetId
29
     * @param string $range
30
     */
31
    public function __construct(Client $client, $spreadSheetId, $range = "")
32
    {
33
        $this->client = $client;
34
        $this->spreadSheetId = $spreadSheetId;
35
        $this->range = $range;
36
    }
37
38
    /**
39
     * @param Value $value
40
     * @param $range
41
     * @param $optParams
42
     *
43
     * @return self
44
     */
45
    public function update(Value $value, $range, $optParams)
46
    {
47
        $this->range = $range;
48
49
        (new Update($this))->execute($value, $this->range, $optParams);
50
51
        return $this;
52
    }
53
54
    /**
55
     * @param Value $value
56
     * @param $range
57
     * @param $optParams
58
     *
59
     * @return self
60
     */
61
    public function append(Value $value, $range, $optParams)
62
    {
63
        $this->range = $range;
64
65
        (new Append($this))->execute($value, $this->range, $optParams);
66
67
        return $this;
68
    }
69
70
    /**
71
     * @param $range
72
     *
73
     * @return self
74
     */
75
    public function clear($range)
76
    {
77
        $this->range = $range;
78
79
        (new Clear($this))->execute($this->range);
80
81
        return $this;
82
    }
83
84
    /**
85
     * @param Value $value
86
     * @param $sheet
87
     * @param $row
88
     * @param array $optParams
89
     *
90
     * @return self
91
     */
92
    public function updateRow(Value $value, $sheet, $row, $optParams = [])
93
    {
94
        $this->range = $this->declareRowRange($sheet, $row, $row);
95
96
        $this->update($value, $this->range, $optParams);
97
98
        return $this;
99
    }
100
101
    /**
102
     * @param string $sheet
103
     * @param string $row
104
     *
105
     * @return self
106
     */
107
    public function clearRow($sheet, $row)
108
    {
109
        $this->range = $this->declareRowRange($sheet, $row, $row);
0 ignored issues
show
Bug introduced by
$row of type string is incompatible with the type integer expected by parameter $rowStart of REverse\GSheets\SpreadSheets::declareRowRange(). ( Ignorable by Annotation )

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

109
        $this->range = $this->declareRowRange($sheet, /** @scrutinizer ignore-type */ $row, $row);
Loading history...
Bug introduced by
$row of type string is incompatible with the type integer expected by parameter $rowEnd of REverse\GSheets\SpreadSheets::declareRowRange(). ( Ignorable by Annotation )

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

109
        $this->range = $this->declareRowRange($sheet, $row, /** @scrutinizer ignore-type */ $row);
Loading history...
110
111
        $this->clear($this->range);
112
113
        return $this;
114
    }
115
116
    /**
117
     * @return Client
118
     */
119
    public function getClient()
120
    {
121
        return $this->client;
122
    }
123
124
    /**
125
     * @return string
126
     */
127
    public function getSpreadSheetId()
128
    {
129
        return $this->spreadSheetId;
130
    }
131
132
    /**
133
     * @param $range
134
     *
135
     * @return self
136
     */
137
    public function setRange($range)
138
    {
139
        $this->range = $range;
140
141
        return $this;
142
    }
143
144
    /**
145
     * Return last range used to write on spreadsheet
146
     *
147
     * @return string
148
     */
149
    public function getRange()
150
    {
151
        return $this->range;
152
    }
153
154
    /**
155
     * This method apply A1 notation to declare row range on sheet chosen
156
     *
157
     * @link https://developers.google.com/sheets/api/guides/concepts
158
     *
159
     * @param string $sheet
160
     * @param int $rowStart
161
     * @param int $rowEnd
162
     *
163
     * @return string
164
     */
165
    public function declareRowRange($sheet, $rowStart, $rowEnd)
166
    {
167
        return $sheet.'!'.$rowStart.':'.$rowEnd;
168
    }
169
}
170