-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2.x] Adds strict types using Phpstan #44
base: main
Are you sure you want to change the base?
Changes from 24 commits
599b3fa
73eda21
0cf54f7
0d09824
171e06a
35a0d35
b5e5698
0c61aba
0b1fa6e
8f3e84f
88987d1
7b06d8b
cb1b4a4
09bc8f9
13aefb6
1258af2
8246b42
6beb17c
e49a07c
9620aa4
3845402
8cedaea
eec2612
5535309
d3f73ec
36b8689
e7a8131
a77ac8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
vendor/ | ||
composer.lock | ||
.php-cs-fixer.cache | ||
.phpunit.result.cache | ||
.phpunit.result.cache |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->in(__DIR__ . DIRECTORY_SEPARATOR . 'tests') | ||
->in(__DIR__ . DIRECTORY_SEPARATOR . 'src') | ||
->in('src') | ||
->in('tests') | ||
->append(['.php-cs-fixer.dist.php']); | ||
|
||
$rules = [ | ||
'@Symfony' => true, | ||
'declare_strict_types' => true, | ||
'phpdoc_no_empty_return' => false, | ||
'array_syntax' => ['syntax' => 'short'], | ||
'yoda_style' => false, | ||
'concat_space' => ['spacing' => 'one'], | ||
'not_operator_with_space' => false, | ||
'php_unit_method_casing' => ['case' => 'snake_case'], | ||
'increment_style' => ['style' => 'post'], | ||
'phpdoc_no_alias_tag' => false, | ||
'phpdoc_align' => [ | ||
'align' => 'vertical', | ||
'tags' => [ | ||
'param', | ||
'property', | ||
'property-read', | ||
'property-write', | ||
'return', | ||
'throws', | ||
'type', | ||
'var', | ||
'method', | ||
], | ||
], | ||
'final_class' => true, | ||
'global_namespace_import' => [ | ||
'import_classes' => true, | ||
], | ||
]; | ||
|
||
$rules['increment_style'] = ['style' => 'post']; | ||
|
||
return (new PhpCsFixer\Config()) | ||
->setUsingCache(true) | ||
->setRules($rules) | ||
->setFinder($finder); | ||
return (new PhpCsFixer\Config())->setFinder($finder)->setRules($rules); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,15 +14,17 @@ | |
} | ||
}, | ||
"require": { | ||
"php": "^7.4|^8.0", | ||
"php": "^8.0", | ||
"illuminate/support": "^8.16" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.4", | ||
"orchestra/testbench": "^6.5", | ||
"spatie/ray": "^1.17", | ||
"ext-soap": "*", | ||
"pestphp/pest": "^1.0" | ||
"pestphp/pest": "^1.0", | ||
"phpstan/phpstan": "^0.12.99", | ||
"friendsofphp/php-cs-fixer": "^3.2" | ||
}, | ||
"prefer-stable": true, | ||
"authors": [ | ||
|
@@ -35,10 +37,28 @@ | |
"email": "[email protected]" | ||
} | ||
], | ||
"scripts": { | ||
"lint": "./vendor/bin/php-cs-fixer fix --allow-risky=yes", | ||
"test:lint": "./vendor/bin/php-cs-fixer fix -v --dry-run --allow-risky=yes", | ||
"test:unit": "./vendor/bin/pest --exclude=integration", | ||
"test:integration": "./vendor/bin/pest --group=integration", | ||
"test:types": "./vendor/bin/phpstan analyse", | ||
"test:ci": [ | ||
"@test:lint", | ||
"@test:unit", | ||
"@test:integration", | ||
"@test:types" | ||
], | ||
"test": [ | ||
"@lint", | ||
"@test:ci" | ||
] | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"RicorocksDigitalAgency\\Soap\\Providers\\SoapServiceProvider" | ||
"RicorocksDigitalAgency\\Soap\\Providers\\SoapServiceProvider", | ||
"RicorocksDigitalAgency\\Soap\\Providers\\SoapRayServiceProvider" | ||
], | ||
"aliases": [ | ||
"RicorocksDigitalAgency\\Soap\\Facades\\Soap" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
parameters: | ||
paths: | ||
- src | ||
|
||
level: max |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RicorocksDigitalAgency\Soap\Contracts; | ||
|
||
interface Builder | ||
{ | ||
/** | ||
* @param array<array<mixed>|Soapable>|Soapable $parameters | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function handle(array|Soapable $parameters): array; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RicorocksDigitalAgency\Soap\Contracts\PhpSoap; | ||
|
||
use SoapHeader; | ||
|
||
interface Client | ||
{ | ||
public function setEndpoint(string $endpoint): static; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if the setters in this interface are a good idea though. See further down this code review - it allows for some strange structures. |
||
|
||
/** | ||
* @param array<string, mixed> $options | ||
*/ | ||
public function setOptions(array $options): static; | ||
|
||
/** | ||
* Set the given headers on the request. | ||
* | ||
* @param array<int, SoapHeader> $headers | ||
*/ | ||
public function setHeaders(array $headers): static; | ||
|
||
/** | ||
* Make a request and return its response. | ||
*/ | ||
public function call(string $method, mixed $body): mixed; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe better to change
It allows for multi-params requests (see #45) |
||
|
||
/** | ||
* Get an array of supported SOAP functions. | ||
* | ||
* @return array<int, string> | ||
*/ | ||
public function getFunctions(): array; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our php-soap engine returns more information about the functions than a regular string. We could parse them back to a regular int, string - but it means you will loose some information. |
||
|
||
public function __getLastRequest(): ?string; | ||
|
||
public function __getLastResponse(): ?string; | ||
|
||
public function __getLastRequestHeaders(): ?string; | ||
|
||
public function __getLastResponseHeaders(): ?string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RicorocksDigitalAgency\Soap\Contracts; | ||
|
||
use RicorocksDigitalAgency\Soap\Response\Response; | ||
use RicorocksDigitalAgency\Soap\Support\Header; | ||
|
||
interface Request | ||
{ | ||
public function to(string $endpoint): self; | ||
|
||
/** | ||
* @param array<mixed> $parameters | ||
* | ||
* @return mixed | ||
*/ | ||
public function __call(string $name, array $parameters); | ||
|
||
/** | ||
* @return array<int, string> | ||
*/ | ||
public function functions(): array; | ||
|
||
/** | ||
* @param array<string, mixed>|Soapable $body | ||
*/ | ||
public function call(string $method, array|Soapable $body = []): Response; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as for the Client contract : it is better to make it an array of parameters imo or a variadic |
||
|
||
/** | ||
* @param callable(Request): mixed ...$closures | ||
*/ | ||
public function beforeRequesting(callable ...$closures): self; | ||
|
||
/** | ||
* @param callable(Request, Response): mixed ...$closures | ||
*/ | ||
public function afterRequesting(callable ...$closures): self; | ||
|
||
/** | ||
* @param callable(Request): Response|Response|null $response | ||
*/ | ||
public function fakeUsing(callable|Response|null $response): self; | ||
|
||
public function getEndpoint(): string; | ||
|
||
public function getMethod(): string; | ||
|
||
/** | ||
* @return array<string, mixed>|Soapable | ||
*/ | ||
public function getBody(): array|Soapable; | ||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
public function getOptions(): array; | ||
|
||
public function set(string $key, mixed $value): self; | ||
|
||
public function trace(bool $shouldTrace = true): self; | ||
|
||
/** | ||
* @param array<string, mixed> $options | ||
*/ | ||
public function withOptions(array $options): self; | ||
|
||
public function withBasicAuth(string $login, string $password): self; | ||
|
||
public function withDigestAuth(string $login, string $password): self; | ||
|
||
public function withHeaders(Header ...$headers): self; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This request is a bit shaped around the existing soap client. |
||
/** | ||
* @return array<int, Header> | ||
*/ | ||
public function getHeaders(): array; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RicorocksDigitalAgency\Soap\Contracts; | ||
|
||
interface Soapable | ||
{ | ||
public function toSoap(); | ||
public function toSoap(): mixed; | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure it is possible to create a client using phpro/soap-client that implements this interface.