diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..3f9f510 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +./vendor/bin/pint \ No newline at end of file diff --git a/composer.json b/composer.json index d3b375f..6627c35 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ } ], "require-dev": { - "pestphp/pest": "^3.5" + "pestphp/pest": "^3.5", + "laravel/pint": "^1.18" }, "config": { "allow-plugins": { @@ -27,4 +28,4 @@ "scripts": { "test": "vendor/bin/pest" } -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index abc04f2..c6e5963 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b595cbd9e5385c047b710d39017efcd0", + "content-hash": "f88345f8e21f0e8e0428612010d13cca", "packages": [ { "name": "brick/math", @@ -5743,6 +5743,72 @@ }, "time": "2024-03-08T09:58:59+00:00" }, + { + "name": "laravel/pint", + "version": "v1.18.3", + "source": { + "type": "git", + "url": "https://github.com/laravel/pint.git", + "reference": "cef51821608239040ab841ad6e1c6ae502ae3026" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/pint/zipball/cef51821608239040ab841ad6e1c6ae502ae3026", + "reference": "cef51821608239040ab841ad6e1c6ae502ae3026", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-mbstring": "*", + "ext-tokenizer": "*", + "ext-xml": "*", + "php": "^8.1.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.65.0", + "illuminate/view": "^10.48.24", + "larastan/larastan": "^2.9.11", + "laravel-zero/framework": "^10.4.0", + "mockery/mockery": "^1.6.12", + "nunomaduro/termwind": "^1.17.0", + "pestphp/pest": "^2.36.0" + }, + "bin": [ + "builds/pint" + ], + "type": "project", + "autoload": { + "psr-4": { + "App\\": "app/", + "Database\\Seeders\\": "database/seeders/", + "Database\\Factories\\": "database/factories/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nuno Maduro", + "email": "enunomaduro@gmail.com" + } + ], + "description": "An opinionated code formatter for PHP.", + "homepage": "https://laravel.com", + "keywords": [ + "format", + "formatter", + "lint", + "linter", + "php" + ], + "support": { + "issues": "https://github.com/laravel/pint/issues", + "source": "https://github.com/laravel/pint" + }, + "time": "2024-11-26T15:34:00+00:00" + }, { "name": "myclabs/deep-copy", "version": "1.12.1", diff --git a/examples/asaas/clients.php b/examples/asaas/clients.php index cc9bf31..f2c32ec 100644 --- a/examples/asaas/clients.php +++ b/examples/asaas/clients.php @@ -1,14 +1,15 @@ NAME, - 'cpf_cnpj' => CPF_CNPJ + 'name' => NAME, + 'cpf_cnpj' => CPF_CNPJ, ]; /** @@ -35,7 +36,7 @@ */ $response = $phpay ->client() - ->with(['cpfCnpj' => '09102295466',]) + ->with(['cpfCnpj' => '09102295466', ]) ->all(); // print_r($response); diff --git a/examples/asaas/credentials.example.php b/examples/asaas/credentials.example.php index 9a943a7..db07ccd 100644 --- a/examples/asaas/credentials.example.php +++ b/examples/asaas/credentials.example.php @@ -3,5 +3,5 @@ const TOKEN_ASAAS_SANDBOX = ''; /* client to testing */ -const NAME = ''; +const NAME = ''; const CPF_CNPJ = ''; diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..fa57763 --- /dev/null +++ b/pint.json @@ -0,0 +1,69 @@ +{ + "preset": "psr12", + "rules": { + "group_import": true, + "single_import_per_statement": false, + "no_unused_imports": true, + "array_indentation": true, + "array_syntax": { + "syntax": "short" + }, + "binary_operator_spaces": { + "default": "single_space", + "operators": { + "=": "align_single_space_minimal", + "=>": "align_single_space_minimal" + } + }, + "blank_line_after_namespace": true, + "blank_line_after_opening_tag": false, + "class_attributes_separation": { + "elements": { + "property": "one" + } + }, + "concat_space": { + "spacing": "one" + }, + "declare_equal_normalize": { + "space": "single" + }, + "elseif": false, + "encoding": true, + "indentation_type": true, + "no_useless_else": false, + "no_useless_return": true, + "ordered_imports": true, + "ternary_operator_spaces": true, + "no_extra_blank_lines": true, + "no_multiline_whitespace_around_double_arrow": true, + "multiline_whitespace_before_semicolons": true, + "no_singleline_whitespace_before_semicolons": true, + "no_spaces_around_offset": true, + "ternary_to_null_coalescing": true, + "whitespace_after_comma_in_array": true, + "trim_array_spaces": true, + "trailing_comma_in_multiline": true, + "unary_operator_spaces": true, + "blank_line_before_statement": { + "statements": [ + "break", + "continue", + "declare", + "return", + "throw", + "try", + "continue", + "do", + "exit", + "for", + "foreach", + "if", + "include", + "include_once", + "require", + "require_once" + ] + } + } +} \ No newline at end of file diff --git a/src/Gateways/Asaas/AsaasGateway.php b/src/Gateways/Asaas/AsaasGateway.php index 59a23f9..733b804 100644 --- a/src/Gateways/Asaas/AsaasGateway.php +++ b/src/Gateways/Asaas/AsaasGateway.php @@ -5,7 +5,7 @@ use Illuminate\Support\Facades\Http; use PHPay\Contracts\GatewayInterface; use PHPay\Exceptions\AsaasExceptions; -use PHPay\Gateways\Asaas\Enums\{BillingType, ClientMethods}; +use PHPay\Gateways\Asaas\Enums\{BillingType}; use PHPay\Gateways\Asaas\Requests\AsaasPixRequest; use PHPay\Gateways\Asaas\Resources\{Auth, Client}; use PHPay\Gateways\Gateway; @@ -58,10 +58,10 @@ public function pix(array $pix): self|AsaasExceptions $payment = Http::asaas() ->post('/payments', [ - 'customer' => $this->customerId, + 'customer' => $this->customerId, 'billingType' => BillingType::PIX->value, - 'value' => $amount, - 'dueDate' => $due_date, + 'value' => $amount, + 'dueDate' => $due_date, 'description' => $description, ])->json(); diff --git a/src/Gateways/Asaas/Enums/BillingType.php b/src/Gateways/Asaas/Enums/BillingType.php index 52d8507..dfbf09c 100644 --- a/src/Gateways/Asaas/Enums/BillingType.php +++ b/src/Gateways/Asaas/Enums/BillingType.php @@ -4,8 +4,8 @@ enum BillingType: string { - case UNDEFINED = 'UNDEFINED'; - case BOLETO = 'BOLETO'; + case UNDEFINED = 'UNDEFINED'; + case BOLETO = 'BOLETO'; case CREDIT_CARD = 'CREDIT_CARD'; - case PIX = 'PIX'; + case PIX = 'PIX'; } diff --git a/src/Gateways/Asaas/Enums/ClientMethods.php b/src/Gateways/Asaas/Enums/ClientMethods.php index 63cd060..5d7cbc3 100644 --- a/src/Gateways/Asaas/Enums/ClientMethods.php +++ b/src/Gateways/Asaas/Enums/ClientMethods.php @@ -4,9 +4,9 @@ enum ClientMethods: string { - case ALL = 'all'; - case FIND = 'find'; - case STORE = 'store'; + case ALL = 'all'; + case FIND = 'find'; + case STORE = 'store'; case UPDATE = 'update'; case DELETE = 'delete'; } diff --git a/src/Gateways/Asaas/Requests/AsaasClientRequest.php b/src/Gateways/Asaas/Requests/AsaasClientRequest.php index 440e360..c77c738 100644 --- a/src/Gateways/Asaas/Requests/AsaasClientRequest.php +++ b/src/Gateways/Asaas/Requests/AsaasClientRequest.php @@ -14,11 +14,11 @@ class AsaasClientRequest */ public static function validate(array $client): void { - if (! isset($client['name'])) { + if (!isset($client['name'])) { throw new \InvalidArgumentException(self::messages()->name); } - if (! isset($client['cpf_cnpj'])) { + if (!isset($client['cpf_cnpj'])) { throw new \InvalidArgumentException(self::messages()->cpf_cnpj); } } @@ -31,7 +31,7 @@ public static function validate(array $client): void public function messages(): stdClass { return (object) [ - 'name' => 'Asaas: Nome do cliente é obrigatório para o Asaas', + 'name' => 'Asaas: Nome do cliente é obrigatório para o Asaas', 'cpf_cnpj' => 'Asaas: CPF/CNPJ do cliente é obrigatório para o Asaas', ]; } diff --git a/src/Gateways/Asaas/Requests/AsaasPixRequest.php b/src/Gateways/Asaas/Requests/AsaasPixRequest.php index 41c0d14..2f68455 100644 --- a/src/Gateways/Asaas/Requests/AsaasPixRequest.php +++ b/src/Gateways/Asaas/Requests/AsaasPixRequest.php @@ -8,15 +8,15 @@ class AsaasPixRequest { public static function validate(array $pix): void { - if (! isset($pix['description'])) { + if (!isset($pix['description'])) { throw new \InvalidArgumentException(self::messages()->description); } - if (! isset($pix['amount'])) { + if (!isset($pix['amount'])) { throw new \InvalidArgumentException(self::messages()->amount); } - if (! isset($pix['due_date'])) { + if (!isset($pix['due_date'])) { throw new \InvalidArgumentException(self::messages()->due_date->required); } @@ -29,10 +29,10 @@ public static function messages(): stdClass { return (object) [ 'description' => 'Asaas: Descrição do pagamento é obrigatório para o Asaas', - 'amount' => 'Asaas: Valor do pagamento é obrigatório para o Asaas', - 'due_date' => (object) [ + 'amount' => 'Asaas: Valor do pagamento é obrigatório para o Asaas', + 'due_date' => (object) [ 'required' => 'Asaas: Data de vencimento do pagamento é obrigatório para o Asaas', - 'date' => 'Asaas: Data de vencimento do pagamento não pode ser menor que a data atual', + 'date' => 'Asaas: Data de vencimento do pagamento não pode ser menor que a data atual', ], ]; } diff --git a/src/Gateways/Asaas/Resources/Auth.php b/src/Gateways/Asaas/Resources/Auth.php index 0226fcb..75d8899 100644 --- a/src/Gateways/Asaas/Resources/Auth.php +++ b/src/Gateways/Asaas/Resources/Auth.php @@ -3,7 +3,6 @@ namespace PHPay\Gateways\Asaas\Resources; use Illuminate\Support\Facades\Http; -use PHPay\Exceptions\AsaasExceptions; final class Auth { @@ -24,7 +23,7 @@ public function __construct(string $token, bool $sandbox) ->baseUrl($baseUrl) ->withHeaders([ 'content-type' => 'application/json', - 'user-agent' => 'payhub', + 'user-agent' => 'payhub', 'access_token' => $token, ]); }); diff --git a/src/Gateways/Asaas/Resources/Client.php b/src/Gateways/Asaas/Resources/Client.php index 0b9ba67..19dbf5a 100644 --- a/src/Gateways/Asaas/Resources/Client.php +++ b/src/Gateways/Asaas/Resources/Client.php @@ -33,7 +33,7 @@ final class Client implements ClientInterface */ public function __construct(array $client, Gateway $gateway) { - $this->client = $client; + $this->client = $client; $this->gateway = $gateway; } @@ -110,13 +110,13 @@ public function store(): string|AsaasExceptions $client = self::find($cpf_cnpj); - if (! empty($client)) { + if (!empty($client)) { return $client[0]['id']; } $client = Http::asaas() ->post(env('ASSAS_CLIENTS'), [ - 'name' => $name, + 'name' => $name, 'cpfCnpj' => $cpf_cnpj, ])->json(); diff --git a/src/PHPay.php b/src/PHPay.php index 3740497..38dc4b1 100644 --- a/src/PHPay.php +++ b/src/PHPay.php @@ -5,8 +5,7 @@ use Dotenv\Dotenv; use Illuminate\Container\Container; use Illuminate\Http\Client\Factory; -use Illuminate\Support\Facades\Facade; -use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\{Facade, Http}; use PHPay\Gateways\Asaas\AsaasGateway; use PHPay\Gateways\Gateway; diff --git a/tests/Feature/PayhubTest.php b/tests/Feature/PHPayTest.php similarity index 61% rename from tests/Feature/PayhubTest.php rename to tests/Feature/PHPayTest.php index ff0d164..dd6e11c 100644 --- a/tests/Feature/PayhubTest.php +++ b/tests/Feature/PHPayTest.php @@ -3,8 +3,10 @@ use PHPay\PHPay; test('instance payhub class', function () { - $payhub = new PHPay('token'); + $token = ''; - expect($payhub) + $phpay = PHPay::asaas($token); + + expect($phpay) ->toBeInstanceOf(PHPay::class); });