Test Failed
Push — master ( e3c39f...fe570d )
by Mihail
07:20
created

Apps/Console/GeneratorActiveRecordCommand.php (1 issue)

Checks if the types of the passed arguments in a function/method call are compatible.

Bug Minor
1
<?php
2
3
namespace Apps\Console;
4
5
6
use Ffcms\Console\Command;
7
use Ffcms\Core\Helper\FileSystem\File;
8
use Ffcms\Core\Helper\Type\Str;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Input\InputOption;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
/**
14
 * Class GeneratorActiveRecordCommand. Generate new active record model based on default carcase
15
 * @package Apps\Console
16
 */
17
class GeneratorActiveRecordCommand extends Command
18
{
19
    /**
20
     * Register command
21
     */
22
    public function configure()
23
    {
24
        $this->setName('generator:activerecord')
25
            ->setDescription('Generate ActiveRecord model template')
26
            ->addOption('name', 'name', InputOption::VALUE_OPTIONAL, 'Set active record model name');
27
    }
28
29
    /**
30
     * Execute active record create
31
     * @param InputInterface $input
32
     * @param OutputInterface $output
33
     * @return void
34
     */
35
    public function execute(InputInterface $input, OutputInterface $output)
36
    {
37
        // get ar name from input
38
        $name = $this->optionOrAsk('name', 'ActiveRecord name');
39
        $name = ucfirst(Str::lowerCase($name));
40
41
        $tpl = File::read('/Private/Carcase/ActiveRecord.tphp');
42
        $code = Str::replace('%name%', $name, $tpl);
0 ignored issues
show
It seems like $tpl can also be of type false; however, parameter $haystack of Ffcms\Core\Helper\Type\Str::replace() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
        $code = Str::replace('%name%', $name, /** @scrutinizer ignore-type */ $tpl);
Loading history...
43
44
        $path = '/Apps/ActiveRecord/' . $name . '.php';
45
        File::write($path, $code);
46
        $output->writeln('ActiveRecord are successful created: ' . $path);
47
    }
48
}