Skip to content
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

add contract interface #5

Merged
merged 2 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions src/ClassPropertyExtension/AbstractClassPropertyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
use PHPStan\Reflection\PropertiesClassReflectionExtension;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStanCakePHP2\Contract\PropertyNameExtensionInterface;
use PHPStanCakePHP2\Reflection\PublicReadOnlyPropertyReflection;

abstract class AbstractClassPropertyExtension implements PropertiesClassReflectionExtension
abstract class AbstractClassPropertyExtension implements PropertiesClassReflectionExtension, PropertyNameExtensionInterface
{
private ReflectionProvider $reflectionProvider;

Expand Down Expand Up @@ -42,26 +43,4 @@ public function getProperty(

return new PublicReadOnlyPropertyReflection($correctedPropertyName, $classReflection);
}

/**
* @todo use constract instead to separate
* Get the class name of the type of property.
*/
abstract protected function getPropertyParentClassName(): string;

/**
* @todo use constract instead to separate
* Get the class names which can contain the property.
*
* @return array<string>
*/
abstract protected function getContainingClassNames(): array;

/**
* @todo use constract instead to separate
* Return the class name from the property name.
*/
abstract protected function getClassNameFromPropertyName(
string $propertyName
): string;
}
6 changes: 3 additions & 3 deletions src/ClassPropertyExtension/ClassModelsPropertyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
*/
final class ClassModelsPropertyExtension extends AbstractClassPropertyExtension
{
protected function getPropertyParentClassName(): string
public function getPropertyParentClassName(): string
{
return 'Model';
}

/**
* @return array<string>
*/
protected function getContainingClassNames(): array
public function getContainingClassNames(): array
{
return [
'Controller',
Expand All @@ -26,7 +26,7 @@ protected function getContainingClassNames(): array
];
}

protected function getClassNameFromPropertyName(
public function getClassNameFromPropertyName(
string $propertyName
): string {
return $propertyName;
Expand Down
6 changes: 3 additions & 3 deletions src/ClassPropertyExtension/ShellClassPropertyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
*/
final class ShellClassPropertyExtension extends AbstractClassPropertyExtension
{
protected function getPropertyParentClassName(): string
public function getPropertyParentClassName(): string
{
return 'Shell';
}

/**
* @return array<string>
*/
protected function getContainingClassNames(): array
public function getContainingClassNames(): array
{
return ['Shell'];
}

protected function getClassNameFromPropertyName(
public function getClassNameFromPropertyName(
string $propertyName
): string {
return $propertyName . 'Task';
Expand Down
25 changes: 25 additions & 0 deletions src/Contract/PropertyNameExtensionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace PHPStanCakePHP2\Contract;

interface PropertyNameExtensionInterface
{
/**
* Get the class name of the type of property.
*/
public function getPropertyParentClassName(): string;

/**
* Get the class names which can contain the property.
*
* @return string[]
*/
public function getContainingClassNames(): array;

/**
* Return the class name from the property name.
*/
public function getClassNameFromPropertyName(string $propertyName): string;
}
1 change: 0 additions & 1 deletion tests/config/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ parameters:
behaviorPaths:
- tests/Source/Model/Behavior/*.php

# @todo add exists validatoin to avoid misspaths
schemaPaths:
- tests/Source/Config/Schema/*.php

Expand Down
Loading