- Corrected code-smell and code style issues in \ncc\Classes > NccExtension > ConstantCompiler

This commit is contained in:
Netkas 2023-08-17 16:09:42 -04:00
parent 309d37fe7d
commit 3afcb731fe
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
2 changed files with 147 additions and 54 deletions

View file

@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Corrected code-smell and code style issues in `\ncc\Classes > ComposerExtension > ComposerSourceBuiltin` - Corrected code-smell and code style issues in `\ncc\Classes > ComposerExtension > ComposerSourceBuiltin`
- Corrected code-smell and code style issues in `\ncc\Classes > GithubExtension > GithubService` - Corrected code-smell and code style issues in `\ncc\Classes > GithubExtension > GithubService`
- Corrected code-smell and code style issues in `\ncc\Classes > GitlabExtension > GitlabService` - Corrected code-smell and code style issues in `\ncc\Classes > GitlabExtension > GitlabService`
- Corrected code-smell and code style issues in `\ncc\Classes > NccExtension > ConstantCompiler`

View file

@ -38,31 +38,58 @@ namespace ncc\Classes\NccExtension;
* @param string|null $input * @param string|null $input
* @param Assembly $assembly * @param Assembly $assembly
* @return string|null * @return string|null
* @noinspection PhpUnnecessaryLocalVariableInspection
*/ */
public static function compileAssemblyConstants(?string $input, Assembly $assembly): ?string public static function compileAssemblyConstants(?string $input, Assembly $assembly): ?string
{ {
if($input == null) if($input === null)
{
return null; return null;
}
if($assembly->Name !== null) if($assembly->Name !== null)
{
$input = str_replace(AssemblyConstants::AssemblyName, $assembly->Name, $input); $input = str_replace(AssemblyConstants::AssemblyName, $assembly->Name, $input);
}
if($assembly->Package !== null) if($assembly->Package !== null)
{
$input = str_replace(AssemblyConstants::AssemblyPackage, $assembly->Package, $input); $input = str_replace(AssemblyConstants::AssemblyPackage, $assembly->Package, $input);
}
if($assembly->Description !== null) if($assembly->Description !== null)
{
$input = str_replace(AssemblyConstants::AssemblyDescription, $assembly->Description, $input); $input = str_replace(AssemblyConstants::AssemblyDescription, $assembly->Description, $input);
}
if($assembly->Company !== null) if($assembly->Company !== null)
{
$input = str_replace(AssemblyConstants::AssemblyCompany, $assembly->Company, $input); $input = str_replace(AssemblyConstants::AssemblyCompany, $assembly->Company, $input);
}
if($assembly->Product !== null) if($assembly->Product !== null)
{
$input = str_replace(AssemblyConstants::AssemblyProduct, $assembly->Product, $input); $input = str_replace(AssemblyConstants::AssemblyProduct, $assembly->Product, $input);
}
if($assembly->Copyright !== null) if($assembly->Copyright !== null)
{
$input = str_replace(AssemblyConstants::AssemblyCopyright, $assembly->Copyright, $input); $input = str_replace(AssemblyConstants::AssemblyCopyright, $assembly->Copyright, $input);
}
if($assembly->Trademark !== null) if($assembly->Trademark !== null)
$input = str_replace(AssemblyConstants::AssemblyTrademark, $assembly->Trademark, $input); {
$input =str_replace(AssemblyConstants::AssemblyTrademark, $assembly->Trademark, $input);
}
if($assembly->Version !== null) if($assembly->Version !== null)
{
$input = str_replace(AssemblyConstants::AssemblyVersion, $assembly->Version, $input); $input = str_replace(AssemblyConstants::AssemblyVersion, $assembly->Version, $input);
}
if($assembly->UUID !== null) if($assembly->UUID !== null)
{
$input = str_replace(AssemblyConstants::AssemblyUid, $assembly->UUID, $input); $input = str_replace(AssemblyConstants::AssemblyUid, $assembly->UUID, $input);
}
return $input; return $input;
} }
@ -72,19 +99,27 @@ namespace ncc\Classes\NccExtension;
* *
* @param string|null $input * @param string|null $input
* @return string|null * @return string|null
* @noinspection PhpUnnecessaryLocalVariableInspection
*/ */
public static function compileBuildConstants(?string $input): ?string public static function compileBuildConstants(?string $input): ?string
{ {
if($input == null) if($input === null)
{
return null; return null;
}
$input = str_replace(BuildConstants::CompileTimestamp, time(), $input); return str_replace(
$input = str_replace(BuildConstants::NccBuildVersion, NCC_VERSION_NUMBER, $input); [
$input = str_replace(BuildConstants::NccBuildFlags, implode(' ', NCC_VERSION_FLAGS), $input); BuildConstants::CompileTimestamp,
$input = str_replace(BuildConstants::NccBuildBranch, NCC_VERSION_BRANCH, $input); BuildConstants::NccBuildVersion,
BuildConstants::NccBuildFlags,
return $input; BuildConstants::NccBuildBranch
],
[
time(),
NCC_VERSION_NUMBER,
implode(' ', NCC_VERSION_FLAGS), NCC_VERSION_BRANCH
], $input
);
} }
/** /**
@ -93,19 +128,27 @@ namespace ncc\Classes\NccExtension;
* @param string|null $input * @param string|null $input
* @param InstallationPaths $installationPaths * @param InstallationPaths $installationPaths
* @return string|null * @return string|null
* @noinspection PhpUnnecessaryLocalVariableInspection
*/ */
public static function compileInstallConstants(?string $input, InstallationPaths $installationPaths): ?string public static function compileInstallConstants(?string $input, InstallationPaths $installationPaths): ?string
{ {
if($input == null) if($input === null)
{
return null; return null;
}
$input = str_replace(InstallConstants::InstallationPath, $installationPaths->getInstallationPath(), $input); return str_replace(
$input = str_replace(InstallConstants::BinPath, $installationPaths->getBinPath(), $input); [
$input = str_replace(InstallConstants::SourcePath, $installationPaths->getSourcePath(), $input); InstallConstants::InstallationPath,
$input = str_replace(InstallConstants::DataPath, $installationPaths->getDataPath(), $input); InstallConstants::BinPath,
InstallConstants::SourcePath,
return $input; InstallConstants::DataPath
],
[
$installationPaths->getInstallationPath(),
$installationPaths->getBinPath(),
$installationPaths->getSourcePath(),
$installationPaths->getDataPath()
], $input);
} }
/** /**
@ -114,67 +157,116 @@ namespace ncc\Classes\NccExtension;
* @param string|null $input * @param string|null $input
* @param int $timestamp * @param int $timestamp
* @return string|null * @return string|null
* @noinspection PhpUnnecessaryLocalVariableInspection
*/ */
public static function compileDateTimeConstants(?string $input, int $timestamp): ?string public static function compileDateTimeConstants(?string $input, int $timestamp): ?string
{ {
if($input == null) if($input === null)
{
return null; return null;
}
$input = str_replace(DateTimeConstants::d, date('d', $timestamp), $input); return str_replace([
$input = str_replace(DateTimeConstants::D, date('D', $timestamp), $input); DateTimeConstants::d,
$input = str_replace(DateTimeConstants::j, date('j', $timestamp), $input); DateTimeConstants::D,
$input = str_replace(DateTimeConstants::l, date('l', $timestamp), $input); DateTimeConstants::j,
$input = str_replace(DateTimeConstants::N, date('N', $timestamp), $input); DateTimeConstants::l,
$input = str_replace(DateTimeConstants::S, date('S', $timestamp), $input); DateTimeConstants::N,
$input = str_replace(DateTimeConstants::w, date('w', $timestamp), $input); DateTimeConstants::S,
$input = str_replace(DateTimeConstants::z, date('z', $timestamp), $input); DateTimeConstants::w,
$input = str_replace(DateTimeConstants::W, date('W', $timestamp), $input); DateTimeConstants::z,
$input = str_replace(DateTimeConstants::F, date('F', $timestamp), $input); DateTimeConstants::W,
$input = str_replace(DateTimeConstants::m, date('m', $timestamp), $input); DateTimeConstants::F,
$input = str_replace(DateTimeConstants::M, date('M', $timestamp), $input); DateTimeConstants::m,
$input = str_replace(DateTimeConstants::n, date('n', $timestamp), $input); DateTimeConstants::M,
$input = str_replace(DateTimeConstants::t, date('t', $timestamp), $input); DateTimeConstants::n,
$input = str_replace(DateTimeConstants::L, date('L', $timestamp), $input); DateTimeConstants::t,
$input = str_replace(DateTimeConstants::o, date('o', $timestamp), $input); DateTimeConstants::L,
$input = str_replace(DateTimeConstants::Y, date('Y', $timestamp), $input); DateTimeConstants::o,
$input = str_replace(DateTimeConstants::y, date('y', $timestamp), $input); DateTimeConstants::Y,
$input = str_replace(DateTimeConstants::a, date('a', $timestamp), $input); DateTimeConstants::y,
$input = str_replace(DateTimeConstants::A, date('A', $timestamp), $input); DateTimeConstants::a,
$input = str_replace(DateTimeConstants::B, date('B', $timestamp), $input); DateTimeConstants::A,
$input = str_replace(DateTimeConstants::g, date('g', $timestamp), $input); DateTimeConstants::B,
$input = str_replace(DateTimeConstants::G, date('G', $timestamp), $input); DateTimeConstants::g,
$input = str_replace(DateTimeConstants::h, date('h', $timestamp), $input); DateTimeConstants::G,
$input = str_replace(DateTimeConstants::H, date('H', $timestamp), $input); DateTimeConstants::h,
$input = str_replace(DateTimeConstants::i, date('i', $timestamp), $input); DateTimeConstants::H,
$input = str_replace(DateTimeConstants::s, date('s', $timestamp), $input); DateTimeConstants::i,
$input = str_replace(DateTimeConstants::c, date('c', $timestamp), $input); DateTimeConstants::s,
$input = str_replace(DateTimeConstants::r, date('r', $timestamp), $input); DateTimeConstants::c,
$input = str_replace(DateTimeConstants::u, date('u', $timestamp), $input); DateTimeConstants::r,
DateTimeConstants::u
],
[
date('d', $timestamp),
date('D', $timestamp),
date('j', $timestamp),
date('l', $timestamp),
date('N', $timestamp),
date('S', $timestamp),
date('w', $timestamp),
date('z', $timestamp),
date('W', $timestamp),
date('F', $timestamp),
date('m', $timestamp),
date('M', $timestamp),
date('n', $timestamp),
date('t', $timestamp),
date('L', $timestamp),
date('o', $timestamp),
date('Y', $timestamp),
date('y', $timestamp),
date('a', $timestamp),
date('A', $timestamp),
date('B', $timestamp),
date('g', $timestamp),
date('G', $timestamp),
date('h', $timestamp),
date('H', $timestamp),
date('i', $timestamp),
date('s', $timestamp),
date('c', $timestamp),
date('r', $timestamp),
date('u', $timestamp)
], $input);
return $input;
} }
/** /**
* @param string|null $input * @param string|null $input
* @return string|null * @return string|null
* @noinspection PhpUnnecessaryLocalVariableInspection
*/ */
public static function compileRuntimeConstants(?string $input): ?string public static function compileRuntimeConstants(?string $input): ?string
{ {
if ($input == null) if ($input === null)
{
return null; return null;
}
if(function_exists('getcwd')) if(function_exists('getcwd'))
{
$input = str_replace(RuntimeConstants::CWD, getcwd(), $input); $input = str_replace(RuntimeConstants::CWD, getcwd(), $input);
}
if(function_exists('getmypid')) if(function_exists('getmypid'))
{
$input = str_replace(RuntimeConstants::PID, getmypid(), $input); $input = str_replace(RuntimeConstants::PID, getmypid(), $input);
}
if(function_exists('getmyuid')) if(function_exists('getmyuid'))
{
$input = str_replace(RuntimeConstants::UID, getmyuid(), $input); $input = str_replace(RuntimeConstants::UID, getmyuid(), $input);
}
if(function_exists('getmygid')) if(function_exists('getmygid'))
{
$input = str_replace(RuntimeConstants::GID, getmygid(), $input); $input = str_replace(RuntimeConstants::GID, getmygid(), $input);
}
if(function_exists('get_current_user')) if(function_exists('get_current_user'))
{
$input = str_replace(RuntimeConstants::User, get_current_user(), $input); $input = str_replace(RuntimeConstants::User, get_current_user(), $input);
}
return $input; return $input;
} }