-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add attributes from spike - yet without tests
- Loading branch information
Showing
4 changed files
with
98 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ebln\PHPStan\EnforceFactory; | ||
|
||
/** | ||
* Marks classes to be instanciated by certain factories | ||
* | ||
* If used together with ForceFactoryInterface | ||
* the configured factories must be congruent! | ||
* This is enforced for PHP 8 and later. | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
class ForceFactory | ||
{ | ||
/** @var array<int, class-string> */ | ||
private array $allowedFactories; | ||
|
||
/** @param class-string ...$factories */ | ||
public function __construct(string ...$factories) | ||
{ | ||
$allowedFactories = []; | ||
foreach ($factories as $factory) { | ||
$allowedFactories[$factory] = $factory; | ||
} | ||
|
||
$this->allowedFactories = array_values($allowedFactories); | ||
} | ||
|
||
/** @return array<int, class-string> */ | ||
public function getAllowedFactories(): array | ||
{ | ||
return $this->allowedFactories; | ||
} | ||
} |
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