Test Setup Failed
Pull Request — master (#9)
by
unknown
13:59
created

PaystackServiceProvider::validator()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
nc 1
nop 0
1
<?php
2
3
namespace Iamolayemi\Paystack;
4
5
use Illuminate\Support\Facades\Validator;
6
use Illuminate\Support\ServiceProvider;
7
8
class PaystackServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     */
13
    public function boot(): void
14
    {
15
        if (
16
            $this->app->runningInConsole()
17
        ) {
18
            $this->publishes([
19
                __DIR__.'/../config/config.php' => config_path('paystack.php'),
20
            ], 'config');
21
        }
22
23
        // Register custom validation rule for Laravel 10+
24
        Validator::extend('required_string', function ($attribute, $value, $parameters, $validator) {
0 ignored issues
show
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

24
        Validator::extend('required_string', function ($attribute, $value, $parameters, /** @scrutinizer ignore-unused */ $validator) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

24
        Validator::extend('required_string', function ($attribute, $value, /** @scrutinizer ignore-unused */ $parameters, $validator) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
            return is_string($value) && ! empty(trim($value));
26
        }, 'The :attribute must be a non-empty string.');
27
    }
28
29
    /**
30
     * Register the application services.
31
     */
32
    public function register(): void
33
    {
34
        // Automatically apply the package configuration
35
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'paystack');
36
37
        // Register the main class to use with the facade
38
        $this->app->bind('paystack', function () {
39
            // Validate required credentials
40
            $config = config('paystack');
41
42
            if (empty($config['secret_key'])) {
43
                throw new \InvalidArgumentException('Paystack secret key is required. Please set PAYSTACK_SECRET_KEY in your .env file.');
44
            }
45
46
            return new Paystack($config['secret_key']);
47
        });
48
    }
49
}
50