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 <?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; namespace Irstea\CS;
use PhpCsFixer\Config as PhpCsFixerConfig; use PhpCsFixer\Config as PhpCsFixerConfig;
/** /**
* Class Config * Class Config.
*/ */
final class Config extends PhpCsFixerConfig final class Config extends PhpCsFixerConfig
{ {
...@@ -144,13 +151,14 @@ final class Config extends PhpCsFixerConfig ...@@ -144,13 +151,14 @@ final class Config extends PhpCsFixerConfig
function () { function () {
$last = date('Y'); $last = date('Y');
$first = exec('git log --format=%cd --date=format:%Y --date-order | tail -n1') ?? $last; $first = exec('git log --format=%cd --date=format:%Y --date-order | tail -n1') ?? $last;
return ($last !== null && $last !== $first) ? "$first-$last" : $first; return ($last !== null && $last !== $first) ? "$first-$last" : $first;
} }
); );
} }
/** /**
* @return boolean[] * @return bool[]
*/ */
private function ruleSets() private function ruleSets()
{ {
...@@ -216,7 +224,7 @@ final class Config extends PhpCsFixerConfig ...@@ -216,7 +224,7 @@ final class Config extends PhpCsFixerConfig
$commit = $this->getHeadCommit(); $commit = $this->getHeadCommit();
$cache = $this->loadCache(); $cache = $this->loadCache();
if (!isset($cache[$commit][$key])) { 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] = [];
} }
$cache[$commit][$key] = $generator(); $cache[$commit][$key] = $generator();
...@@ -234,6 +242,7 @@ final class Config extends PhpCsFixerConfig ...@@ -234,6 +242,7 @@ final class Config extends PhpCsFixerConfig
if ($this->commit === null) { if ($this->commit === null) {
$this->commit = trim(shell_exec('git rev-parse HEAD')); $this->commit = trim(shell_exec('git rev-parse HEAD'));
} }
return $this->commit; return $this->commit;
} }
...@@ -248,6 +257,7 @@ final class Config extends PhpCsFixerConfig ...@@ -248,6 +257,7 @@ final class Config extends PhpCsFixerConfig
$this->cache = json_decode(file_get_contents($this->cacheFile), true); $this->cache = json_decode(file_get_contents($this->cacheFile), true);
} }
} }
return $this->cache; return $this->cache;
} }
...@@ -258,5 +268,4 @@ final class Config extends PhpCsFixerConfig ...@@ -258,5 +268,4 @@ final class Config extends PhpCsFixerConfig
{ {
file_put_contents($this->cacheFile, json_encode($cache)); 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