Commit 0ef5bf3d authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Ne plante pas si on ne trouve pas de dépôt git.

No related merge requests found
Showing with 21 additions and 7 deletions
+21 -7
......@@ -5,7 +5,6 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace Irstea\CS;
......@@ -167,8 +166,7 @@ final class Config extends PhpCsFixerConfig
$fileLocator = new FileLocator($callerPath);
$composerPackage = new ComposerPackage($fileLocator);
$repoPath = self::findGitRepository($callerPath);
$gitRepository = new GitRepository($repoPath);
$variables = self::getTemplateVariables($callerPath, $composerPackage);
$headerProvider = new FormattedHeaderProvider(
new ChainTemplateProvider(
......@@ -178,18 +176,34 @@ final class Config extends PhpCsFixerConfig
new LicenseTemplateProvider($composerPackage),
]
),
new TemplateFormatter($gitRepository, $composerPackage)
new TemplateFormatter($variables)
);
return new self($composerPackage, $headerProvider);
}
private static function findGitRepository(string $path): string
private static function getTemplateVariables(string $path, ComposerPackage $composerPackage): array
{
$gitRepository = self::findGitRepository($path);
return [
'%copyrightHolder%' => 'INRAE',
'%package%' => $composerPackage->getName(),
'%description%' => $composerPackage->getDescription(),
'%yearRange%' => $gitRepository ? $gitRepository->getYearRange() : date('Y'),
];
}
private static function findGitRepository(string $path): ?GitRepository
{
while (!is_dir($path . '/.git') && $path !== '/') {
while ($path !== '/') {
if (is_dir($path . '/.git')) {
return new GitRepository($path);
}
$path = \dirname($path);
}
return $path;
return null;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment