Added an PHP CS fixer config file and applied it to files.

We now use the same the same style as the symfony project, and it allows us to simply fix the style by executing php_cs_fixer fix in the project root.
This commit is contained in:
Jan Böhmer 2019-11-09 00:47:20 +01:00
parent 89258bc102
commit e557bdedd5
210 changed files with 2099 additions and 2742 deletions

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Services;
use Symfony\Component\HttpKernel\KernelInterface;
class GitVersionInfo
@ -35,33 +33,41 @@ class GitVersionInfo
}
/**
* Get the Git branch name of the installed system
* @return string|null The current git branch name. Null, if this is no Git installation
* Get the Git branch name of the installed system.
*
* @return string|null The current git branch name. Null, if this is no Git installation
*/
public function getGitBranchName()
{
if (file_exists($this->project_dir . '/.git/HEAD')) {
$git = file($this->project_dir . '/.git/HEAD');
if (file_exists($this->project_dir.'/.git/HEAD')) {
$git = file($this->project_dir.'/.git/HEAD');
$head = explode('/', $git[0], 3);
return trim($head[2]);
}
return null; // this is not a Git installation
}
/**
* Get hash of the last git commit (on remote "origin"!)
* Get hash of the last git commit (on remote "origin"!).
*
* @note If this method does not work, try to make a "git pull" first!
* @param integer $length if this is smaller than 40, only the first $length characters will be returned
* @return string|null The hash of the last commit, null If this is no Git installation
*
* @param int $length if this is smaller than 40, only the first $length characters will be returned
*
* @return string|null The hash of the last commit, null If this is no Git installation
*/
public function getGitCommitHash(int $length = 7)
{
$filename = $this->project_dir . '/.git/refs/remotes/origin/' . $this->getGitBranchName();
$filename = $this->project_dir.'/.git/refs/remotes/origin/'.$this->getGitBranchName();
if (file_exists($filename)) {
$head = file($filename);
$hash = $head[0];
return substr($hash, 0, $length);
}
return null; // this is not a Git installation
}
}
}