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

RonasIT / laravel-entity-generator / 12026977149

26 Nov 2024 08:49AM UTC coverage: 39.655% (+0.1%) from 39.537%
12026977149

Pull #108

github

web-flow
Merge ddd257d48 into 8497bb4ef
Pull Request #108: feat: skip generation for invalid stubs

33 of 75 new or added lines in 15 files covered. (44.0%)

23 existing lines in 2 files now uncovered.

391 of 986 relevant lines covered (39.66%)

1.31 hits per line

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

0.0
/src/Generators/TranslationsGenerator.php
1
<?php
2

3
namespace RonasIT\Support\Generators;
4

5
use Illuminate\Support\Arr;
6
use RonasIT\Support\Events\SuccessCreateMessage;
7

8
class TranslationsGenerator extends EntityGenerator
9
{
10
    protected $translationPath;
11

12
    public function __construct()
13
    {
14
        parent::__construct();
×
15

16
        $this->translationPath = Arr::get($this->paths, 'translations', 'resources/lang/en/validation.php');
×
17
    }
18

19
    public function generate(): void
20
    {
NEW
21
        if (!file_exists($this->translationPath) && $this->checkStubExists('validation')) {
×
22
            $this->createTranslate();
×
23
        }
24
        
NEW
25
        if ($this->isTranslationMissed('validation.exceptions.not_found') && $this->checkStubExists('translation_not_found')) {
×
26
            $this->appendNotFoundException();
×
27
        }
28
    }
29

30
    protected function isTranslationMissed($translation) : bool
31
    {
32
        return __($translation) === 'validation.exceptions.not_found';
×
33
    }
34

35
    protected function createTranslate(): void
36
    {
37
        $stubPath = config('entity-generator.stubs.validation');
×
38

39
        $content = "<?php \n\n" . view($stubPath)->render();
×
40

41
        file_put_contents($this->translationPath, $content);
×
42

43
        $createMessage = "Created a new Translations dump on path: {$this->translationPath}";
×
44
        
45
        event(new SuccessCreateMessage($createMessage));
×
46
    }
47

48
    protected function appendNotFoundException(): void
49
    {
50
        $content = file_get_contents($this->translationPath);
×
51
        
52
        $stubPath = config('entity-generator.stubs.translation_not_found');
×
53
        
54
        $stubContent = view($stubPath)->render();
×
55

56
        $fixedContent = preg_replace('/\]\;\s*$/', "\n\t{$stubContent}", $content);
×
57
        
58
        file_put_contents($this->translationPath, $fixedContent);
×
59
    }
60
}
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

© 2025 Coveralls, Inc