• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pixelpeter / laravel-isocodes-validation / 14190687605

01 Apr 2025 08:17AM UTC coverage: 98.469%. Remained the same
14190687605

Pull #10

github

web-flow
Merge c27ede9be into c923a5c59
Pull Request #10: ADD: Laravel 12 compatibility

193 of 196 relevant lines covered (98.47%)

127.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/IsoCodesValidationServiceProvider.php
1
<?php
2

3
namespace Pixelpeter\IsoCodesValidation;
4

5
use Illuminate\Support\ServiceProvider;
6
use Illuminate\Support\Str;
7

8
class IsoCodesValidationServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     *
13
     * @return void
14
     */
15
    public function boot()
800✔
16
    {
17
        // load translation files
18
        $this->loadTranslationsFrom(
800✔
19
            __DIR__.'/../lang',
800✔
20
            'validation'
800✔
21
        );
800✔
22

23
        // registering intervention validator extension
24
        $this->app['validator']->resolver(function ($translator, $data, $rules, $messages, $customAttributes) {
800✔
25
            // set the validation error messages
26
            foreach (get_class_methods('Pixelpeter\IsoCodesValidation\IsoCodesValidator') as $method) {
800✔
27
                $key = $this->getTranslationKeyFromMethodName($method);
800✔
28

29
                $messages[$key] = $this->getErrorMessage($translator, $messages, $key);
800✔
30
            }
31

32
            return new IsoCodesValidator($translator, $data, $rules, $messages, $customAttributes);
800✔
33
        });
800✔
34
    }
35

36
    /**
37
     * Return translation key for correspondent method name
38
     *
39
     * @param  string  $name
40
     * @return string
41
     */
42
    private function getTranslationKeyFromMethodName($name)
800✔
43
    {
44
        if (stripos($name, 'validate') !== false) {
800✔
45
            return Str::snake(substr($name, 8));
800✔
46
        }
47

48
        return '';
800✔
49
    }
50

51
    /**
52
     * Return the matching error message for the key
53
     *
54
     * @param  string  $key
55
     * @return string
56
     */
57
    private function getErrorMessage($translator, $messages, $key)
800✔
58
    {
59
        // return error messages passed directly to the validator
60
        if (isset($messages[$key])) {
800✔
61
            return $messages[$key];
800✔
62
        }
63

64
        // return error message from validation translation file
65
        if ($translator->has("validation.{$key}")) {
800✔
66
            return $translator->get("validation.{$key}");
800✔
67
        }
68

69
        // return packages default message
70
        return $translator->get("validation::validation.{$key}");
800✔
71
    }
72

73
    /**
74
     * Register the application services.
75
     *
76
     * @return void
77
     */
78
    public function register()
800✔
79
    {
80
        //
81
    }
800✔
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc