Skip to content

Commit c4a8fce

Browse files
committed
Add addHelper() autocomplete for Cake4.
1 parent 357046b commit c4a8fce

File tree

7 files changed

+40
-1408
lines changed

7 files changed

+40
-1408
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ IdeHelper plugin for CakePHP applications.
1212

1313
> Boost your productivity. Avoid mistakes.
1414
15-
This branch is for use with **CakePHP 4.2+**. For details see [version map](https://github.com/dereuromark/cakephp-ide-helper/wiki#cakephp-version-map).
15+
This branch is for use with **CakePHP 4.4+**. For details see [version map](https://github.com/dereuromark/cakephp-ide-helper/wiki#cakephp-version-map).
1616

1717
## Features
1818

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"require": {
3333
"php": ">=7.4",
34-
"cakephp/cakephp": "^4.2.0",
34+
"cakephp/cakephp": "^4.4.0",
3535
"cakephp/bake": "^2.1.0",
3636
"sebastian/diff": "^4.0.3||^5.0",
3737
"phpstan/phpdoc-parser": "^1.7.0",

src/Generator/Task/HelperTask.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414

1515
class HelperTask implements TaskInterface {
1616

17-
public const CLASS_VIEW = View::class;
18-
public const CLASS_VIEW_BUILDER = ViewBuilder::class;
17+
protected const CLASS_VIEW = View::class;
18+
protected const CLASS_VIEW_BUILDER = ViewBuilder::class;
1919

2020
/**
21-
* @var string
21+
* @var array<string>
2222
*/
23-
protected const METHOD_VIEW = '\\' . self::CLASS_VIEW . '::loadHelper(0)';
23+
protected array $overrideMethods = [
24+
'\\' . self::CLASS_VIEW . '::loadHelper(0)',
25+
'\\' . self::CLASS_VIEW . '::addHelper(0)',
26+
];
2427

2528
/**
2629
* @var string
@@ -41,8 +44,10 @@ public function collect(): array {
4144

4245
$result = [];
4346

44-
$directive = new Override(static::METHOD_VIEW, $map);
45-
$result[$directive->key()] = $directive;
47+
foreach ($this->overrideMethods as $method) {
48+
$directive = new Override($method, $map);
49+
$result[$directive->key()] = $directive;
50+
}
4651

4752
$list = [];
4853
foreach ($helpers as $name => $className) {

tests/TestCase/Generator/PhpstormGeneratorTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ public function testCollect() {
5555
file_put_contents(TMP . '.meta.php', $result);
5656

5757
$file = Plugin::path('IdeHelper') . 'tests' . DS . 'test_files' . DS . 'meta' . DS . 'phpstorm' . DS . '.meta.php';
58-
if (version_compare(Configure::version(), '4.4.0') > 0) {
59-
$file = Plugin::path('IdeHelper') . 'tests' . DS . 'test_files' . DS . 'meta' . DS . 'phpstorm' . DS . '.meta-44.php';
60-
}
6158
$expected = file_get_contents($file);
6259

6360
$this->assertTextEquals($expected, $result);

tests/TestCase/Generator/Task/HelperTaskTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ protected function setUp(): void {
2727
public function testCollect() {
2828
$result = $this->task->collect();
2929

30-
$this->assertCount(2, $result);
30+
$this->assertCount(3, $result);
3131

3232
/** @var \IdeHelper\Generator\Directive\Override $directive */
3333
$directive = array_shift($result);
3434
$this->assertSame('\Cake\View\View::loadHelper(0)', $directive->toArray()['method']);
3535

36+
/** @var \IdeHelper\Generator\Directive\Override $directive */
37+
$directive = array_shift($result);
38+
$this->assertSame('\Cake\View\View::addHelper(0)', $directive->toArray()['method']);
39+
3640
$map = $directive->toArray()['map'];
3741

3842
$expected = '\Cake\View\Helper\FormHelper::class';

0 commit comments

Comments
 (0)