Skip to content

Commit

Permalink
add contract interface (#5)
Browse files Browse the repository at this point in the history
* add contract interface

* misc
  • Loading branch information
TomasVotruba authored Feb 18, 2024
1 parent c8dcab7 commit 71baeef
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 30 deletions.
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

0 comments on commit 71baeef

Please sign in to comment.