Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
ci:
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Coding Style

on:
push:
branches: [ "master" ]
pull_request: ~

jobs:
ci:
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v3
- name: Set up PHP Version
uses: shivammathur/setup-php@v2
with:
php-version: 7.2
tools: composer:v1
- name: Validate composer.json
run: composer validate --strict
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: .Build/vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-php-latest
- name: Install dependencies
run: composer install
- name: ECS
run: .Build/bin/ecs
23 changes: 9 additions & 14 deletions Classes/Configuration/ExtensionConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;

/**
* Class ExtensionConfiguration
*/
final class ExtensionConfiguration implements SingletonInterface
{
private const DEFAULT_VERSION_FILE = 'VERSION';
Expand Down Expand Up @@ -60,10 +57,17 @@ final class ExtensionConfiguration implements SingletonInterface
*/
private $staticVersion;

public function __construct()
{
$this->configuration = $this->getExtensionConfigurationFromGlobals();
$this->versionFilePath = $this->resolveVersionFilePath();
$this->mode = $this->configuration['mode'] ?? ProjectVersionModeEnumeration::FILE;
$this->gitFormat = $this->configuration['gitFormat'] ?? '';
$this->staticVersion = $this->configuration['staticVersion'] ?? '';
}

/**
* Fetch absolute version filename.
*
* @return string
*/
public function getAbsVersionFilePath(): string
{
Expand All @@ -90,15 +94,6 @@ public function getStaticVersion(): string
return $this->staticVersion;
}

public function __construct()
{
$this->configuration = $this->getExtensionConfigurationFromGlobals();
$this->versionFilePath = $this->resolveVersionFilePath();
$this->mode = $this->configuration['mode'] ?? ProjectVersionModeEnumeration::FILE;
$this->gitFormat = $this->configuration['gitFormat'] ?? '';
$this->staticVersion = $this->configuration['staticVersion'] ?? '';
}

private function getExtensionConfigurationFromGlobals(): array
{
return $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['project_version'] ?? [];
Expand Down
9 changes: 6 additions & 3 deletions Classes/Enumeration/GitCommandEnumeration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@

namespace KamiYang\ProjectVersion\Enumeration;

/**
* Class GitCommandEnumeration
*/
final class GitCommandEnumeration
{
public const CMD_BRANCH = 'git rev-parse --abbrev-ref HEAD';

public const CMD_REVISION = 'git rev-parse --short HEAD';

public const CMD_TAG = 'git describe --tags';

public const FORMAT_REVISION = '0';

public const FORMAT_REVISION_BRANCH = '1';

public const FORMAT_REVISION_TAG = '2';

public const FORMAT_BRANCH = '3';

public const FORMAT_TAG = '4';
}
6 changes: 3 additions & 3 deletions Classes/Enumeration/ProjectVersionModeEnumeration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

namespace KamiYang\ProjectVersion\Enumeration;

/**
* Class ProjectVersionModeEnumeration
*/
final class ProjectVersionModeEnumeration
{
public const FILE = '0';

public const GIT = '1';

public const GIT_FILE_FALLBACK = '2';

public const STATIC_VERSION = '3';
}
3 changes: 0 additions & 3 deletions Classes/Facade/CommandUtilityFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

use TYPO3\CMS\Core\Utility\CommandUtility;

/**
* Class CommandUtilityFacade
*/
class CommandUtilityFacade
{
/**
Expand Down
26 changes: 3 additions & 23 deletions Classes/Service/ProjectVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,19 @@

use function trim;

/**
* Class ProjectVersion
*/
class ProjectVersion implements SingletonInterface
{
public const UNKNOWN_VERSION = self::LLL . ':toolbarItems.sysinfo.project-version.unknown';

private const LLL = 'LLL:EXT:project_version/Resources/Private/Language/Backend.xlf';

/**
* @var string $title
* @var string
*/
protected $title = self::LLL . ':toolbarItems.sysinfo.project-version';

/**
* @var string $version
* @var string
*/
protected $version = self::UNKNOWN_VERSION;

Expand All @@ -43,49 +41,31 @@ class ProjectVersion implements SingletonInterface
*/
protected $iconIdentifier = 'information-project-version';

/**
* @return string
*/
public function getTitle(): string
{
return $this->title;
}

/**
* @param string $title
*/
public function setTitle(string $title): void
{
$this->title = $title;
}

/**
* @return string
*/
public function getVersion(): string
{
return $this->version;
}

/**
* @param string $version
*/
public function setVersion(string $version): void
{
$this->version = trim($version);
}

/**
* @return string
*/
public function getIconIdentifier(): string
{
return $this->iconIdentifier;
}

/**
* @param string $iconIdentifier
*/
public function setIconIdentifier(string $iconIdentifier): void
{
$this->iconIdentifier = $iconIdentifier;
Expand Down
11 changes: 4 additions & 7 deletions Classes/Service/ProjectVersionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@
use function sprintf;
use function trim;

/**
* Class ProjectVersionService
*/
class ProjectVersionService implements SingletonInterface
{
/**
* @var CommandUtilityFacade
*/
protected $commandUtilityFacade;

/**
* @var ExtensionConfiguration
*/
Expand Down Expand Up @@ -80,7 +78,6 @@ public function getProjectVersion(): ProjectVersion

/**
* @internal protected so we can mock it in unit tests.
* @return bool
*/
protected function isGitAvailable(): bool
{
Expand Down Expand Up @@ -129,12 +126,12 @@ private function setVersionFromFile(ProjectVersion $projectVersion): void

private function setVersionFromGit(ProjectVersion $projectVersion): void
{
if (!$this->isGitAvailable()) {
if (! $this->isGitAvailable()) {
return;
}

$version = $this->getVersionByFormat();
if (!empty($version)) {
if (! empty($version)) {
$gitIconIdentifier = 'information-git';

$projectVersion->setVersion($version);
Expand All @@ -158,6 +155,6 @@ private function getVersionByFormat(): string

private function isExecEnabled(): bool
{
return !in_array('exec', GeneralUtility::trimExplode(',', ini_get('disable_functions')), true);
return ! in_array('exec', GeneralUtility::trimExplode(',', ini_get('disable_functions')), true);
}
}
13 changes: 2 additions & 11 deletions Tests/Unit/EventListener/ProjectVersionEventListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Class ProjectVersionSlotTest
*/
class ProjectVersionEventListenerTest extends UnitTestCase
{
/**
Expand All @@ -47,10 +44,7 @@ protected function tearDown(): void
parent::tearDown();
}

/**
* @test
*/
public function getProjectVersionShouldAddProjectVersionAsSystemInformation(): void
public function testGetProjectVersionShouldAddProjectVersionAsSystemInformation(): void
{
$version = '9000-rc.69';
$title = 'Project Version';
Expand All @@ -69,10 +63,7 @@ public function getProjectVersionShouldAddProjectVersionAsSystemInformation(): v
->shouldHaveBeenCalledTimes(1);
}

/**
* @test
*/
public function getProjectVersionShouldResolveCurrentVersionAndLocalizeItIfNecessary(): void
public function testGetProjectVersionShouldResolveCurrentVersionAndLocalizeItIfNecessary(): void
{
$initialVersionValue = 'LLL:EXT:project_version/Resources/Private/Language/Backend.xlf:toolbarItems.sysinfo.project-version.unknown';
$projectVersion = new ProjectVersion();
Expand Down
Loading