Skip to content

Commit 9c79d96

Browse files
committed
Add coding standards
1 parent 1ba62fd commit 9c79d96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+534
-290
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ composer.lock
33
/vendor/
44
/AresRestApi-verejne.json
55
/coverage.html
6+
/var/

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,21 @@
3838
"nette/tester": "^2.4",
3939
"phpstan/phpstan": "^2.1",
4040
"phpstan/phpstan-strict-rules": "^2.0",
41+
"shipmonk/coding-standard": "^0.2",
4142
"tracy/tracy": "^2.9"
4243
},
4344
"config": {
4445
"sort-packages": true,
4546
"allow-plugins": {
47+
"dealerdirect/phpcodesniffer-composer-installer": true,
4648
"php-http/discovery": true
4749
}
4850
},
4951
"scripts": {
52+
"cbf": "vendor/bin/phpcbf",
5053
"coverage": "vendor/bin/tester --coverage coverage.html --coverage-src src/ --colors 1 -s -C tests/src",
51-
"qa": ["@tests", "@stan"],
54+
"cs": "vendor/bin/phpcs",
55+
"qa": ["@tests", "@cs", "@stan"],
5256
"stan": "vendor/bin/phpstan analyse",
5357
"tests": "vendor/bin/tester --colors 1 -s -C tests/src"
5458
},

phpcs.xml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0"?>
2+
<ruleset
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"
5+
>
6+
<arg name="basepath" value="."/>
7+
<arg name="cache" value="var/phpcs.cache"/>
8+
9+
<file>src/</file>
10+
<file>tests/</file>
11+
12+
<config name="installed_paths" value="vendor/slevomat/coding-standard,vendor/shipmonk/coding-standard"/>
13+
<rule ref="ShipMonkCodingStandard">
14+
<!-- tabs instead of spaces -->
15+
<exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
16+
<!-- allow PHPUnit annotations -->
17+
<exclude name="SlevomatCodingStandard.Commenting.ForbiddenAnnotations"/>
18+
</rule>
19+
20+
<!-- ForbiddenAnnotations without PHPUnit annotations -->
21+
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenAnnotations">
22+
<properties>
23+
<property name="forbiddenAnnotations" type="array">
24+
<element value="@author"/>
25+
<element value="@copyright"/>
26+
<element value="@internal-allowed-path"/>
27+
<element value="@internal-allowed-scope"/>
28+
<element value="@license"/>
29+
<element value="@link"/>
30+
<element value="@package"/>
31+
<element value="@phpstan-extends"/>
32+
<element value="@phpstan-implements"/>
33+
<element value="@phpstan-param"/>
34+
<element value="@phpstan-return"/>
35+
<element value="@phpstan-template"/>
36+
<element value="@phpstan-var"/>
37+
<element value="@psalm-param"/>
38+
<element value="@psalm-return"/>
39+
<element value="@psalm-template"/>
40+
<element value="@psalm-type"/>
41+
<element value="@psalm-var"/>
42+
<element value="@since"/>
43+
<element value="@version"/>
44+
</property>
45+
</properties>
46+
</rule>
47+
48+
<!-- tabs instead of spaces -->
49+
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
50+
51+
<!-- allow non-camelCase properties in Data.php (API response mapping) -->
52+
<rule ref="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps">
53+
<exclude-pattern>src/Ares/Core/Data.php</exclude-pattern>
54+
<exclude-pattern>src/Ares/Core/JsonToDataTransformer.php</exclude-pattern>
55+
<exclude-pattern>tests/src/Unit/Ares/Core/DataTest.php</exclude-pattern>
56+
<exclude-pattern>tests/src/E2E/Ares/CoreTest.php</exclude-pattern>
57+
</rule>
58+
<rule ref="Generic.WhiteSpace.ScopeIndent">
59+
<properties>
60+
<property name="tabIndent" value="true"/>
61+
</properties>
62+
</rule>
63+
</ruleset>

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ parameters:
88
ignoreErrors:
99
-
1010
message: "#^Variable property access on \\$this\\(h4kuna\\\\Ares\\\\Ares\\\\Core\\\\Data\\)\\.$#"
11-
count: 3
11+
count: 1
1212
path: src/Ares/Core/Data.php
1313
- '/Method h4kuna\\Ares\\Tests\\.*? throws checked exception .*? but it.s missing from the PHPDoc @throws tag\./'
1414

src/Adis/Client.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types=1);
1+
<?php declare(strict_types = 1);
22

33
namespace h4kuna\Ares\Adis;
44

@@ -11,17 +11,19 @@
1111
use h4kuna\Ares\Tool\Xml;
1212
use SimpleXMLElement;
1313
use stdClass;
14+
use function simplexml_load_string;
1415

1516
final class Client
1617
{
18+
1719
public static string $url = 'https://adisrws.mfcr.cz/adistc/axis2/services/rozhraniCRPDPH.rozhraniCRPDPHSOAP';
1820

1921
public function __construct(
2022
private TransportProvider $transportProvider,
21-
) {
23+
)
24+
{
2225
}
2326

24-
2527
/**
2628
* @param array<string, string> $chunk
2729
* @return list<stdClass>
@@ -30,7 +32,7 @@ public function __construct(
3032
*/
3133
public function statusBusinessSubjects(array $chunk): array
3234
{
33-
$xml = Envelope::StatusNespolehlivySubjektRozsireny(...$chunk);
35+
$xml = Envelope::statusNespolehlivySubjektRozsireny(...$chunk);
3436
$data = $this->request($xml, 'StatusNespolehlivySubjektRozsirenyResponse');
3537
$attributes = '@attributes';
3638

@@ -52,17 +54,25 @@ public function statusBusinessSubjects(array $chunk): array
5254
/**
5355
* @throws ServerResponseException
5456
*/
55-
private function request(string $xml, string $name): stdClass
57+
private function request(
58+
string $xml,
59+
string $name,
60+
): stdClass
5661
{
5762
$request = $this->transportProvider->createXmlRequest(self::$url, $xml);
5863
$response = $this->transportProvider->response($request);
5964
$xml = @simplexml_load_string($response->getBody()->getContents(), namespace_or_prefix: 'soapenv', is_prefix: true);
6065

61-
if ($xml === false || ($xml->Body->children()->$name instanceof SimpleXMLElement) === false) {
62-
throw ServerResponseException::badResponse(sprintf('Missing tag "%s" in response.', $name));
66+
if ($xml === false) {
67+
throw ServerResponseException::badResponse('Broken XML.');
68+
}
69+
70+
$body = $xml->Body; // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
71+
if (($body->children()->$name instanceof SimpleXMLElement) === false) {
72+
throw ServerResponseException::badResponse("Missing tag '{$name}' in response.");
6373
}
6474

65-
return Xml::toJson($xml->Body->children()->$name);
75+
return Xml::toJson($body->children()->$name);
6676
}
6777

6878
}

src/Adis/ContentProvider.php

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

33
namespace h4kuna\Ares\Adis;
44

@@ -12,11 +12,14 @@
1212

1313
final class ContentProvider
1414
{
15-
public function __construct(private Client $client, private StatusBusinessSubjectsTransformer $stdClassTransformer)
15+
16+
public function __construct(
17+
private Client $client,
18+
private StatusBusinessSubjectsTransformer $stdClassTransformer,
19+
)
1620
{
1721
}
1822

19-
2023
/**
2124
* @throws ServerResponseException
2225
*/
@@ -29,7 +32,6 @@ public function statusBusinessSubject(string $tin): Subject
2932
throw new LogicException('ADIS must return anything.');
3033
}
3134

32-
3335
/**
3436
* @param array<string, string> $tin
3537
* @return Generator<string, Subject>

src/Adis/Soap/Envelope.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
<?php declare(strict_types=1);
1+
<?php declare(strict_types = 1);
22

33
namespace h4kuna\Ares\Adis\Soap;
44

5+
use function implode;
6+
57
final class Envelope
68
{
9+
710
public static function seznamNespolehlivyPlatce(): string
811
{
912
return self::soap('<SeznamNespolehlivyPlatceRequest xmlns="http://adis.mfcr.cz/rozhraniCRPDPH/"></SeznamNespolehlivyPlatceRequest>');
@@ -19,8 +22,7 @@ public static function statusNespolehlivyPlatce(string ...$tin): string
1922
XML);
2023
}
2124

22-
23-
public static function StatusNespolehlivyPlatceRozsireny(string ...$tin): string
25+
public static function statusNespolehlivyPlatceRozsireny(string ...$tin): string
2426
{
2527
$dic = implode('</roz:dic><roz:dic>', $tin);
2628
return self::soapExtends(<<<XML
@@ -30,8 +32,7 @@ public static function StatusNespolehlivyPlatceRozsireny(string ...$tin): string
3032
XML);
3133
}
3234

33-
34-
public static function StatusNespolehlivySubjektRozsireny(string ...$tin): string
35+
public static function statusNespolehlivySubjektRozsireny(string ...$tin): string
3536
{
3637
$dic = implode('</roz:dic><roz:dic>', $tin);
3738
return self::soapExtends(<<<XML
@@ -52,7 +53,6 @@ private static function soap(string $body): string
5253
XML;
5354
}
5455

55-
5656
private static function soapExtends(string $body): string
5757
{
5858
return <<<XML
@@ -64,4 +64,5 @@ private static function soapExtends(string $body): string
6464
</soapenv:Envelope>
6565
XML;
6666
}
67+
6768
}

src/Adis/StatusBusinessSubjects/StatusBusinessSubjectsTransformer.php

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

33
namespace h4kuna\Ares\Adis\StatusBusinessSubjects;
44

55
use stdClass;
6+
use function rtrim;
67

78
class StatusBusinessSubjectsTransformer
89
{
@@ -31,7 +32,8 @@ public function transform(stdClass $data): Subject
3132
$exists && $isVatPayer ? $data->$attributes->nespolehlivyPlatce !== 'ANO' : null,
3233
$isVatPayer,
3334
$data->$attributes->cisloFu ?? '',
34-
$address
35+
$address,
3536
);
3637
}
38+
3739
}

src/Adis/StatusBusinessSubjects/Subject.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
<?php declare(strict_types=1);
1+
<?php declare(strict_types = 1);
22

33
namespace h4kuna\Ares\Adis\StatusBusinessSubjects;
44

55
use stdClass;
66

77
final class Subject
88
{
9+
910
public function __construct(
1011
public bool $exists,
1112
public string $type,
@@ -17,4 +18,5 @@ public function __construct(
1718
)
1819
{
1920
}
21+
2022
}

src/Ares.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
<?php declare(strict_types=1);
1+
<?php declare(strict_types = 1);
22

33
namespace h4kuna\Ares;
44

55
use Generator;
6-
use h4kuna\Ares\Ares\Core;
6+
use h4kuna\Ares\Adis\ContentProvider as AdisContentProvider;
7+
use h4kuna\Ares\Ares\Client as AresClient;
8+
use h4kuna\Ares\Ares\Core\ContentProvider as AresCoreContentProvider;
79
use h4kuna\Ares\Ares\Core\Data;
10+
use h4kuna\Ares\DataBox\ContentProvider as DataBoxContentProvider;
811
use h4kuna\Ares\Exception\AdisResponseException;
912
use h4kuna\Ares\Exception\IdentificationNumberNotFoundException;
1013
use h4kuna\Ares\Exception\ResultException;
1114
use h4kuna\Ares\Exception\ServerResponseException;
15+
use h4kuna\Ares\Vies\ContentProvider as ViesContentProvider;
1216
use h4kuna\Ares\Vies\ViesEntity;
1317
use stdClass;
1418

@@ -17,32 +21,35 @@
1721
*/
1822
class Ares
1923
{
24+
2025
public function __construct(
21-
public Core\ContentProvider $aresContentProvider,
22-
public DataBox\ContentProvider $dataBoxContentProvider,
23-
public Adis\ContentProvider $adisContentProvider,
24-
public Vies\ContentProvider $viesContentProvider,
25-
) {
26+
public AresCoreContentProvider $aresContentProvider,
27+
public DataBoxContentProvider $dataBoxContentProvider,
28+
public AdisContentProvider $adisContentProvider,
29+
public ViesContentProvider $viesContentProvider,
30+
)
31+
{
2632
}
2733

2834
/**
2935
* @deprecated use property
3036
*/
31-
public function getAdis(): Adis\ContentProvider
37+
public function getAdis(): AdisContentProvider
3238
{
3339
return $this->adisContentProvider;
3440
}
3541

36-
public function getAresClient(): Ares\Client
42+
public function getAresClient(): AresClient
3743
{
3844
return $this->aresContentProvider->getClient();
3945
}
4046

4147
/**
42-
* @template KeyName
4348
* @param array<KeyName, string|int> $identificationNumbers
4449
* @return Generator<(int&KeyName)|(KeyName&string), Data>
4550
*
51+
* @template KeyName
52+
*
4653
* @throws ResultException
4754
* @throws ServerResponseException
4855
*/
@@ -63,6 +70,7 @@ public function loadBasic(string $in): Data
6370

6471
/**
6572
* @return array<stdClass>
73+
*
6674
* @throws ResultException
6775
* @throws ServerResponseException
6876
*/

0 commit comments

Comments
 (0)