• 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/ServiceGenerator.php
1
<?php
2

3
namespace RonasIT\Support\Generators;
4

5
use Illuminate\Support\Arr;
6
use Illuminate\Support\Str;
7
use RonasIT\Support\Exceptions\ClassNotExistsException;
8
use RonasIT\Support\Events\SuccessCreateMessage;
9

10
class ServiceGenerator extends EntityGenerator
11
{
12
    public function setRelations($relations)
13
    {
14
        foreach ($relations['belongsTo'] as $field) {
×
15
            $name = Str::snake($field) . '_id';
×
16

17
            $this->fields['integer'][] = $name;
×
18
        }
19

20
        return $this;
×
21
    }
22

23
    public function generate(): void
24
    {
25
        if ($this->classExists('repositories', "{$this->model}Repository")) {
×
26
            $stub = 'service';
×
27
        } else {
28
            $stub = 'service_with_trait';
×
29

30
            if (!$this->classExists('models', $this->model)) {
×
31
                $this->throwFailureException(
×
32
                    ClassNotExistsException::class,
×
33
                    "Cannot create {$this->model} Model cause {$this->model} Model does not exists.",
×
34
                    "Create a {$this->model} Model by himself or run command 'php artisan make:entity {$this->model} --only-model'."
×
35
                );
×
36
            }
37
        }
38

NEW
39
        if (!$this->checkStubExists($stub)) {
×
NEW
40
            return;
×
41
        }
42

43
        $serviceContent = $this->getStub($stub, [
×
44
            'entity' => $this->model,
×
45
            'fields' => $this->getFields(),
×
46
            'namespace' => $this->getOrCreateNamespace('services'),
×
47
            'repositoriesNamespace' => $this->getOrCreateNamespace('repositories'),
×
48
            'modelsNamespace' => $this->getOrCreateNamespace('models')
×
49
        ]);
×
50

51
        $this->saveClass('services', "{$this->model}Service", $serviceContent);
×
52

53
        event(new SuccessCreateMessage("Created a new Service: {$this->model}Service"));
×
54
    }
55

56
    protected function getFields(): array
57
    {
58
        $simpleSearch = Arr::only($this->fields, ['integer', 'integer-required', 'boolean', 'boolean-required']);
×
59

60
        return [
×
61
            'simple_search' => Arr::collapse($simpleSearch),
×
62
            'search_by_query' => array_merge($this->fields['string'], $this->fields['string-required'])
×
63
        ];
×
64
    }
65
}
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