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

pixelpeter / laravel5-isocodes-validation / 14199022807

01 Apr 2025 02:59PM UTC coverage: 98.99%. First build
14199022807

Pull #37

github

web-flow
Merge ca950ec49 into fa868bdcc
Pull Request #37: ADD: github actions

196 of 198 relevant lines covered (98.99%)

50.22 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()
328✔
16
    {
17
        // load translation files
18
        $this->loadTranslationsFrom(
328✔
19
            __DIR__ . '/../lang',
328✔
20
            'validation'
328✔
21
        );
22

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

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

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

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

48
    }
328✔
49

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

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

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

72
    /**
73
     * Register the application services.
74
     *
75
     * @return void
76
     */
77
    public function register()
328✔
78
    {
79
        //
80
    }
328✔
81
}
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