Commit 5f3a557c authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

CS.

Showing with 13 additions and 4 deletions
+13 -4
<?php
/*
* This file is part of "irstea/php-cs-fixer-config".
* (c) 2018 Irstea <dsi.poleis@irstea.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Irstea\CS;
use PhpCsFixer\Config as PhpCsFixerConfig;
/**
* Class Config
* Class Config.
*/
final class Config extends PhpCsFixerConfig
{
......@@ -144,13 +151,14 @@ final class Config extends PhpCsFixerConfig
function () {
$last = date('Y');
$first = exec('git log --format=%cd --date=format:%Y --date-order | tail -n1') ?? $last;
return ($last !== null && $last !== $first) ? "$first-$last" : $first;
}
);
}
/**
* @return boolean[]
* @return bool[]
*/
private function ruleSets()
{
......@@ -216,7 +224,7 @@ final class Config extends PhpCsFixerConfig
$commit = $this->getHeadCommit();
$cache = $this->loadCache();
if (!isset($cache[$commit][$key])) {
if (!isset($cache[$commit])) {
if (!isset($cache[$commit])) { // TODO: load a template from a local file.
$cache[$commit] = [];
}
$cache[$commit][$key] = $generator();
......@@ -234,6 +242,7 @@ final class Config extends PhpCsFixerConfig
if ($this->commit === null) {
$this->commit = trim(shell_exec('git rev-parse HEAD'));
}
return $this->commit;
}
......@@ -248,6 +257,7 @@ final class Config extends PhpCsFixerConfig
$this->cache = json_decode(file_get_contents($this->cacheFile), true);
}
}
return $this->cache;
}
......@@ -258,5 +268,4 @@ final class Config extends PhpCsFixerConfig
{
file_put_contents($this->cacheFile, json_encode($cache));
}
}
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