-
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.
feat: install netlogix/coding-guidelines-php
- Loading branch information
Showing
11 changed files
with
126 additions
and
75 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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Netlogix\CodingGuidelines\Php\DefaultPhp; | ||
use Symplify\EasyCodingStandard\Config\ECSConfig; | ||
|
||
return static function (ECSConfig $ecsConfig): void { | ||
(new DefaultPhp())->configure($ecsConfig); | ||
|
||
$ecsConfig->paths( | ||
[ | ||
__DIR__ . '/src', | ||
__DIR__ . '/tests', | ||
] | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netlogix\DependencyResolver; | ||
|
||
interface ResettableTaskPoolInterface extends TaskPoolInterface { | ||
|
||
function reset(): self; | ||
|
||
interface ResettableTaskPoolInterface extends TaskPoolInterface | ||
{ | ||
public function reset(): self; | ||
} |
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 |
---|---|---|
@@ -1,26 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netlogix\DependencyResolver; | ||
|
||
interface TaskInterface | ||
{ | ||
function getName(): string; | ||
public function getName(): string; | ||
|
||
/** | ||
* @return string[] Names of tasks that need to be resolved before this task can be resolved | ||
*/ | ||
function getDependencies(): array; | ||
public function getDependencies(): array; | ||
|
||
/** | ||
* @param string[] $resolvedTasks Names of tasks that are already resolved | ||
* @return bool | ||
*/ | ||
function checkDependencies(array $resolvedTasks): bool; | ||
public function checkDependencies(array $resolvedTasks): bool; | ||
|
||
function resolve(): self; | ||
public function resolve(): self; | ||
|
||
function reset(): self; | ||
public function reset(): self; | ||
|
||
function isResolved(): bool; | ||
public function isResolved(): bool; | ||
} |
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 |
---|---|---|
@@ -1,47 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netlogix\DependencyResolver; | ||
|
||
use ArrayIterator; | ||
use InvalidArgumentException; | ||
use Traversable; | ||
|
||
class TaskPool implements ResettableTaskPoolInterface | ||
{ | ||
private array $tasks = []; | ||
function __construct( | ||
iterable $tasks = [] | ||
) | ||
|
||
public function __construct(iterable $tasks = []) | ||
{ | ||
foreach ($tasks as $task) { | ||
$this->addTask($task); | ||
} | ||
} | ||
|
||
function addTask(TaskInterface $task): self | ||
public function addTask(TaskInterface $task): self | ||
{ | ||
if (isset($this->tasks[$task->getName()])) { | ||
throw new \InvalidArgumentException('Task already exists'); | ||
throw new InvalidArgumentException('Task already exists'); | ||
} | ||
|
||
$this->tasks[$task->getName()] = $task; | ||
|
||
return $this; | ||
} | ||
|
||
function getTask(string $name): TaskInterface | ||
public function getTask(string $name): TaskInterface | ||
{ | ||
if (!isset($this->tasks[$name])) { | ||
throw new \InvalidArgumentException(sprintf('Task "%s" does not exist', $name)); | ||
throw new InvalidArgumentException(sprintf('Task "%s" does not exist', $name)); | ||
} | ||
|
||
return $this->tasks[$name]; | ||
} | ||
|
||
function getIterator(): \Traversable | ||
public function getIterator(): Traversable | ||
{ | ||
return new \ArrayIterator($this->tasks); | ||
return new ArrayIterator($this->tasks); | ||
} | ||
|
||
function reset(): self | ||
public function reset(): self | ||
{ | ||
array_map(fn($t) => $t->reset(), $this->tasks); | ||
array_map(fn ($t) => $t->reset(), $this->tasks); | ||
|
||
return $this; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,14 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netlogix\DependencyResolver; | ||
|
||
interface TaskPoolInterface extends \IteratorAggregate { | ||
use IteratorAggregate; | ||
use Traversable; | ||
|
||
interface TaskPoolInterface extends IteratorAggregate | ||
{ | ||
/** | ||
* @return \Traversable<TaskInterface> | ||
* @return Traversable<TaskInterface> | ||
*/ | ||
function getIterator(): \Traversable; | ||
public function getIterator(): Traversable; | ||
|
||
function getTask(string $name): TaskInterface; | ||
public function getTask(string $name): TaskInterface; | ||
} |
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
Oops, something went wrong.