Skip to content

Commit 1e02302

Browse files
committed
ci: added php_cs_fixer
1 parent 55fcabf commit 1e02302

File tree

11 files changed

+117
-52
lines changed

11 files changed

+117
-52
lines changed

.github/workflows/code_style.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Code style
2+
3+
on: [ push ]
4+
5+
jobs:
6+
php-cs-fixer:
7+
name: PHP-CS-Fixer
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
13+
- name: PHP-CS-Fixer
14+
uses: docker://oskarstark/php-cs-fixer-ga
15+
with:
16+
args: --allow-risky=yes --dry-run --diff --verbose

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.idea
33
.DS_Store
44
composer.lock
5+
.php-cs-fixer.cache

.php-cs-fixer.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use PhpCsFixer\Finder;
4+
use PhpCsFixer\Config;
5+
6+
$finder = Finder::create()
7+
->in([
8+
'src',
9+
'tests'
10+
]);
11+
12+
$config = new Config();
13+
14+
return $config
15+
->setRules([
16+
'@PSR12' => true,
17+
'strict_param' => true,
18+
'array_syntax' => ['syntax' => 'short'],
19+
'no_trailing_comma_in_singleline' => true,
20+
'no_unused_imports' => true,
21+
'trailing_comma_in_multiline' => [
22+
'elements' => ['arrays'],
23+
],
24+
'blank_line_before_statement' => ['statements' => ['return']],
25+
'braces' => [
26+
'position_after_functions_and_oop_constructs' => 'next',
27+
],
28+
'php_unit_construct' => true,
29+
'php_unit_method_casing' => true,
30+
'php_unit_mock_short_will_return' => true,
31+
'php_unit_test_annotation' => true,
32+
'php_unit_test_case_static_method_calls' => ['call_type' => 'this'],
33+
])
34+
->setFinder($finder);

Makefile

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
.SILENT:
22

3-
all: test
3+
DC = docker compose run --rm php
4+
5+
all: dependencies lint test
46

57
.PHONY: shell sh
68
shell sh:
7-
docker compose run --rm shell sh
9+
${DC} sh
10+
11+
.PHONY: dependencies
12+
dependencies:
13+
${DC} composer install --no-interaction
814

915
.PHONY: test
10-
test:
11-
docker compose run --rm shell ./vendor/bin/phpunit tests
16+
test: dependencies
17+
${DC} composer test
1218

1319
.PHONY: test-legacy
1420
test-legacy:
15-
docker compose run --rm test
21+
${DC} php /app/tests/test.php
1622

1723
.PHONY: build
1824
build:
1925
docker compose build
26+
27+
.PHONY: lint
28+
lint:
29+
${DC} composer lint:show
30+
31+
.PHONY: lint-fix
32+
lint-fix:
33+
${DC} composer lint:fix

composer.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@
1919
}
2020
],
2121
"require-dev": {
22-
"phpunit/phpunit": "^9.6"
22+
"phpunit/phpunit": "^9.6",
23+
"friendsofphp/php-cs-fixer": "^3.89"
24+
},
25+
"scripts": {
26+
"test": [
27+
"@test:unit"
28+
],
29+
"test:unit": "./vendor/bin/phpunit tests",
30+
"lint:fix": "./vendor/bin/php-cs-fixer fix --allow-risky=yes",
31+
"lint:show": "@lint:fix --dry-run --diff --verbose"
32+
},
33+
"config": {
34+
"platform": {
35+
"php": "7.4.1"
36+
}
2337
}
2438
}

docker-compose.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
services:
2-
shell:
2+
php:
33
build: .docker
4-
image: comagic-api-dev
5-
pull_policy: never
64
volumes:
75
- .:/app
8-
9-
test:
10-
build: .docker
11-
image: comagic-api-dev
12-
pull_policy: never
13-
volumes:
14-
- .:/app
15-
command: [
16-
"sh", "-c",
17-
"composer install --no-interaction && php /app/tests/test.php"
18-
]

src/CoMagic/CallApiClient.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace CoMagic;
46

@@ -27,8 +29,8 @@ public function __construct(CallApiConfig $config, ?Client $client = null)
2729
$this->client = $client ?? new Client([
2830
'headers' => [
2931
'Accept' => 'application/json',
30-
'Content-type' => 'application/json; charset=UTF-8'
31-
]
32+
'Content-type' => 'application/json; charset=UTF-8',
33+
],
3234
]);
3335

3436
$this->accessToken = $config->getAccessToken();
@@ -52,7 +54,7 @@ private function refreshAccessToken(): void
5254
'login.user',
5355
[
5456
'login' => $this->login,
55-
'password' => $this->password
57+
'password' => $this->password,
5658
]
5759
);
5860

src/CoMagic/CallApiConfig.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
namespace CoMagic;
46

src/CoMagic/RestApiClient.php

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ public function __construct($config)
5050
$this->_client = new Client([
5151
'base_uri' => $this->_entryPoint,
5252
'headers' => [
53-
'Accept' => 'application/json'
54-
]
53+
'Accept' => 'application/json',
54+
],
5555
]);
5656

57-
if (!empty($config['login']) && !empty($config['password']))
58-
{
57+
if (!empty($config['login']) && !empty($config['password'])) {
5958
$this->login($config['login'], $config['password']);
6059
}
6160
}
@@ -82,15 +81,15 @@ public function login($login, $password)
8281
$payload = [
8382
'form_params' => [
8483
'login' => $login,
85-
'password' => $password
86-
]
84+
'password' => $password,
85+
],
8786
];
8887

8988
$data = $this->_doRequest('login', $payload);
9089

91-
if (isset($data->session_key))
92-
{
90+
if (isset($data->session_key)) {
9391
$this->_sessionKey = $data->session_key;
92+
9493
return true;
9594
}
9695

@@ -109,18 +108,15 @@ public function __call($method, $arguments)
109108
{
110109
$payload = ['session_key' => $this->_sessionKey];
111110

112-
if (is_null($this->_sessionKey))
113-
{
111+
if (is_null($this->_sessionKey)) {
114112
throw new Exception('You are not logged in');
115113
}
116114

117-
if (!empty($arguments[0]))
118-
{
115+
if (!empty($arguments[0])) {
119116
$payload = array_merge($payload, $arguments[0]);
120117
}
121118

122-
if ($this->_mapMethod($method) === 'GET')
123-
{
119+
if ($this->_mapMethod($method) === 'GET') {
124120
$payload = ['query' => $payload];
125121
}
126122

@@ -137,8 +133,7 @@ public function __call($method, $arguments)
137133
*/
138134
private function _doRequest($method, $payload)
139135
{
140-
try
141-
{
136+
try {
142137
$response = $this->_client->request(
143138
$this->_mapMethod($method),
144139
$method . '/',
@@ -147,15 +142,12 @@ private function _doRequest($method, $payload)
147142

148143
$responseBody = json_decode($response->getBody());
149144

150-
if (!$responseBody->success)
151-
{
145+
if (!$responseBody->success) {
152146
throw new Exception($responseBody->message);
153147
}
154148

155149
return $responseBody->data;
156-
}
157-
catch (TransferException $e)
158-
{
150+
} catch (TransferException $e) {
159151
throw new Exception($e->getMessage());
160152
}
161153
}
@@ -168,8 +160,7 @@ private function _doRequest($method, $payload)
168160
*/
169161
private function _mapMethod($name)
170162
{
171-
switch ($name)
172-
{
163+
switch ($name) {
173164
case 'create_agent_customer':
174165
case 'create_site':
175166
case 'create_ac_condition_group':
@@ -189,4 +180,4 @@ private function _mapMethod($name)
189180
return 'GET';
190181
}
191182
}
192-
}
183+
}

tests/CallApiClientTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
24

35
use CoMagic\CallApiClient;
46
use CoMagic\CallApiConfig;
@@ -101,7 +103,7 @@ public function apiCallsProvider(): array
101103
[
102104
'tag_id' => 456,
103105
'tag_name' => 'Целевой',
104-
]
106+
],
105107
],
106108
'legs' => [
107109
[

0 commit comments

Comments
 (0)