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

RonasIT / laravel-entity-generator / 12350519352

16 Dec 2024 10:17AM UTC coverage: 48.366%. Remained the same
12350519352

Pull #126

github

web-flow
Merge 90fa94bb7 into 100fe1d25
Pull Request #126: #125: Use model test states in tests generator

1 of 4 new or added lines in 3 files covered. (25.0%)

444 of 918 relevant lines covered (48.37%)

1.65 hits per line

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

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

3
namespace RonasIT\Support\Generators;
4

5
use RonasIT\Support\Events\SuccessCreateMessage;
6
use RonasIT\Support\Exceptions\ClassAlreadyExistsException;
7

8
class ResourceGenerator extends EntityGenerator
9
{
10
    public function generate(): void
11
    {
12
        if ($this->isStubExists('resource')) {
×
13
            $this->generateResource();
×
14

15
            if ($this->isStubExists('collection_resource')) {
×
16
                $this->generateCollectionResource();
×
17
            }
18
        }
19
    }
20

21
    public function generateCollectionResource(): void
22
    {
23
        $pluralName = $this->getPluralName($this->model);
×
24

25
        if ($this->classExists('resources', "{$pluralName}CollectionResource")) {
×
26
            $this->throwFailureException(
×
27
                ClassAlreadyExistsException::class,
×
28
                "Cannot create {$pluralName}CollectionResource cause {$pluralName}CollectionResource already exists.",
×
29
                "Remove {$pluralName}CollectionResource."
×
30
            );
×
31
        }
32

33
        $collectionResourceContent = $this->getStub('collection_resource', [
×
34
            'singular_name' => $this->model,
×
35
            'plural_name' => $pluralName,
×
36
            'namespace' => $this->getOrCreateNamespace('resources')
×
37
        ]);
×
38

NEW
39
        $this->saveClass('resources', "{$pluralName}CollectionResource", $collectionResourceContent, $this->model);
×
40

41
        event(new SuccessCreateMessage("Created a new CollectionResource: {$pluralName}CollectionResource"));
×
42
    }
43

44
    public function generateResource(): void
45
    {
46
        if ($this->classExists('resources', "{$this->model}Resource")) {
×
47
            $this->throwFailureException(
×
48
                ClassAlreadyExistsException::class,
×
49
                "Cannot create {$this->model}Resource cause {$this->model}Resource already exists.",
×
50
                "Remove {$this->model}Resource."
×
51
            );
×
52
        }
53

54
        $resourceContent = $this->getStub('resource', [
×
55
            'entity' => $this->model,
×
56
            'namespace' => $this->getOrCreateNamespace('resources'),
×
57
            'model_namespace' => $this->getOrCreateNamespace('models'),
×
58
        ]);
×
59

NEW
60
        $this->saveClass('resources', "{$this->model}Resource", $resourceContent, $this->model);
×
61

62
        event(new SuccessCreateMessage("Created a new Resource: {$this->model}Resource"));
×
63
    }
64
}
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