• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

api-platform / core / 18089937549

29 Sep 2025 07:56AM UTC coverage: 21.764% (-0.3%) from 22.093%
18089937549

Pull #7416

github

web-flow
Merge 061bcc790 into abe0438be
Pull Request #7416: fix(laravel): serializer attributes on Eloquent methods

0 of 151 new or added lines in 11 files covered. (0.0%)

5028 existing lines in 173 files now uncovered.

11889 of 54626 relevant lines covered (21.76%)

25.32 hits per line

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

0.0
/src/Laravel/Console/Maker/AbstractMakeStateCommand.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Laravel\Console\Maker;
15

16
use ApiPlatform\Laravel\Console\Maker\Utils\StateAppServiceProviderTagger;
17
use ApiPlatform\Laravel\Console\Maker\Utils\StateTemplateGenerator;
18
use ApiPlatform\Laravel\Console\Maker\Utils\StateTypeEnum;
19
use ApiPlatform\Laravel\Console\Maker\Utils\SuccessMessageTrait;
20
use Illuminate\Console\Command;
21
use Illuminate\Contracts\Filesystem\FileNotFoundException;
22
use Illuminate\Filesystem\Filesystem;
23

24
abstract class AbstractMakeStateCommand extends Command
25
{
26
    use SuccessMessageTrait;
27

28
    public function __construct(
29
        private readonly Filesystem $filesystem,
30
        private readonly StateTemplateGenerator $stateTemplateGenerator,
31
        private readonly StateAppServiceProviderTagger $stateAppServiceProviderTagger,
32
    ) {
33
        parent::__construct();
×
34
    }
35

36
    /**
37
     * @throws FileNotFoundException
38
     */
39
    public function handle(): int
40
    {
41
        $stateType = $this->getStateType()->name;
×
UNCOV
42
        $stateName = $this->ask(\sprintf('Choose a class name for your state %s (e.g. <fg=yellow>AwesomeState%s</>)', strtolower($stateType), ucfirst($stateType)));
×
43
        if (null === $stateName || '' === $stateName) {
×
44
            $this->error('[ERROR] The name argument cannot be blank.');
×
45

46
            return self::FAILURE;
×
47
        }
48

UNCOV
49
        $directoryPath = base_path('app/State/');
×
50
        $this->filesystem->ensureDirectoryExists($directoryPath);
×
51

UNCOV
52
        $filePath = $this->stateTemplateGenerator->getFilePath($directoryPath, $stateName);
×
53
        if ($this->filesystem->exists($filePath)) {
×
54
            $this->error(\sprintf('[ERROR] The file "%s" can\'t be generated because it already exists.', $filePath));
×
55

UNCOV
56
            return self::FAILURE;
×
57
        }
58

UNCOV
59
        $this->stateTemplateGenerator->generate($filePath, $stateName, $this->getStateType());
×
60
        if (!$this->filesystem->exists($filePath)) {
×
UNCOV
61
            $this->error(\sprintf('[ERROR] The file "%s" could not be created.', $filePath));
×
62

UNCOV
63
            return self::FAILURE;
×
64
        }
65

UNCOV
66
        $this->stateAppServiceProviderTagger->addTagToServiceProvider($stateName, $this->getStateType());
×
67

UNCOV
68
        $this->writeSuccessMessage($filePath, \sprintf('State %s', ucfirst($this->getStateType()->name)));
×
69

70
        return self::SUCCESS;
×
71
    }
72

73
    abstract protected function getStateType(): StateTypeEnum;
74
}
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