Skip to content

Commit

Permalink
fixed scrutinizer issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Apr 8, 2016
1 parent 24d81b7 commit e8776fd
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 32 deletions.
8 changes: 6 additions & 2 deletions src/controllers/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use hidev\helpers\Helper;
use Yii;
use yii\console\Response;

/**
* Abstract controller.
Expand Down Expand Up @@ -46,6 +47,9 @@ public function actionBefore()
return $this->runRequests($this->getBefore());
}

/**
* @return int|Response exit code
*/
public function actionMake()
{
return $this->runActions($this->getMake());
Expand Down Expand Up @@ -196,10 +200,10 @@ public function markDone($action, $time = null)
/**
* Runs given binary with given arguments. Returns exit code.
* @param string $name
* @param string $args
* @param array|string $args
* @return int exit code
*/
public static function passthru($name, $args = '')
public static function passthru($name, $args = [])
{
return static::takeGoal('binaries')->passthruBinary($name, $args);
}
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/BinariesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getItemConfig($name = null, array $config = [])
/**
* Prepares and runs with passthru. Returns exit code.
* @param string $name binary
* @param string $args
* @param array|string $args
* @return int exit code
*/
public function passthruBinary($name, $args = [])
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/GenerateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public static function template2file($template, $extension = '.php')

public function actionPerform($template = null, $file = null)
{
$this->template = $template;
$this->file = $file ?: static::template2file($template);
$this->setTemplate($template);
$this->setFile($file ?: static::template2file($template));

return parent::actionPerform();
}
Expand Down
18 changes: 12 additions & 6 deletions src/controllers/GitController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace hidev\controllers;

use Yii;
use yii\base\InvalidConfigException;

/**
* Controller for Git.
Expand Down Expand Up @@ -73,17 +73,23 @@ public function addHistory($commit)
$this->_history[$this->tag][$hash] = $commit;
}

/**
* Loads raw git history.
* @throws InvalidConfigException
*/
public function loadHistory()
{
if (!file_exists('.git')) {
return;
}
exec("git log --date=short --pretty='format:%h %ad %ae %s |%d'", $logs);
$this->tag = $this->lastTag;
if (empty($logs)) {
return;
}
foreach ($logs as $log) {
if (!preg_match('/^(\w+) ([0-9-]+) (\S+) (.*?)\s+\| ?(\([^\(\)]+\))?$/', $log, $m)) {
Yii::error('failed parse git log');
die();
throw new InvalidConfigException('failed parse git log');
}
$this->addHistory([
'hash' => $m[1],
Expand Down Expand Up @@ -132,10 +138,10 @@ public function getUserEmail()
public function getYear()
{
$tags = $this->getTags();
if ($tags) {
$date = array_pop($this->getTags());
} else {
if (empty($tags)) {
$date = `git log --reverse --pretty=%ai | head -n 1`;
} else {
$date = array_pop($tags);
}
$year = $date ? date('Y', strtotime($date)) : '';

Expand Down
1 change: 1 addition & 0 deletions src/controllers/InitController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace hidev\controllers;

use Exception;
use hidev\helpers\Helper;
use yii\base\InvalidParamException;

Expand Down
9 changes: 7 additions & 2 deletions src/controllers/VcsignoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ class VcsignoreController extends FileController
'.DS_Store' => 'IDE & OS files',
];

/**
* Load action.
*/
public function actionLoad()
{
$items = [];
foreach ($this->takeGoal('binaries')->keys() as $name) {
$items[$name . '.phar'] = 'PHARs';
}
Expand All @@ -41,10 +45,11 @@ public function actionLoad()
$this->takeVcs()->setIgnore($items);
}

/**
* Save action.
*/
public function actionSave()
{
$this->getFile()->save($this->takeVcs()->getIgnore());

return 0;
}
}
10 changes: 10 additions & 0 deletions src/handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ public function parsePath($path, $minimal = null)
return $this->parse($this->read($path));
}

/**
* Parses string input. To be redefined in real handlers.
* @param string $json
* @return array
*/
public function parse($json)
{
return [];
}

/**
* Writes given content to the file.
* Doesn't touch file if it has exactly same content.
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/ChangelogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function render($data)

foreach ($this->goal->takeGoal('commits')->getHistory() as $tag => $notes) {
$tag = CommitsHandler::arrayPop($notes, 'tag') ?: $tag;
$new = CommitsHandler::arrayPop($notes, '');
CommitsHandler::arrayPop($notes, '');
$res .= CommitsHandler::renderTag($tag);
$this->releaseNotes[$tag] = '';
foreach ($notes as $note => $cs) {
Expand Down
22 changes: 9 additions & 13 deletions src/handlers/CommitsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public function addTag($tag, $label = null)

public function addNote($note, $label = null)
{
$this->note = $note;
$ref = &$this->_history[$this->tag][$note]['note'];
$ref = $label ?: $ref ?: $note;
$this->setNote($note);
$ref = &$this->_history[$this->getTag()][$note]['note'];
$ref = $label ?: $ref ?: $note;
}

public function addHash($hash, $label)
Expand All @@ -86,11 +86,12 @@ public function hasCommit($hash)

public function parsePath($path, $minimal = null)
{
$this->tag = static::getVcs()->lastTag;
$this->setTag(static::getVcs()->lastTag);
$this->_history = [
$this->tag => [],
$this->getTag() => [],
];
$lines = is_file($path) ? $this->readArray($path) : [];
$no = 0;
foreach ($lines as $str) {
$str = rtrim($str);
++$no;
Expand Down Expand Up @@ -119,7 +120,7 @@ public function parsePath($path, $minimal = null)
if (preg_match('/^\s+- ([0-9a-fA-F]{7})/', $str, $m)) {
$this->addHash($m[1], $str);
}
$this->_history[$this->tag][$this->note][$this->hash][] = $str;
$this->_history[$this->getTag()][$this->getNote()][$this->getHash()][] = $str;
}

return $this->_history;
Expand Down Expand Up @@ -169,13 +170,10 @@ public function render($data)
$this->addHistory(['tag' => static::getVcs()->initTag]);
}

/// TODO
/// $this->cleanupHistory();

foreach ($this->_history as $tag => $notes) {
$prev = $res;
$tag = static::arrayPop($notes, 'tag') ?: $tag;
$new = static::arrayPop($notes, '') ?: [];
$tag = static::arrayPop($notes, 'tag') ?: $tag;
$new = static::arrayPop($notes, '') ?: [];
$res .= static::renderTag($tag);
$save = $res;
foreach ($new as $hash => $lines) {
Expand All @@ -188,8 +186,6 @@ public function render($data)
$res .= static::renderLines($lines);
}
}
/// TODO redo with cleanupHistory
/// skip empty Under development section
if ($save === $res && stripos($tag, static::getVcs()->lastTag) !== false) {
$res = $prev;
unset($this->_history[$tag]);
Expand Down
1 change: 1 addition & 0 deletions src/handlers/GitignoreHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function parsePath($path, $minimal = null)
{
$items = [];
$lines = is_file($path) ? $this->readArray($path) : [];
$comment = '';
foreach ($lines as $str) {
$str = trim($str);
if (!$str) {
Expand Down
5 changes: 0 additions & 5 deletions src/handlers/TemplateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ public function prepareData($data)
], parent::prepareData($data));
}

public function parse($json)
{
return [];
}

public function existsTemplate()
{
return $this->template && $this->view->existsTemplate($this->template);
Expand Down

0 comments on commit e8776fd

Please sign in to comment.