From 1932eb37d9b08b5eebe04f12db04f88e850f7d08 Mon Sep 17 00:00:00 2001 From: mscherer Date: Fri, 2 Oct 2020 02:12:15 +0200 Subject: [PATCH 1/3] Add behavior remove autocomplete. --- docs/Generator.md | 1 + src/Generator/Task/BehaviorTask.php | 28 +++++++++++++++---- .../Generator/Task/BehaviorTaskTest.php | 14 +++++++++- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/docs/Generator.md b/docs/Generator.md index 4d2f0542..c8acadcf 100644 --- a/docs/Generator.md +++ b/docs/Generator.md @@ -111,6 +111,7 @@ Note: Using Configure key `'IdeHelper.preemptive'` set to `true` you can be a bi The following is now auto-completed, for example: ```php $this->addBehavior('Tools.Slugged'); +$this->removeBehavior('Slugged'); // Note the alias without plugin prefix ``` #### Components diff --git a/src/Generator/Task/BehaviorTask.php b/src/Generator/Task/BehaviorTask.php index f30fe909..2647ddcb 100644 --- a/src/Generator/Task/BehaviorTask.php +++ b/src/Generator/Task/BehaviorTask.php @@ -17,26 +17,42 @@ class BehaviorTask implements TaskInterface { /** * @var int[] */ - protected $aliases = [ + protected $addAliases = [ '\\' . self::CLASS_TABLE . '::addBehavior()' => 0, ]; + /** + * @var int[] + */ + protected $removeAliases = [ + '\\' . self::CLASS_TABLE . '::removeBehavior()' => 0, + ]; + /** * @return \IdeHelper\Generator\Directive\BaseDirective[] */ public function collect(): array { - $list = []; + $addList = []; $behaviors = $this->collectBehaviors(); foreach ($behaviors as $name => $className) { - $list[$name] = StringName::create($name); + $addList[$name] = StringName::create($name); + if (strpos($name, '.') !== false) { + [, $name] = pluginSplit($name); + } + $removeList[$name] = StringName::create($name); } - ksort($list); + ksort($addList); + ksort($removeList); $result = []; - foreach ($this->aliases as $alias => $position) { - $directive = new ExpectedArguments($alias, $position, $list); + foreach ($this->addAliases as $alias => $position) { + $directive = new ExpectedArguments($alias, $position, $addList); + $result[$directive->key()] = $directive; + } + foreach ($this->removeAliases as $alias => $position) { + $directive = new ExpectedArguments($alias, $position, $removeList); $result[$directive->key()] = $directive; } diff --git a/tests/TestCase/Generator/Task/BehaviorTaskTest.php b/tests/TestCase/Generator/Task/BehaviorTaskTest.php index e4c77a8e..81fa87ab 100644 --- a/tests/TestCase/Generator/Task/BehaviorTaskTest.php +++ b/tests/TestCase/Generator/Task/BehaviorTaskTest.php @@ -27,7 +27,7 @@ public function setUp(): void { public function testCollect() { $result = $this->task->collect(); - $this->assertCount(1, $result); + $this->assertCount(2, $result); /** @var \IdeHelper\Generator\Directive\Override $directive */ $directive = array_shift($result); @@ -40,6 +40,18 @@ public function testCollect() { $expected = '\'Shim.Nullable\''; $this->assertSame($expected, (string)$list['Shim.Nullable']); + + /** @var \IdeHelper\Generator\Directive\Override $directive */ + $directive = array_shift($result); + $this->assertSame('\Cake\ORM\Table::removeBehavior()', $directive->toArray()['method']); + + $list = $directive->toArray()['list']; + + $expected = '\'Timestamp\''; + $this->assertSame($expected, (string)$list['Timestamp']); + + $expected = '\'Nullable\''; + $this->assertSame($expected, (string)$list['Nullable']); } } From de52c6255231fb84fd99545f5a86982037d619dc Mon Sep 17 00:00:00 2001 From: mscherer Date: Fri, 2 Oct 2020 10:58:16 +0200 Subject: [PATCH 2/3] Fix tests. --- tests/test_files/meta/phpstorm/.meta.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_files/meta/phpstorm/.meta.php b/tests/test_files/meta/phpstorm/.meta.php index 8e3be7d0..043c84e5 100644 --- a/tests/test_files/meta/phpstorm/.meta.php +++ b/tests/test_files/meta/phpstorm/.meta.php @@ -367,6 +367,17 @@ ]) ); + expectedArguments( + \Cake\ORM\Table::removeBehavior(), + 0, + 'CounterCache', + 'My', + 'Nullable', + 'Timestamp', + 'Translate', + 'Tree' + ); + override( \Cake\ORM\TableRegistry::get(0), map([ From 55dab9c0c6ac98907fcfd45ec7d63a7a155c9b27 Mon Sep 17 00:00:00 2001 From: mscherer Date: Fri, 2 Oct 2020 11:10:45 +0200 Subject: [PATCH 3/3] Fix CS. --- src/Generator/Task/BehaviorTask.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Generator/Task/BehaviorTask.php b/src/Generator/Task/BehaviorTask.php index 2647ddcb..18fc1afd 100644 --- a/src/Generator/Task/BehaviorTask.php +++ b/src/Generator/Task/BehaviorTask.php @@ -32,8 +32,7 @@ class BehaviorTask implements TaskInterface { * @return \IdeHelper\Generator\Directive\BaseDirective[] */ public function collect(): array { - - $addList = []; + $addList = $removeList = []; $behaviors = $this->collectBehaviors(); foreach ($behaviors as $name => $className) { $addList[$name] = StringName::create($name);