-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
256 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Aeliot\TodoRegistrar\Config; | ||
use Aeliot\TodoRegistrar\Service\File\Finder; | ||
|
||
return (new Config()) | ||
->setFinder(new Finder()); |
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,56 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
use Aeliot\TodoRegistrar\ApplicationFactory; | ||
use Aeliot\TodoRegistrar\Config; | ||
|
||
$autoloaderPath = (static function (): string { | ||
$paths = [ | ||
__DIR__ . '/vendor/autoload.php', | ||
__DIR__ . '/../vendor/autoload.php', | ||
__DIR__ . '/../../vendor/autoload.php', | ||
__DIR__ . '/../../../vendor/autoload.php', | ||
]; | ||
|
||
foreach ($paths as $path) { | ||
if (file_exists($path)) { | ||
return realpath($path); | ||
} | ||
} | ||
|
||
throw new RuntimeException('Cannot find autoloader'); | ||
})(); | ||
|
||
require_once $autoloaderPath; | ||
|
||
$projectPath = dirname($autoloaderPath, 2); | ||
|
||
$absolutePathMaker = static function (string $path) use ($projectPath): string { | ||
if (preg_match('#^(?:[[:alpha:]]:[/\\\\]|/)#', $path)) { | ||
return $path; | ||
} | ||
|
||
return $projectPath . '/' . $path; | ||
}; | ||
|
||
$options = (static function () use ($absolutePathMaker): array { | ||
$values = []; | ||
$options = getopt('c:', ['config']); | ||
$defaults = [ | ||
'config' => ['c', '.todo-registrar.dist.php'], | ||
]; | ||
|
||
foreach ($defaults as $long => [$short, $default]) { | ||
if (isset($options[$short], $options[$long])) { | ||
throw new InvalidArgumentException(sprintf('Option %s is duplicated', $long)); | ||
} | ||
$values[$long] = $absolutePathMaker($options[$short] ?? $options[$long] ?? $default); | ||
} | ||
|
||
return $values; | ||
})(); | ||
|
||
/** @var Config $config */ | ||
$config = require $options['config']; | ||
|
||
(new ApplicationFactory())->create($config)->run(); |
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Aeliot\TodoRegistrar; | ||
|
||
use Aeliot\TodoRegistrar\Service\File\Finder; | ||
use Aeliot\TodoRegistrar\Service\FileProcessor; | ||
|
||
final class Application | ||
{ | ||
public function __construct( | ||
private Finder $finder, | ||
private FileProcessor $fileProcessor, | ||
) { | ||
} | ||
|
||
public function run(): void | ||
{ | ||
foreach ($this->finder as $file) { | ||
$this->fileProcessor->process($file); | ||
} | ||
} | ||
} |
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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Aeliot\TodoRegistrar; | ||
|
||
use Aeliot\TodoRegistrar\Service\Comment\Detector; | ||
use Aeliot\TodoRegistrar\Service\Comment\Extractor; | ||
use Aeliot\TodoRegistrar\Service\CommentRegistrar; | ||
use Aeliot\TodoRegistrar\Service\File\Saver; | ||
use Aeliot\TodoRegistrar\Service\File\Tokenizer; | ||
use Aeliot\TodoRegistrar\Service\FileProcessor; | ||
use Aeliot\TodoRegistrar\Service\Registrar\RegistrarFactory; | ||
use Aeliot\TodoRegistrar\Service\Registrar\RegistrarInterface; | ||
|
||
final class ApplicationFactory | ||
{ | ||
public function create(Config $config): Application | ||
{ | ||
$registrar = $this->createRegistrar($config); | ||
$commentRegistrar = $this->createCommentRegistrar($registrar); | ||
$fileProcessor = $this->createFileProcessor($commentRegistrar); | ||
|
||
return new Application( | ||
$config->getFinder(), | ||
$fileProcessor, | ||
); | ||
} | ||
|
||
private function createCommentRegistrar(RegistrarInterface $registrar): CommentRegistrar | ||
{ | ||
return new CommentRegistrar( | ||
new Detector(), | ||
new Extractor(), | ||
$registrar, | ||
); | ||
} | ||
|
||
private function createFileProcessor(CommentRegistrar $commentRegistrar): FileProcessor | ||
{ | ||
return new FileProcessor( | ||
$commentRegistrar, | ||
new Saver(), | ||
new Tokenizer(), | ||
); | ||
} | ||
|
||
private function createRegistrar(Config $config): RegistrarInterface | ||
{ | ||
return (new RegistrarFactory())->createRegistrar( | ||
$config->getRegistrarType(), | ||
$config->getRegistrarConfig(), | ||
); | ||
} | ||
} |
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,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Aeliot\TodoRegistrar; | ||
|
||
use Aeliot\TodoRegistrar\Enum\RegistrarType; | ||
use Aeliot\TodoRegistrar\Service\File\Finder; | ||
|
||
final class Config | ||
{ | ||
private Finder $finder; | ||
/** | ||
* @var array<string,mixed> | ||
*/ | ||
private array $registrarConfig; | ||
private RegistrarType $registrarType; | ||
|
||
public function getFinder(): Finder | ||
{ | ||
return $this->finder; | ||
} | ||
|
||
public function setFinder(Finder $finder): self | ||
{ | ||
$this->finder = $finder; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return array<string,mixed> | ||
*/ | ||
public function getRegistrarConfig(): array | ||
{ | ||
return $this->registrarConfig; | ||
} | ||
|
||
public function getRegistrarType(): RegistrarType | ||
{ | ||
return $this->registrarType; | ||
} | ||
|
||
/** | ||
* @param array<string,mixed> $config | ||
*/ | ||
public function setRegistrar(RegistrarType $type, array $config): self | ||
{ | ||
$this->registrarType = $type; | ||
$this->registrarConfig = $config; | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Aeliot\TodoRegistrar\Enum; | ||
|
||
enum RegistrarType: string | ||
{ | ||
case AzureBoards = 'AzureBoards'; | ||
case Github = 'Github'; | ||
case Gitlab = 'Gitlab'; | ||
case JIRA = 'JIRA'; | ||
case PivotalTracker = 'PivotalTracker'; | ||
case Redmine = 'Redmine'; | ||
case YouTrack = 'YouTrack'; | ||
} |
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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Aeliot\TodoRegistrar\Service\Registrar; | ||
|
||
use Aeliot\TodoRegistrar\Enum\RegistrarType; | ||
|
||
final class RegistrarFactory | ||
{ | ||
/** | ||
* @param array<string,mixed> $config | ||
*/ | ||
public function createRegistrar(RegistrarType $type, array $config): RegistrarInterface | ||
{ | ||
return $this->getExactFactory($type)->create($config); | ||
} | ||
|
||
private function getExactFactory(RegistrarType $type): RegistrarFactoryInterface | ||
{ | ||
return match ($type) { | ||
// TODO add factory of different registrars | ||
default => throw new \DomainException(sprintf('Not supported registrar type "%s"', $type->value)), | ||
}; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Aeliot\TodoRegistrar\Service\Registrar; | ||
|
||
interface RegistrarFactoryInterface | ||
{ | ||
/** | ||
* @param array<string,mixed> $config | ||
*/ | ||
public function create(array $config): RegistrarInterface; | ||
} |