Skip to content

Commit

Permalink
Remove Shim plugin dependency (#325)
Browse files Browse the repository at this point in the history
* Remove shim dep
  • Loading branch information
dereuromark authored Sep 10, 2023
1 parent 3b86e10 commit 29a0ae3
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 29 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"require-dev": {
"cakephp/plugin-installer": "^2.0.1",
"cakephp/migrations": "^4.0.1",
"dereuromark/cakephp-shim": "dev-cake5",
"dereuromark/cakephp-shim": "^3.0.0",
"fig-r/psr2r-sniffer": "dev-next",
"phpunit/phpunit": "^10.1"
},
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Annotate/CallbacksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function execute(Arguments $args, ConsoleIo $io): int {
* @return void
*/
protected function _callbacks(string $folder) {
$this->io?->out(str_replace(ROOT, '', $folder), 1, ConsoleIo::VERBOSE);
$this->io->out(str_replace(ROOT, '', $folder), 1, ConsoleIo::VERBOSE);

$folderContent = glob($folder . '*') ?: [];
foreach ($folderContent as $path) {
Expand All @@ -83,7 +83,7 @@ protected function _callbacks(string $folder) {
continue;
}

$this->io?->out('-> ' . $name, 1, ConsoleIo::VERBOSE);
$this->io->out('-> ' . $name, 1, ConsoleIo::VERBOSE);

$annotator = $this->getAnnotator(CallbackAnnotator::class);
$annotator->annotate($path);
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Annotate/ClassesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function execute(Arguments $args, ConsoleIo $io): int {
* @return void
*/
protected function _classes(string $folder) {
$this->io?->out(str_replace(ROOT, '', $folder), 1, ConsoleIo::VERBOSE);
$this->io->out(str_replace(ROOT, '', $folder), 1, ConsoleIo::VERBOSE);

$folderContent = glob($folder . '*') ?: [];
foreach ($folderContent as $path) {
Expand Down Expand Up @@ -108,7 +108,7 @@ protected function _classes(string $folder) {
continue;
}

$this->io?->out('-> ' . $name, 1, ConsoleIo::VERBOSE);
$this->io->out('-> ' . $name, 1, ConsoleIo::VERBOSE);

$annotator = $this->getAnnotator(ClassAnnotator::class);
$annotator->annotate($path);
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Annotate/CommandsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function execute(Arguments $args, ConsoleIo $io): int {
* @return void
*/
protected function _commands(string $folder) {
$this->io?->out(str_replace(ROOT, '', $folder), 1, ConsoleIo::VERBOSE);
$this->io->out(str_replace(ROOT, '', $folder), 1, ConsoleIo::VERBOSE);

$folderContent = glob($folder . '*') ?: [];
foreach ($folderContent as $file) {
Expand All @@ -56,7 +56,7 @@ protected function _commands(string $folder) {
continue;
}

$this->io?->out('-> ' . $name, 1, ConsoleIo::VERBOSE);
$this->io->out('-> ' . $name, 1, ConsoleIo::VERBOSE);
$annotator = $this->getAnnotator(CommandAnnotator::class);
$annotator->annotate($file);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Annotate/ComponentsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function execute(Arguments $args, ConsoleIo $io): int {
* @return void
*/
protected function _components(string $folder) {
$this->io?->out(str_replace(ROOT, '', $folder), 1, ConsoleIo::VERBOSE);
$this->io->out(str_replace(ROOT, '', $folder), 1, ConsoleIo::VERBOSE);

$folderContent = glob($folder . '*') ?: [];
foreach ($folderContent as $path) {
Expand All @@ -56,7 +56,7 @@ protected function _components(string $folder) {
continue;
}

$this->io?->out('-> ' . $name, 1, ConsoleIo::VERBOSE);
$this->io->out('-> ' . $name, 1, ConsoleIo::VERBOSE);
$annotator = $this->getAnnotator(ComponentAnnotator::class);
$annotator->annotate($path);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Annotate/ControllersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function execute(Arguments $args, ConsoleIo $io): int {
* @return void
*/
protected function _controllers(string $folder) {
$this->io?->out(str_replace(ROOT, '', $folder), 1, ConsoleIo::VERBOSE);
$this->io->out(str_replace(ROOT, '', $folder), 1, ConsoleIo::VERBOSE);

$folderContent = glob($folder . '*') ?: [];
foreach ($folderContent as $path) {
Expand All @@ -69,7 +69,7 @@ protected function _controllers(string $folder) {
continue;
}

$this->io?->out('-> ' . $name, 1, ConsoleIo::VERBOSE);
$this->io->out('-> ' . $name, 1, ConsoleIo::VERBOSE);

$annotator = $this->getAnnotator(ControllerAnnotator::class);
$annotator->annotate($path);
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Annotate/HelpersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function execute(Arguments $args, ConsoleIo $io): int {
* @return void
*/
protected function _helpers($folder) {
$this->io?->out(str_replace(ROOT, '', $folder), 1, ConsoleIo::VERBOSE);
$this->io->out(str_replace(ROOT, '', $folder), 1, ConsoleIo::VERBOSE);

$folderContent = glob($folder . '*') ?: [];
foreach ($folderContent as $path) {
Expand All @@ -56,7 +56,7 @@ protected function _helpers($folder) {
continue;
}

$this->io?->out('-> ' . $name, 1, ConsoleIo::VERBOSE);
$this->io->out('-> ' . $name, 1, ConsoleIo::VERBOSE);
$annotator = $this->getAnnotator(HelperAnnotator::class);
$annotator->annotate($path);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Annotate/ModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function execute(Arguments $args, ConsoleIo $io): int {
* @return void
*/
protected function _models(string $folder) {
$this->io?->out(str_replace(ROOT, '', $folder), 1, ConsoleIo::VERBOSE);
$this->io->out(str_replace(ROOT, '', $folder), 1, ConsoleIo::VERBOSE);

$folderContent = glob($folder . '*') ?: [];
foreach ($folderContent as $file) {
Expand All @@ -56,7 +56,7 @@ protected function _models(string $folder) {
continue;
}

$this->io?->out('-> ' . $name, 1, ConsoleIo::VERBOSE);
$this->io->out('-> ' . $name, 1, ConsoleIo::VERBOSE);

$annotator = $this->getAnnotator(ModelAnnotator::class);
$annotator->annotate($file);
Expand Down
8 changes: 4 additions & 4 deletions src/Command/Annotate/TemplatesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function execute(Arguments $args, ConsoleIo $io): int {
* @return void
*/
protected function _templates($folder) {
$this->io?->out(str_replace(ROOT, '', $folder), 1, ConsoleIo::VERBOSE);
$this->io->out(str_replace(ROOT, '', $folder), 1, ConsoleIo::VERBOSE);

$folderContent = glob($folder . '*') ?: [];
foreach ($folderContent as $path) {
Expand All @@ -61,8 +61,8 @@ protected function _templates($folder) {
continue;
}

if ($this->args?->getOption('verbose')) {
$this->io?->warning(sprintf('Skipped template folder `%s`', str_replace(ROOT, '', $subFolder)));
if ($this->args->getOption('verbose')) {
$this->io->warning(sprintf('Skipped template folder `%s`', str_replace(ROOT, '', $subFolder)));
}

break;
Expand All @@ -84,7 +84,7 @@ protected function _templates($folder) {
continue;
}

$this->io?->out('-> ' . $name, 1, ConsoleIo::VERBOSE);
$this->io->out('-> ' . $name, 1, ConsoleIo::VERBOSE);
$annotator = $this->getAnnotator(TemplateAnnotator::class);
$annotator->annotate($path);
}
Expand Down
15 changes: 14 additions & 1 deletion src/Command/AnnotateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace IdeHelper\Command;

use Cake\Command\Command;
use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use Cake\Core\Configure;
use IdeHelper\Annotator\AbstractAnnotator;
use IdeHelper\Console\Io;
use Shim\Command\Command;

abstract class AnnotateCommand extends Command {

Expand Down Expand Up @@ -36,6 +36,16 @@ abstract class AnnotateCommand extends Command {
*/
protected array $_instantiatedAnnotators = [];

/**
* @var \Cake\Console\Arguments
*/
protected Arguments $args;

/**
* @var \Cake\Console\ConsoleIo
*/
protected ConsoleIo $io;

/**
* @return void
*/
Expand All @@ -59,6 +69,9 @@ public function initialize(): void {
* @return int|null|void The exit code or null for success
*/
public function execute(Arguments $args, ConsoleIo $io) {
$this->args = $args;
$this->io = $io;

parent::execute($args, $io);

if ($args->getOption('ci')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/GenerateCodeCompletionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace IdeHelper\Command;

use Cake\Command\Command;
use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use IdeHelper\CodeCompletion\CodeCompletionGenerator;
use IdeHelper\CodeCompletion\TaskCollection;
use Shim\Command\Command;

class GenerateCodeCompletionCommand extends Command {

Expand Down
9 changes: 8 additions & 1 deletion src/Command/GeneratePhpStormMetaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace IdeHelper\Command;

use Cake\Command\Command;
use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use IdeHelper\Console\Io;
use IdeHelper\Generator\PhpstormGenerator;
use IdeHelper\Generator\TaskCollection;
use RuntimeException;
use Shim\Command\Command;

class GeneratePhpStormMetaCommand extends Command {

Expand All @@ -18,6 +18,11 @@ class GeneratePhpStormMetaCommand extends Command {
*/
public const CODE_CHANGES = 2;

/**
* @var \Cake\Console\ConsoleIo
*/
protected ConsoleIo $io;

/**
* @return string
*/
Expand All @@ -33,6 +38,8 @@ public static function getDescription(): string {
* @return int The exit code or null for success
*/
public function execute(Arguments $args, ConsoleIo $io): int {
$this->io = $io;

parent::execute($args, $io);

$phpstormGenerator = $this->getGenerator();
Expand Down
22 changes: 15 additions & 7 deletions src/Command/IlluminateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace IdeHelper\Command;

use Cake\Command\Command;
use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
Expand All @@ -10,7 +11,6 @@
use IdeHelper\Illuminator\Illuminator;
use IdeHelper\Illuminator\TaskCollection;
use InvalidArgumentException;
use Shim\Command\Command;

class IlluminateCommand extends Command {

Expand All @@ -19,6 +19,11 @@ class IlluminateCommand extends Command {
*/
public const CODE_CHANGES = 2;

/**
* @var \Cake\Console\ConsoleIo
*/
protected ConsoleIo $io;

/**
* @return string
*/
Expand All @@ -37,7 +42,10 @@ public static function getDescription(): string {
* @return int The exit code or null for success
*/
public function execute(Arguments $args, ConsoleIo $io): int {
$this->io = $io;

parent::execute($args, $io);

$path = $args->getArgument('path');
if (!$path) {
$path = ($args->getOption('plugin') ? 'src' : APP_DIR) . DS;
Expand All @@ -52,7 +60,7 @@ public function execute(Arguments $args, ConsoleIo $io): int {
throw new InvalidArgumentException('Path does not exist: ' . $path);
}

$illuminator = $this->getIlluminator();
$illuminator = $this->getIlluminator($args);
$filesChanged = $illuminator->illuminate($path, (string)$args->getOption('filter') ?: null);
if (!$filesChanged) {
return static::CODE_SUCCESS;
Expand Down Expand Up @@ -114,14 +122,14 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
}

/**
* @param \Cake\Console\Arguments $args
*
* @return \IdeHelper\Illuminator\Illuminator
*/
protected function getIlluminator(): Illuminator {
assert($this->args !== null, 'Args not set');

$tasks = $this->args->getOption('task') ? explode(',', (string)$this->args->getOption('task')) : [];
protected function getIlluminator(Arguments $args): Illuminator {
$tasks = $args->getOption('task') ? explode(',', (string)$args->getOption('task')) : [];

$taskCollection = new TaskCollection($this->io(), $this->args->getOptions(), $tasks);
$taskCollection = new TaskCollection($this->io(), $args->getOptions(), $tasks);

return new Illuminator($taskCollection);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase/Command/GeneratePhpstormMetaCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class GeneratePhpstormMetaCommandTest extends TestCase {
*/
protected ConsoleOutput $err;

/**
* @var \Cake\Console\ConsoleIo
*/
protected ConsoleIo $io;

protected const META_FOLDER = ROOT . DS . '.phpstorm.meta.php' . DS;
Expand Down

0 comments on commit 29a0ae3

Please sign in to comment.