-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from 123inkt/Add_option_to_opt_out_of_parent_m…
…ethod_checks Added option to exclude class methods or all parent methods
- Loading branch information
Showing
63 changed files
with
827 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace DigitalRevolution\AccessorPairConstraint\Constraint\MethodPair; | ||
|
||
use DigitalRevolution\AccessorPairConstraint\Constraint\ConstraintConfig; | ||
use ReflectionClass; | ||
use ReflectionMethod; | ||
|
||
class ClassMethodProvider | ||
{ | ||
/** @var ConstraintConfig */ | ||
private $config; | ||
|
||
public function __construct(ConstraintConfig $config) | ||
{ | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* @return ReflectionMethod[] | ||
*/ | ||
public function getMethods(ReflectionClass $class): array | ||
{ | ||
$excludeParentMethods = $this->config->isAssertParentMethods() === false; | ||
$excludedMethods = $this->config->getExcludedMethods(); | ||
|
||
$methods = []; | ||
foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { | ||
// exclude all methods that are not from the class' parent class. | ||
if ($excludeParentMethods && $class->getName() !== $method->getDeclaringClass()->getName()) { | ||
continue; | ||
} | ||
|
||
// method is specifically excluded | ||
if (in_array($method->getName(), $excludedMethods, true)) { | ||
continue; | ||
} | ||
|
||
$methods[] = $method; | ||
} | ||
|
||
return $methods; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace DigitalRevolution\AccessorPairConstraint\Tests\Unit\Constraint\MethodPair; | ||
|
||
use DigitalRevolution\AccessorPairConstraint\Constraint\ConstraintConfig; | ||
|
||
/** | ||
* @suppressWarnings(PHPMD.NumberOfChildren) | ||
*/ | ||
abstract class AbstractDataClass | ||
{ | ||
/** | ||
* Return the config used for the AccessorPairProvider test | ||
*/ | ||
public function getConfig(): ConstraintConfig | ||
{ | ||
return new ConstraintConfig(); | ||
} | ||
|
||
/** | ||
* Expect to return: | ||
* - method name of getter | ||
* - method name of setter | ||
* - true if the method has multi setter | ||
* @return array<int, array{0:string, 1:string, 2:bool}> | ||
*/ | ||
abstract public function getExpectedPairs(): array; | ||
} |
Oops, something went wrong.