Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/LionBundle/Commands/Lion/New/ControllerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,12 @@ class ControllerCommand extends Command
];

/**
* Controller path
*
* @const PATH_CONTROLLER
* Controller path.
*/
public const string PATH_CONTROLLER = 'app/Http/Controllers/';

/**
* Model path
*
* @const PATH_MODEL
* Model path.
*/
public const string PATH_MODEL = 'app/Models/';

Expand Down
46 changes: 27 additions & 19 deletions src/LionBundle/Commands/Lion/New/SHFileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,25 @@
use Symfony\Component\Console\Output\OutputInterface;

/**
* Generates a .sh file
*
* @package Lion\Bundle\Commands\Lion\New
* Generates a .sh file.
*/
class SHFileCommand extends Command
{
/**
* Fabricates the data provided to manipulate information (folder, class, namespace)
* SH path.
*/
public const string PATH_SH = 'storage/Sh/';

/**
* Fabricates the data provided to manipulate information (folder, class,
* namespace).
*
* @var ClassFactory $classFactory
*/
private ClassFactory $classFactory;

/**
* Manipulate system files
* Manipulate system files.
*
* @var Store $store
*/
Expand All @@ -52,50 +56,54 @@ public function setStore(Store $store): SHFileCommand
}

/**
* Configures the current command
* Configures the current command.
*
* @return void
*/
protected function configure(): void
{
$this
->setName('new:sh')
->setDescription('Command required to create files with sh extension')
->addArgument('sh', InputArgument::OPTIONAL, 'SH name', 'Example');
->setDescription('Command required to create files with sh extension.')
->addArgument('sh', InputArgument::OPTIONAL, '.sh file name.', 'example');
}

/**
* Executes the current command
* Executes the current command.
*
* This method is not abstract because you can use this class as a concrete
* class. In this case, instead of defining the execute() method, you set the
* code to execute by passing a Closure to the setCode() method
* code to execute by passing a Closure to the setCode() method.
*
* @param InputInterface $input InputInterface is the interface implemented by
* all input classes
* all input classes.
* @param OutputInterface $output OutputInterface is the interface implemented
* by all Output classes
* by all Output classes.
*
* @return int
*
* @throws Exception If the file could not be opened
* @throws LogicException When this abstract method is not implemented
* @throws Exception If the file could not be opened.
* @throws LogicException When this abstract method is not implemented.
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var string $sh */
$sh = $input->getArgument('sh');

$this->store->folder('storage/sh/');
$this->classFactory->classFactory(self::PATH_SH, $sh);

$fileName = basename($sh);

$folder = $this->classFactory->getFolder();

$this->store->folder($folder);

$this->classFactory
->create($sh, ClassFactory::SH_EXTENSION, 'storage/sh/')
->create($fileName, ClassFactory::SH_EXTENSION, $folder)
->add("#!/bin/bash\n")
->close();

chmod("storage/sh/{$sh}.sh", 0755);

$output->writeln($this->warningOutput("\t>> SH: {$sh}"));
$output->writeln($this->warningOutput("\t>> SH: {$folder}{$fileName}." . ClassFactory::SH_EXTENSION));

$output->writeln($this->successOutput("\t>> SH: The script was generated successfully."));

Expand Down
7 changes: 3 additions & 4 deletions tests/Commands/Lion/SH/SHFileCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

class SHFileCommandTest extends Test
{
private const string URL_PATH = './storage/sh/';
private const string FILE_NAME = 'test-app';
private const string FILE = self::URL_PATH . self::FILE_NAME . '.sh';
private const string FILE = SHFileCommand::PATH_SH . self::FILE_NAME . '.sh';
private const string OUTPUT_MESSAGE = 'The script was generated successfully.';

private CommandTester $commandTester;
Expand All @@ -45,14 +44,14 @@ protected function setUp(): void

$this->commandTester = new CommandTester($application->find('new:sh'));

$this->createDirectory(self::URL_PATH);
$this->createDirectory(SHFileCommand::PATH_SH);

$this->initReflection($this->shFileCommand);
}

protected function tearDown(): void
{
$this->rmdirRecursively(self::URL_PATH);
$this->rmdirRecursively(SHFileCommand::PATH_SH);
}

/**
Expand Down
Loading