-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Support custom application namespace #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.next-cake5
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,12 +42,22 @@ class AddAssociationExistsTableClassRule extends LoadObjectExistsCakeClassRule | |
| */ | ||
| protected array $associationCollectionMethods = ['load']; | ||
|
|
||
| private readonly CakeNameRegistry $cakeNameRegistry; | ||
|
|
||
| /** | ||
| * @param \CakeDC\PHPStan\Utility\CakeNameRegistry $cakeNameRegistry | ||
| */ | ||
| public function __construct(?CakeNameRegistry $cakeNameRegistry = null) | ||
| { | ||
| $this->cakeNameRegistry = $cakeNameRegistry ?? CakeNameRegistry::instance(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| } | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| protected function getTargetClassName(string $name): ?string | ||
| { | ||
| return CakeNameRegistry::getTableClassName($name); | ||
| return $this->cakeNameRegistry->getTableClassName($name); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,12 +38,22 @@ class AddBehaviorExistsClassRule extends LoadObjectExistsCakeClassRule | |
| 'load', | ||
| ]; | ||
|
|
||
| private readonly CakeNameRegistry $cakeNameRegistry; | ||
|
|
||
| /** | ||
| * @param \CakeDC\PHPStan\Utility\CakeNameRegistry $cakeNameRegistry | ||
| */ | ||
| public function __construct(?CakeNameRegistry $cakeNameRegistry = null) | ||
| { | ||
| $this->cakeNameRegistry = $cakeNameRegistry ?? CakeNameRegistry::instance(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
| } | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| protected function getTargetClassName(string $name): ?string | ||
| { | ||
| return CakeNameRegistry::getBehaviorClassName($name); | ||
| return $this->cakeNameRegistry->getBehaviorClassName($name); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| use Cake\Console\ConsoleIo; | ||
| use Cake\Console\Helper; | ||
| use CakeDC\PHPStan\Traits\BaseCakeRegistryReturnTrait; | ||
| use CakeDC\PHPStan\Utility\CakeNameRegistry; | ||
| use PHPStan\Type\DynamicMethodReturnTypeExtension; | ||
| use PHPStan\Type\Type; | ||
|
|
||
|
|
@@ -42,15 +43,18 @@ class ConsoleHelperLoadDynamicReturnTypeExtension implements DynamicMethodReturn | |
| */ | ||
| protected string $namespaceFormat; | ||
|
|
||
| private readonly CakeNameRegistry $cakeNameRegistry; | ||
|
|
||
| /** | ||
| * TableLocatorDynamicReturnTypeExtension constructor. | ||
| */ | ||
| public function __construct() | ||
| public function __construct(?CakeNameRegistry $cakeNameRegistry = null) | ||
| { | ||
| $this->className = ConsoleIo::class; | ||
| $this->methodName = 'helper'; | ||
| $this->defaultClass = Helper::class; | ||
| $this->namespaceFormat = '%s\\Command\Helper\\%sHelper'; | ||
| $this->cakeNameRegistry = $cakeNameRegistry ?? CakeNameRegistry::instance(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| use Cake\Utility\Inflector; | ||
| use CakeDC\PHPStan\Traits\BaseCakeRegistryReturnTrait; | ||
| use CakeDC\PHPStan\Traits\RepositoryReferenceTrait; | ||
| use CakeDC\PHPStan\Utility\CakeNameRegistry; | ||
| use PhpParser\Node\Expr\MethodCall; | ||
| use PHPStan\Analyser\Scope; | ||
| use PHPStan\Reflection\MethodReflection; | ||
|
|
@@ -56,14 +57,17 @@ class RepositoryEntityDynamicReturnTypeExtension implements DynamicMethodReturnT | |
| */ | ||
| protected string $namespaceFormat; | ||
|
|
||
| private readonly CakeNameRegistry $cakeNameRegistry; | ||
|
|
||
| /** | ||
| * @param class-string $className The target className. | ||
| */ | ||
| public function __construct(string $className) | ||
| public function __construct(string $className, ?CakeNameRegistry $cakeNameRegistry = null) | ||
| { | ||
| $this->className = $className; | ||
| $this->defaultClass = EntityInterface::class; | ||
| $this->namespaceFormat = '%s\\Model\Entity\\%s'; | ||
| $this->cakeNameRegistry = $cakeNameRegistry ?? CakeNameRegistry::instance(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. |
||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
|
|
||
| use Cake\Datasource\EntityInterface; | ||
| use CakeDC\PHPStan\Traits\BaseCakeRegistryReturnTrait; | ||
| use CakeDC\PHPStan\Utility\CakeNameRegistry; | ||
| use PhpParser\Node\Expr\MethodCall; | ||
| use PHPStan\Analyser\Scope; | ||
| use PHPStan\Reflection\MethodReflection; | ||
|
|
@@ -56,14 +57,17 @@ class RepositoryFirstArgIsTheReturnTypeExtension implements DynamicMethodReturnT | |
| */ | ||
| protected string $namespaceFormat; | ||
|
|
||
| private readonly CakeNameRegistry $cakeNameRegistry; | ||
|
|
||
| /** | ||
| * @param class-string $className The target className. | ||
| */ | ||
| public function __construct(string $className) | ||
| public function __construct(string $className, ?CakeNameRegistry $cakeNameRegistry = null) | ||
| { | ||
| $this->className = $className; | ||
| $this->defaultClass = EntityInterface::class; | ||
| $this->namespaceFormat = '%s\\Model\Entity\\%s'; | ||
| $this->cakeNameRegistry = $cakeNameRegistry ?? CakeNameRegistry::instance(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed
$this->cakeNameRegistry = $cakeNameRegistry ?? CakeNameRegistry::instance();? PHPStan should inject CakeNameRegistryThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rochamarcelo this was added for BC (see #66 (comment)). I can revert the change if is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Lets keep it for now.