Skip to content

Commit fcb769d

Browse files
committed
add rules
1 parent 3971bec commit fcb769d

21 files changed

+309
-37
lines changed

composer.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@
1717
],
1818
"require": {
1919
"php": "^8.2",
20-
"illuminate/contracts": "^10.0||^11.0",
20+
"illuminate/contracts": "^11.0",
2121
"saloonphp/cache-plugin": "^3.0",
2222
"saloonphp/laravel-plugin": "^3.5",
2323
"saloonphp/rate-limit-plugin": "^2.0",
2424
"saloonphp/saloon": "^3.0",
2525
"spatie/laravel-package-tools": "^1.16"
2626
},
2727
"require-dev": {
28-
"laravel/pint": "^1.14",
29-
"nunomaduro/collision": "^8.1.1||^7.10.0",
30-
"larastan/larastan": "^2.9",
31-
"orchestra/testbench": "^9.0.0||^8.22.0",
32-
"pestphp/pest": "^2.34",
33-
"pestphp/pest-plugin-arch": "^2.7",
34-
"pestphp/pest-plugin-laravel": "^2.3",
35-
"phpstan/extension-installer": "^1.3",
36-
"phpstan/phpstan-deprecation-rules": "^1.1",
37-
"phpstan/phpstan-phpunit": "^1.3"
28+
"laravel/pint": "^1.0",
29+
"nunomaduro/collision": "^8.1",
30+
"larastan/larastan": "^3.0.0",
31+
"orchestra/testbench": "^9.0",
32+
"pestphp/pest": "^3.0",
33+
"pestphp/pest-plugin-arch": "^3.0",
34+
"pestphp/pest-plugin-laravel": "^3.0",
35+
"phpstan/extension-installer": "^1.4",
36+
"phpstan/phpstan-deprecation-rules": "^2.0",
37+
"phpstan/phpstan-phpunit": "^2.0"
3838
},
3939
"autoload": {
4040
"psr-4": {

config/pappers.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
// config for Elegantly/Pappers
46

57
return [

phpstan.neon.dist

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ includes:
22
- phpstan-baseline.neon
33

44
parameters:
5-
level: 5
5+
level: 9
66
paths:
77
- src
88
- config
99
- database
1010
tmpDir: build/phpstan
1111
checkOctaneCompatibility: true
1212
checkModelProperties: true
13-
13+
checkModelAppends: false
14+
noEnvCallsOutsideOfConfig: false

pint.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"preset": "laravel",
3+
"rules": {
4+
"declare_strict_types": true,
5+
"explicit_string_variable": true,
6+
"mb_str_functions": true
7+
}
8+
}

src/Enums/CompanyFields.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Elegantly\Pappers\Enums;
6+
7+
enum CompanyFields: string
8+
{
9+
case Officers = 'officers';
10+
case Ubos = 'ubos';
11+
case Financials = 'financials';
12+
case Documents = 'documents';
13+
case Certificates = 'certificates';
14+
case Publications = 'publications';
15+
case Establishments = 'establishments';
16+
case Contacts = 'contacts';
17+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Elegantly\Pappers\Enums;
6+
7+
enum EntrepriseChampsSupplementaires: string
8+
{
9+
// 1 jeton supplémentaire
10+
case SitesInternet = 'sites_internet';
11+
case Telephone = 'telephone';
12+
case Email = 'email';
13+
14+
// Gratuit
15+
case Enseigne1 = 'enseigne_1';
16+
case Enseigne2 = 'enseigne_2';
17+
case Enseigne3 = 'enseigne_3';
18+
case DistributionSpeciale = 'distribution_speciale';
19+
case CodeCedex = 'code_cedex';
20+
case LibelleCedex = 'libelle_cedex';
21+
case CodeCommune = 'code_commune';
22+
case CodeRegion = 'code_region';
23+
case Region = 'region';
24+
case CodeDepartement = 'code_departement';
25+
case Departement = 'departement';
26+
case NomenclatureCodeNaf = 'nomenclature_code_naf';
27+
case Labels = 'labels';
28+
case MicroEntreprise = 'micro_entreprise';
29+
30+
// 0.5 jeton supplémentaire
31+
case LabelsOrias = 'labels:orias';
32+
case LabelsCci = 'labels:cci';
33+
case Deces = 'deces';
34+
35+
// 1 jeton supplémentaire
36+
case Sanctions = 'sanctions';
37+
case PersonnePolitiquementExposee = 'personne_politiquement_exposee';
38+
39+
// 30 jetons supplémentaires
40+
case ScoringFinancier = 'scoring_financier';
41+
case ScoringNonFinancier = 'scoring_non_financier';
42+
43+
// Gratuit
44+
case CategorieEntreprise = 'categorie_entreprise';
45+
}

src/Enums/FormatPublicationsBodacc.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Elegantly\Pappers\Enums;
46

57
enum FormatPublicationsBodacc: string

src/Facades/Pappers.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Elegantly\Pappers\Facades;
46

57
use Elegantly\Pappers\Integrations\France\PappersFranceConnector;

src/Integrations/France/PappersFranceConnector.php

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Elegantly\Pappers\Integrations\France;
46

7+
use Elegantly\Pappers\Integrations\France\Requests\EntrepriseRequest;
58
use Illuminate\Support\Facades\Cache;
69
use Saloon\CachePlugin\Contracts\Cacheable;
710
use Saloon\CachePlugin\Contracts\Driver;
811
use Saloon\CachePlugin\Drivers\LaravelCacheDriver;
912
use Saloon\CachePlugin\Traits\HasCaching;
1013
use Saloon\Http\Auth\QueryAuthenticator;
1114
use Saloon\Http\Connector;
15+
use Saloon\Http\Response;
1216
use Saloon\RateLimitPlugin\Contracts\RateLimitStore;
1317
use Saloon\RateLimitPlugin\Limit;
1418
use Saloon\RateLimitPlugin\Stores\LaravelCacheStore;
@@ -28,8 +32,8 @@ public function __construct(
2832
public string $token,
2933
public string $version
3034
) {
31-
$this->cachingEnabled = config('pappers.cache.enabled', true);
32-
$this->useRateLimitPlugin(config('pappers.rate_limit.enabled', false));
35+
$this->cachingEnabled = config()->boolean('pappers.cache.enabled', true);
36+
$this->useRateLimitPlugin(config()->boolean('pappers.rate_limit.enabled', false));
3337
}
3438

3539
protected function defaultAuth(): QueryAuthenticator
@@ -52,23 +56,46 @@ protected function defaultHeaders(): array
5256

5357
public function resolveCacheDriver(): Driver
5458
{
55-
return new LaravelCacheDriver(Cache::store(config('pappers.cache.driver', 'file')));
59+
return new LaravelCacheDriver(Cache::store(
60+
config()->string('pappers.cache.driver', 'file')
61+
));
5662
}
5763

5864
public function cacheExpiryInSeconds(): int
5965
{
60-
return config('pappers.cache.expiry_seconds', 86_400);
66+
return config()->integer('pappers.cache.expiry_seconds', 604_800);
6167
}
6268

6369
protected function resolveRateLimitStore(): RateLimitStore
6470
{
65-
return new LaravelCacheStore(Cache::store(config('pappers.rate_limit.driver', 'array')));
71+
return new LaravelCacheStore(Cache::store(
72+
config()->string('pappers.rate_limit.driver', 'array')
73+
));
6674
}
6775

76+
/**
77+
* @return Limit[]
78+
*/
6879
protected function resolveLimits(): array
6980
{
7081
return [
71-
Limit::allow(config('pappers.rate_limit.every_minute'))->everyMinute(),
82+
Limit::allow(
83+
config()->integer('pappers.rate_limit.every_minute', 30)
84+
)->everyMinute(),
7285
];
7386
}
87+
88+
public function siren(string $siren): Response
89+
{
90+
return $this->send(new EntrepriseRequest(
91+
siren: $siren
92+
));
93+
}
94+
95+
public function siret(string $siret): Response
96+
{
97+
return $this->send(new EntrepriseRequest(
98+
siret: $siret
99+
));
100+
}
74101
}

src/Integrations/France/Requests/EntrepriseRequest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Elegantly\Pappers\Integrations\France\Requests;
46

7+
use Elegantly\Pappers\Enums\EntrepriseChampsSupplementaires;
58
use Elegantly\Pappers\Enums\FormatPublicationsBodacc;
6-
use Illuminate\Support\Arr;
79
use Saloon\Enums\Method;
810
use Saloon\Http\Request;
911

1012
class EntrepriseRequest extends Request
1113
{
1214
protected Method $method = Method::GET;
1315

16+
/**
17+
* @param EntrepriseChampsSupplementaires[] $champs_supplementaires
18+
*/
1419
public function __construct(
1520
protected readonly ?string $siren = null,
1621
protected readonly ?string $siret = null,
17-
protected readonly ?bool $integrer_diffusions_partielles = null,
22+
protected readonly ?bool $integrer_diffusions_partielles = true,
1823
protected readonly ?FormatPublicationsBodacc $format_publications_bodacc = null,
1924
protected readonly ?bool $marques = null,
2025
protected readonly ?bool $validite_tva_intracommunautaire = null,
2126
protected readonly ?bool $publications_bodacc_brutes = null,
22-
protected readonly array|string|null $champs_supplementaires = null,
27+
protected readonly array $champs_supplementaires = [],
2328
) {
2429
//
2530
}
@@ -34,8 +39,10 @@ protected function defaultQuery(): array
3439
'marques' => $this->marques,
3540
'validite_tva_intracommunautaire' => $this->validite_tva_intracommunautaire,
3641
'publications_bodacc_brutes' => $this->publications_bodacc_brutes,
37-
'champs_supplementaires' => Arr::join(Arr::wrap($this->champs_supplementaires), ','),
38-
], fn ($value) => $value !== null);
42+
'champs_supplementaires' => collect($this->champs_supplementaires)
43+
->map(fn (EntrepriseChampsSupplementaires $item) => $item->value)
44+
->implode(','),
45+
], fn ($value) => blank($value));
3946
}
4047

4148
public function resolveEndpoint(): string

src/Integrations/International/PappersInternationalConnector.php

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Elegantly\Pappers\Integrations\International;
46

7+
use Elegantly\Pappers\Integrations\International\Requests\CompanyRequest;
58
use Illuminate\Support\Facades\Cache;
69
use Saloon\CachePlugin\Contracts\Cacheable;
710
use Saloon\CachePlugin\Contracts\Driver;
811
use Saloon\CachePlugin\Drivers\LaravelCacheDriver;
912
use Saloon\CachePlugin\Traits\HasCaching;
1013
use Saloon\Http\Auth\QueryAuthenticator;
1114
use Saloon\Http\Connector;
15+
use Saloon\Http\Response;
1216
use Saloon\RateLimitPlugin\Contracts\RateLimitStore;
1317
use Saloon\RateLimitPlugin\Limit;
1418
use Saloon\RateLimitPlugin\Stores\LaravelCacheStore;
@@ -28,8 +32,8 @@ public function __construct(
2832
public string $token,
2933
public string $version
3034
) {
31-
$this->cachingEnabled = config('pappers.cache.enabled', true);
32-
$this->useRateLimitPlugin(config('pappers.rate_limit.enabled', false));
35+
$this->cachingEnabled = config()->boolean('pappers.cache.enabled', true);
36+
$this->useRateLimitPlugin(config()->boolean('pappers.rate_limit.enabled', false));
3337
}
3438

3539
protected function defaultAuth(): QueryAuthenticator
@@ -52,23 +56,40 @@ protected function defaultHeaders(): array
5256

5357
public function resolveCacheDriver(): Driver
5458
{
55-
return new LaravelCacheDriver(Cache::store(config('pappers.cache.driver', 'file')));
59+
return new LaravelCacheDriver(Cache::store(
60+
config()->string('pappers.cache.driver', 'file')
61+
));
5662
}
5763

5864
public function cacheExpiryInSeconds(): int
5965
{
60-
return config('pappers.cache.expiry_seconds', 86_400);
66+
return config()->integer('pappers.cache.expiry_seconds', 604_800);
6167
}
6268

6369
protected function resolveRateLimitStore(): RateLimitStore
6470
{
65-
return new LaravelCacheStore(Cache::store(config('pappers.rate_limit.driver', 'array')));
71+
return new LaravelCacheStore(Cache::store(
72+
config()->string('pappers.rate_limit.driver', 'array')
73+
));
6674
}
6775

76+
/**
77+
* @return Limit[]
78+
*/
6879
protected function resolveLimits(): array
6980
{
7081
return [
71-
Limit::allow(config('pappers.rate_limit.every_minute'))->everyMinute(),
82+
Limit::allow(
83+
config()->integer('pappers.rate_limit.every_minute', 30)
84+
)->everyMinute(),
7285
];
7386
}
87+
88+
public function number(string $country_code, string $company_number): Response
89+
{
90+
return $this->send(new CompanyRequest(
91+
country_code: $country_code,
92+
company_number: $company_number,
93+
));
94+
}
7495
}

src/Integrations/International/Requests/CompanyRequest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Elegantly\Pappers\Integrations\International\Requests;
46

7+
use Elegantly\Pappers\Enums\CompanyFields;
58
use Saloon\Enums\Method;
69
use Saloon\Http\Request;
710

811
class CompanyRequest extends Request
912
{
1013
protected Method $method = Method::GET;
1114

15+
/**
16+
* @param CompanyFields[] $fields
17+
*/
1218
public function __construct(
1319
protected readonly string $country_code,
1420
protected readonly string $company_number,
15-
protected readonly ?array $fields = [],
21+
protected readonly array $fields = [],
1622
) {
1723
//
1824
}
@@ -22,8 +28,10 @@ protected function defaultQuery(): array
2228
return array_filter([
2329
'country_code' => $this->country_code,
2430
'company_number' => $this->company_number,
25-
'fields' => implode(',', $this->fields),
26-
]);
31+
'fields' => collect($this->fields)
32+
->map(fn (CompanyFields $field) => $field->value)
33+
->implode(','),
34+
], fn ($value) => blank($value));
2735
}
2836

2937
public function resolveEndpoint(): string

0 commit comments

Comments
 (0)