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

api-platform / core / 17493833050

05 Sep 2025 12:55PM UTC coverage: 22.604% (+22.6%) from 0.0%
17493833050

push

github

soyuka
fix(state)!: parameter default value overrides falsy value

1 of 1 new or added line in 1 file covered. (100.0%)

110 existing lines in 7 files now uncovered.

12071 of 53402 relevant lines covered (22.6%)

26.39 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