Skip to content

Commit c345261

Browse files
committed
more cleanup
1 parent b79c021 commit c345261

File tree

14 files changed

+26
-157
lines changed

14 files changed

+26
-157
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
}
1212
],
1313
"minimum-stability": "dev",
14+
"prefer-stable": true,
1415
"require": {
1516
"php": ">=8.1.0",
1617
"phpstan/phpstan": "^1.0",

extension.neon

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ services:
6666
tags:
6767
- phpstan.broker.dynamicMethodReturnTypeExtension
6868
-
69-
class: CakeDC\PHPStan\Type\ShellHelperLoadDynamicReturnTypeExtension
70-
tags:
71-
- phpstan.broker.dynamicMethodReturnTypeExtension
72-
-
73-
factory: CakeDC\PHPStan\Type\ShellHelperLoadDynamicReturnTypeExtension(Cake\Console\ConsoleIo)
69+
class: CakeDC\PHPStan\Type\ConsoleHelperLoadDynamicReturnTypeExtension
7470
tags:
7571
- phpstan.broker.dynamicMethodReturnTypeExtension

src/Traits/BaseCakeRegistryReturnTrait.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use PHPStan\Type\ObjectType;
2020
use PHPStan\Type\Type;
2121

22+
use function Cake\Core\pluginSplit;
23+
2224
trait BaseCakeRegistryReturnTrait
2325
{
2426
/**
@@ -88,6 +90,6 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
8890
*/
8991
protected function pluginSplit($baseName): array
9092
{
91-
return \pluginSplit($baseName);
93+
return pluginSplit($baseName);
9294
}
9395
}

src/Type/ShellHelperLoadDynamicReturnTypeExtension.php renamed to src/Type/ConsoleHelperLoadDynamicReturnTypeExtension.php

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212

1313
namespace CakeDC\PHPStan\Type;
1414

15+
use Cake\Console\ConsoleIo;
16+
use Cake\Controller\Component;
1517
use CakeDC\PHPStan\Traits\BaseCakeRegistryReturnTrait;
16-
use Cake\Console\Helper;
17-
use Cake\Console\Shell;
1818
use PhpParser\Node\Expr\MethodCall;
1919
use PHPStan\Analyser\Scope;
2020
use PHPStan\Reflection\MethodReflection;
2121
use PHPStan\Type\DynamicMethodReturnTypeExtension;
2222
use PHPStan\Type\Type;
2323

24-
class ShellHelperLoadDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
24+
class ConsoleHelperLoadDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
2525
{
2626
use BaseCakeRegistryReturnTrait;
2727

@@ -37,13 +37,11 @@ class ShellHelperLoadDynamicReturnTypeExtension implements DynamicMethodReturnTy
3737
/**
3838
* TableLocatorDynamicReturnTypeExtension constructor.
3939
*
40-
* @param string|null $className The target className.
41-
* @param string|null $methodName The dynamic method to handle.
4240
*/
43-
public function __construct(?string $className = null, ?string $methodName = null)
41+
public function __construct()
4442
{
45-
$this->className = $className ?? Shell::class;
46-
$this->methodName = $methodName ?? 'helper';
43+
$this->className = ConsoleIo::class;
44+
$this->methodName = 'helper';
4745
}
4846

4947
/**
@@ -58,25 +56,9 @@ public function getTypeFromMethodCall(
5856
MethodCall $methodCall,
5957
Scope $scope
6058
): Type {
61-
$defaultClass = Helper::class;
62-
$namespaceFormat = [
63-
'%s\\Command\Helper\\%sHelper',
64-
'%s\\Shell\Helper\\%sHelper'
65-
];
59+
$defaultClass = Component::class;
60+
$namespaceFormat = '%s\\Command\Helper\\%sHelper';
6661

6762
return $this->getRegistryReturnType($methodReflection, $methodCall, $scope, $defaultClass, $namespaceFormat);
6863
}
69-
70-
/**
71-
* @param string $baseName
72-
* @return array
73-
* @psalm-return array{string|null, string}
74-
*/
75-
protected function pluginSplit($baseName): array
76-
{
77-
list($plugin, $name) = pluginSplit($baseName);
78-
$name = \ucfirst($name);
79-
80-
return [$plugin, $name];
81-
}
8264
}

tests/TestCase/Type/ShellHelperLoadDynamicReturnTypeExtensionTest.php

Lines changed: 0 additions & 76 deletions
This file was deleted.

tests/test_app/Shell/Helper/BazBazHelper.php renamed to tests/test_app/Command/Helper/BazBazHelper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1111
*/
1212

13-
namespace App\Shell\Helper;
13+
namespace App\Command\Helper;
1414

1515
use Cake\Console\Helper;
1616

@@ -24,16 +24,16 @@ class BazBazHelper extends Helper
2424
*/
2525
public function output(array $args): void
2626
{
27-
$this->_io->success('Sample text');
27+
$this->_io->success('Sample heading');
2828
}
2929

3030
/**
31-
* Sample foo method.
31+
* Custom method
3232
*
3333
* @return string
3434
*/
3535
public function foo(): string
3636
{
37-
return 'sample text';
37+
return 'Invoked!';
3838
}
3939
}

tests/test_app/Command/MyTestLoadCommand.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ class MyTestLoadCommand extends Command
2323
*/
2424
public function execute(Arguments $args, ConsoleIo $io)
2525
{
26-
$article = $this->loadModel('VeryCustomize00009Articles')
27-
->newSample();
28-
29-
$io->out(strval($article->get('title')));
26+
$this->fetchTable('VeryCustomize00009Articles')->newSample();
3027

3128
$io->helper('progress')->increment(1);
3229
$io->out($io->helper('BazBaz')->foo());

tests/test_app/Controller/MyTestLoadComponentController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ class MyTestLoadComponentController extends Controller
2424
*/
2525
public function myTest()
2626
{
27-
$model = TableRegistry::getTableLocator()->get('MyCustomSources');
28-
$this->loadComponent('Paginator')->paginate($model);
27+
$this->loadComponent('Flash')->success('Something');
2928
}
3029

3130
/**
@@ -36,7 +35,7 @@ public function myTest()
3635
public function lately()
3736
{
3837
//getLatestOne is defined at HelloWorld101010ArticlesTable
39-
$latest = $this->loadModel('CakeDC/MyPlugin.HelloWorld101010Articles')
38+
$latest = $this->fetchTable('CakeDC/MyPlugin.HelloWorld101010Articles')
4039
->getLatestOne();
4140
$this->set('latest', $latest);
4241
}

tests/test_app/Mailer/MyTestLoadMailer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class MyTestLoadMailer extends Mailer
2323
*/
2424
protected function sampleLoading()
2525
{
26-
$article = $this->loadModel('VeryCustomize00009Articles')
26+
$article = $this->fetchTable('VeryCustomize00009Articles')
2727
->newSample();
2828
$this->viewBuilder()->setVar('article', $article);
2929
}

tests/test_app/Model/Logic/Action/FixArticles.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function process()
2828
->where(['created <=' => new \DateTime('-30 days')])
2929
->all();
3030

31+
/** @var \Cake\ORM\Entity $record */
3132
foreach ($records as $record) {
3233
$Table->fixArticle($record);
3334
}

0 commit comments

Comments
 (0)