1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace Shahruslan \ProductionCalendar ;
4
6
5
7
use DateTimeInterface ;
17
19
use Shahruslan \ProductionCalendar \Factory \Factory ;
18
20
use Shahruslan \ProductionCalendar \Validator \Validator ;
19
21
22
+ /**
23
+ * @api
24
+ */
20
25
final class Calendar
21
26
{
22
27
private static string $ host = 'https://production-calendar.ru ' ;
@@ -52,17 +57,17 @@ private function request(string $url): string
52
57
$ response = $ this ->client ->sendRequest ($ request );
53
58
54
59
if ($ response ->getStatusCode () >= 400 ) {
55
- throw new HttpException (" Error executing request " , $ request , $ response );
60
+ throw new HttpException (' Error executing request ' , $ request , $ response );
56
61
}
57
62
58
63
return $ response ->getBody ()->getContents ();
59
64
}
60
65
61
66
/**
62
67
* Установить буквенный код страны для получения календаря.
63
- * В данный момент поддерживаются только ru и kz
68
+ * В данный момент поддерживаются только ru и kz.
64
69
*/
65
- public function setCountry (string $ country ): Calendar
70
+ public function setCountry (string $ country ): self
66
71
{
67
72
$ this ->country = $ country ;
68
73
return $ this ;
@@ -73,7 +78,7 @@ public function setCountry(string $country): Calendar
73
78
* производственный календарь отличается). В качестве номера региона задается однозначные или двузначные коды ГИБДД.
74
79
* Трехзначные не поддерживаются.
75
80
*/
76
- public function setRegion (?int $ region ): Calendar
81
+ public function setRegion (?int $ region ): self
77
82
{
78
83
$ this ->region = $ region ;
79
84
return $ this ;
@@ -82,7 +87,7 @@ public function setRegion(?int $region): Calendar
82
87
/**
83
88
* Настройка расчета по 6-ти дневной рабочей недели. По умолчанию расчет идет по 5-дневной недели.
84
89
*/
85
- public function setIsSixDayWeek (bool $ isSixDayWeek ): Calendar
90
+ public function setIsSixDayWeek (bool $ isSixDayWeek ): self
86
91
{
87
92
$ this ->isSixDayWeek = $ isSixDayWeek ;
88
93
return $ this ;
@@ -94,7 +99,7 @@ public function setIsSixDayWeek(bool $isSixDayWeek): Calendar
94
99
* которые как бы есть, и одновременно которых как бы нет". Weekends of the Schrodinger. Так называемая отсылка к
95
100
* всем известному коту Шредингера. По умолчанию параметр равен false, то есть подобные выходные не учитываются.
96
101
*/
97
- public function setIsWeekendsOfSchrodinger (bool $ isWeekendsOfSchrodinger ): Calendar
102
+ public function setIsWeekendsOfSchrodinger (bool $ isWeekendsOfSchrodinger ): self
98
103
{
99
104
$ this ->isWeekendsOfSchrodinger = $ isWeekendsOfSchrodinger ;
100
105
return $ this ;
@@ -105,7 +110,7 @@ public function setIsWeekendsOfSchrodinger(bool $isWeekendsOfSchrodinger): Calen
105
110
* дни, которые отличаются от обычного календаря. По умолчанию этот параметр равен false и календарь выдает все
106
111
* сутки заданного периода.
107
112
*/
108
- public function setIsCompact (bool $ isCompact ): Calendar
113
+ public function setIsCompact (bool $ isCompact ): self
109
114
{
110
115
$ this ->isCompact = $ isCompact ;
111
116
return $ this ;
@@ -118,8 +123,8 @@ public function setIsCompact(bool $isCompact): Calendar
118
123
public function getPeriod (string $ period ): Period
119
124
{
120
125
$ weekType = $ this ->isSixDayWeek ? 6 : 5 ;
121
- $ wsch = $ this ->isWeekendsOfSchrodinger ? '1 ' : '0 ' ;
122
- $ isCompact = $ this ->isCompact ? '1 ' : '0 ' ;
126
+ $ wsch = $ this ->isWeekendsOfSchrodinger ? '1 ' : '0 ' ;
127
+ $ isCompact = $ this ->isCompact ? '1 ' : '0 ' ;
123
128
124
129
$ url = sprintf (
125
130
'/get-period/%s/%s/%s/json?week_type=%d&wsch=%s&compact=%s ' ,
@@ -132,7 +137,7 @@ public function getPeriod(string $period): Period
132
137
);
133
138
134
139
if ($ this ->region !== null ) {
135
- $ region = str_pad ($ this ->region , 2 , '0 ' , STR_PAD_LEFT );
140
+ $ region = str_pad (" $ this ->region " , 2 , '0 ' , STR_PAD_LEFT );
136
141
$ url .= "®ion= $ region " ;
137
142
}
138
143
@@ -175,7 +180,7 @@ public function getPeriodForMonth(int $year, int $month): Period
175
180
{
176
181
$ this ->validator ->validateYear ($ year );
177
182
$ this ->validator ->validateMonth ($ month );
178
- $ month = str_pad ($ month , 2 , '0 ' , STR_PAD_LEFT );
183
+ $ month = str_pad (" $ month" , 2 , '0 ' , STR_PAD_LEFT );
179
184
return $ this ->getPeriod ("$ month- $ year " );
180
185
}
181
186
0 commit comments