Skip to content

Commit

Permalink
Move checkbox list to a trait for re-use
Browse files Browse the repository at this point in the history
  • Loading branch information
bennothommo committed Sep 4, 2020
1 parent ce12834 commit 68afc38
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 33 deletions.
36 changes: 3 additions & 33 deletions src/Commands/InstallCheck/Command.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace BennoThommo\OctoberCli\Commands\InstallCheck;

use BennoThommo\OctoberCli\BaseCommand;
use BennoThommo\OctoberCli\Traits\CheckboxList;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -12,6 +13,8 @@
*/
class Command extends BaseCommand
{
use CheckboxList;

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -56,39 +59,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->checkFilterExtension();
}

protected function doCheck($text)
{
$this->section = $this->output->section();
$this->sectionText = $text;
$this->section->writeln('[ ] ' . $text);
}

protected function checkFailed()
{
$this->section->overwrite('[<error>X</error>] ' . $this->sectionText);
if (func_num_args() > 0) {
$this->section->writeln("<comment> " . implode("\n ", func_get_args()) . '</comment>');
}
$this->failed = true;
}

protected function checkWarned()
{
$this->section->overwrite('[<warn>W</warn>] ' . $this->sectionText);
if (func_num_args() > 0) {
$this->section->writeln("<comment> " . implode("\n ", func_get_args()) . '</comment>');
}
$this->warned = true;
}

protected function checkSuccessful()
{
$this->section->overwrite('[<success>✓</success>] ' . $this->sectionText);
if (func_num_args() > 0) {
$this->section->writeln("<comment> " . implode("\n ", func_get_args()) . '</comment>');
}
}

protected function checkPHPVersion()
{
$this->doCheck('Installed PHP version is 7.2.9 or higher.');
Expand Down
48 changes: 48 additions & 0 deletions src/Traits/CheckboxList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php namespace BennoThommo\OctoberCli\Traits;

use Symfony\Component\Console\Output\OutputInterface;

trait CheckboxList
{
/** @var OutputInterface Output interface */
protected $output;

/**
* Writes out a checkbox item to console.
*
* @param [type] $text
* @return void
*/
protected function doCheck($text)
{
$this->section = $this->output->section();
$this->sectionText = $text;
$this->section->writeln('[ ] ' . $text);
}

protected function checkFailed()
{
$this->section->overwrite('[<error>X</error>] ' . $this->sectionText);
if (func_num_args() > 0) {
$this->section->writeln("<comment> " . implode("\n ", func_get_args()) . '</comment>');
}
$this->failed = true;
}

protected function checkWarned()
{
$this->section->overwrite('[<warn>W</warn>] ' . $this->sectionText);
if (func_num_args() > 0) {
$this->section->writeln("<comment> " . implode("\n ", func_get_args()) . '</comment>');
}
$this->warned = true;
}

protected function checkSuccessful()
{
$this->section->overwrite('[<success>✓</success>] ' . $this->sectionText);
if (func_num_args() > 0) {
$this->section->writeln("<comment> " . implode("\n ", func_get_args()) . '</comment>');
}
}
}

0 comments on commit 68afc38

Please sign in to comment.