Skip to content

Commit 17de0d6

Browse files
authored
Merge pull request #1 from shahruslan/code-analize
Code analizer
2 parents 5186e18 + 7e92e96 commit 17de0d6

18 files changed

+191
-46
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ indent_size = 2
1818
indent_style = space
1919
tab_width = 2
2020

21+
[composer.json]
22+
indent_size = 4
23+
tab_width = 4
2124

2225
[{*.yaml,*.yml}]
2326
indent_size = 2

.github/workflows/ci.yml

+12
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,20 @@ jobs:
3030
- name: Composer audit
3131
run: composer audit
3232

33+
- name: Composer normalize
34+
run: composer normalize --diff --dry-run
35+
3336
- name: Lint PHP files
3437
uses: overtrue/phplint@main
3538
with:
3639
path: .
3740
options: --exclude=vendor
41+
42+
- name: Php cs fixer
43+
run: composer phpcs
44+
45+
- name: Rector
46+
run: composer rector
47+
48+
- name: Psalm
49+
run: composer psalm

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.idea/
22
vendor/
3+
/var/
34
composer.lock
5+
.php-cs-fixer.php

.php-cs-fixer.dist.php

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
use PhpCsFixer\Config;
5+
use PhpCsFixer\Finder;
6+
use PHPyh\CodingStandard\PhpCsFixerCodingStandard;
7+
8+
$finder = (new Finder())
9+
->in([
10+
'./src',
11+
])
12+
->append([
13+
__FILE__,
14+
'./rector.php',
15+
]);
16+
17+
$config = (new Config())
18+
->setCacheFile('./var/php-cs-fixer.cache')
19+
->setFinder($finder);
20+
21+
(new PhpCsFixerCodingStandard())->applyTo($config, [
22+
'@PHP83Migration' => false,
23+
'@PHP81Migration' => true,
24+
'nullable_type_declaration_for_default_null_value' => false,
25+
'explicit_string_variable' => false,
26+
'native_function_invocation' => false,
27+
'global_namespace_import' => false,
28+
'blank_line_before_statement' => [
29+
'statements' => [
30+
'include',
31+
'include_once',
32+
'phpdoc',
33+
'require',
34+
'require_once',
35+
'switch',
36+
'try',
37+
'declare',
38+
],
39+
],
40+
'class_attributes_separation' => [
41+
'elements' => [
42+
'property' => 'none',
43+
],
44+
],
45+
]);
46+
47+
return $config;

composer.json

+27-11
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
11
{
22
"name": "shahruslan/production-calendar",
33
"description": "Производственный календарь",
4-
"type": "library",
54
"license": "MIT",
6-
"autoload": {
7-
"psr-4": {
8-
"Shahruslan\\ProductionCalendar\\": "src/"
9-
}
10-
},
5+
"type": "library",
116
"authors": [
127
{
138
"name": "Руслан Шихмагомедов",
149
"email": "[email protected]"
1510
}
1611
],
17-
"minimum-stability": "stable",
1812
"require": {
1913
"php": "^8.1",
20-
"psr/http-client": "^1.0",
21-
"psr/http-factory": "^1.0",
14+
"php-http/client-common": "^2.7",
2215
"php-http/discovery": "^1.19",
23-
"php-http/client-common": "^2.7"
16+
"psr/http-client": "^1.0",
17+
"psr/http-factory": "^1.0"
18+
},
19+
"require-dev": {
20+
"ergebnis/composer-normalize": "^2.44",
21+
"friendsofphp/php-cs-fixer": "^3.64",
22+
"phpyh/coding-standard": "^2.6",
23+
"rector/rector": "^1.2",
24+
"vimeo/psalm": "^5.26"
25+
},
26+
"minimum-stability": "stable",
27+
"autoload": {
28+
"psr-4": {
29+
"Shahruslan\\ProductionCalendar\\": "src/"
30+
}
2431
},
2532
"config": {
2633
"allow-plugins": {
34+
"ergebnis/composer-normalize": true,
2735
"php-http/discovery": true
28-
}
36+
},
37+
"sort-packages": true
38+
},
39+
"scripts": {
40+
"phpcs": "vendor/bin/php-cs-fixer check --diff",
41+
"phpcs-fix": "vendor/bin/php-cs-fixer fix --diff",
42+
"psalm": "vendor/bin/psalm --no-cache",
43+
"rector": "vendor/bin/rector process --dry-run",
44+
"rector-fix": "vendor/bin/rector process"
2945
}
3046
}

psalm.xml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="3"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
findUnusedBaselineEntry="true"
9+
findUnusedCode="true"
10+
>
11+
<projectFiles>
12+
<directory name="src" />
13+
<ignoreFiles>
14+
<directory name="vendor" />
15+
</ignoreFiles>
16+
</projectFiles>
17+
</psalm>

rector.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\ValueObject\PhpVersion;
7+
8+
return RectorConfig::configure()
9+
->withRootFiles()
10+
->withPaths([
11+
__DIR__ . '/src',
12+
])
13+
->withParallel()
14+
->withCache(__DIR__ . '/var/rector')
15+
->withPhpVersion(PhpVersion::PHP_81)
16+
->withPhpSets(php81: true);

src/Calendar.php

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Shahruslan\ProductionCalendar;
46

57
use DateTimeInterface;
@@ -17,6 +19,9 @@
1719
use Shahruslan\ProductionCalendar\Factory\Factory;
1820
use Shahruslan\ProductionCalendar\Validator\Validator;
1921

22+
/**
23+
* @api
24+
*/
2025
final class Calendar
2126
{
2227
private static string $host = 'https://production-calendar.ru';
@@ -52,17 +57,17 @@ private function request(string $url): string
5257
$response = $this->client->sendRequest($request);
5358

5459
if ($response->getStatusCode() >= 400) {
55-
throw new HttpException("Error executing request", $request, $response);
60+
throw new HttpException('Error executing request', $request, $response);
5661
}
5762

5863
return $response->getBody()->getContents();
5964
}
6065

6166
/**
6267
* Установить буквенный код страны для получения календаря.
63-
* В данный момент поддерживаются только ru и kz
68+
* В данный момент поддерживаются только ru и kz.
6469
*/
65-
public function setCountry(string $country): Calendar
70+
public function setCountry(string $country): self
6671
{
6772
$this->country = $country;
6873
return $this;
@@ -73,7 +78,7 @@ public function setCountry(string $country): Calendar
7378
* производственный календарь отличается). В качестве номера региона задается однозначные или двузначные коды ГИБДД.
7479
* Трехзначные не поддерживаются.
7580
*/
76-
public function setRegion(?int $region): Calendar
81+
public function setRegion(?int $region): self
7782
{
7883
$this->region = $region;
7984
return $this;
@@ -82,7 +87,7 @@ public function setRegion(?int $region): Calendar
8287
/**
8388
* Настройка расчета по 6-ти дневной рабочей недели. По умолчанию расчет идет по 5-дневной недели.
8489
*/
85-
public function setIsSixDayWeek(bool $isSixDayWeek): Calendar
90+
public function setIsSixDayWeek(bool $isSixDayWeek): self
8691
{
8792
$this->isSixDayWeek = $isSixDayWeek;
8893
return $this;
@@ -94,7 +99,7 @@ public function setIsSixDayWeek(bool $isSixDayWeek): Calendar
9499
* которые как бы есть, и одновременно которых как бы нет". Weekends of the Schrodinger. Так называемая отсылка к
95100
* всем известному коту Шредингера. По умолчанию параметр равен false, то есть подобные выходные не учитываются.
96101
*/
97-
public function setIsWeekendsOfSchrodinger(bool $isWeekendsOfSchrodinger): Calendar
102+
public function setIsWeekendsOfSchrodinger(bool $isWeekendsOfSchrodinger): self
98103
{
99104
$this->isWeekendsOfSchrodinger = $isWeekendsOfSchrodinger;
100105
return $this;
@@ -105,7 +110,7 @@ public function setIsWeekendsOfSchrodinger(bool $isWeekendsOfSchrodinger): Calen
105110
* дни, которые отличаются от обычного календаря. По умолчанию этот параметр равен false и календарь выдает все
106111
* сутки заданного периода.
107112
*/
108-
public function setIsCompact(bool $isCompact): Calendar
113+
public function setIsCompact(bool $isCompact): self
109114
{
110115
$this->isCompact = $isCompact;
111116
return $this;
@@ -118,8 +123,8 @@ public function setIsCompact(bool $isCompact): Calendar
118123
public function getPeriod(string $period): Period
119124
{
120125
$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';
123128

124129
$url = sprintf(
125130
'/get-period/%s/%s/%s/json?week_type=%d&wsch=%s&compact=%s',
@@ -132,7 +137,7 @@ public function getPeriod(string $period): Period
132137
);
133138

134139
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);
136141
$url .= "&region=$region";
137142
}
138143

@@ -175,7 +180,7 @@ public function getPeriodForMonth(int $year, int $month): Period
175180
{
176181
$this->validator->validateYear($year);
177182
$this->validator->validateMonth($month);
178-
$month = str_pad($month, 2, '0', STR_PAD_LEFT);
183+
$month = str_pad("$month", 2, '0', STR_PAD_LEFT);
179184
return $this->getPeriod("$month-$year");
180185
}
181186

src/Entity/Day.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Shahruslan\ProductionCalendar\Entity;
46

57
use DateTimeImmutable;
68
use Shahruslan\ProductionCalendar\Entity\Dictionary\DayType;
79
use Shahruslan\ProductionCalendar\Entity\Dictionary\WeekDay;
810

9-
class Day
11+
/**
12+
* @api
13+
*/
14+
final class Day
1015
{
1116
public function __construct(
1217
public readonly DateTimeImmutable $date,
1318
public readonly DayType $type,
1419
public readonly WeekDay $weekDay,
1520
public readonly int $workingHours,
16-
) {
17-
}
21+
) {}
1822
}

src/Entity/Dictionary/Country.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Shahruslan\ProductionCalendar\Entity\Dictionary;
46

5-
class Country
7+
/**
8+
* @api
9+
*/
10+
final class Country
611
{
712
public function __construct(
813
public readonly string $code,
914
public readonly string $text,
10-
) {
11-
}
15+
) {}
1216
}

src/Entity/Dictionary/DayType.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Shahruslan\ProductionCalendar\Entity\Dictionary;
46

57
enum DayType: string

src/Entity/Dictionary/Region.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Shahruslan\ProductionCalendar\Entity\Dictionary;
46

5-
class Region
7+
/**
8+
* @api
9+
*/
10+
final class Region
611
{
712
public function __construct(
813
public readonly int $number,
914
public readonly string $text,
10-
) {
11-
}
15+
) {}
1216
}

src/Entity/Dictionary/WeekDay.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Shahruslan\ProductionCalendar\Entity\Dictionary;
46

57
enum WeekDay: string

src/Entity/Period.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Shahruslan\ProductionCalendar\Entity;
46

57
use DateTimeImmutable;
68
use Shahruslan\ProductionCalendar\Entity\Dictionary\Country;
79
use Shahruslan\ProductionCalendar\Entity\Dictionary\Region;
810

9-
class Period
11+
/**
12+
* @api
13+
*/
14+
final class Period
1015
{
1116
/**
1217
* @param array<Day> $days
@@ -20,6 +25,5 @@ public function __construct(
2025
public readonly string $period,
2126
public readonly array $days,
2227
public readonly Statistic $statistic,
23-
) {
24-
}
28+
) {}
2529
}

0 commit comments

Comments
 (0)