Skip to content

Commit

Permalink
fix code analysis suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
kentico-ericd committed Nov 15, 2023
1 parent 9a4824c commit 1689beb
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 30 deletions.
4 changes: 2 additions & 2 deletions KenticoInspector.Core/AbstractModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ModuleMetadata<T> Metadata
{
get
{
return metadata ?? (metadata = moduleMetadataService.GetModuleMetadata<T>(Codename));
return metadata ??= moduleMetadataService.GetModuleMetadata<T>(Codename);
}
}

Expand All @@ -44,7 +44,7 @@ private static string GetDirectParentNamespace(Type reportType)
var fullNameSpace = reportType.Namespace;
var indexAfterLastPeriod = fullNameSpace.LastIndexOf('.') + 1;

return fullNameSpace.Substring(indexAfterLastPeriod, fullNameSpace.Length - indexAfterLastPeriod);
return fullNameSpace[indexAfterLastPeriod..];
}
}
}
2 changes: 1 addition & 1 deletion KenticoInspector.Core/Constants/ActionTags.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace KenticoInspector.Core.Constants
{
public class ActionTags
public static class ActionTags
{
public const string Reset = "Reset";
public const string User = "User";
Expand Down
8 changes: 2 additions & 6 deletions KenticoInspector.Core/Helpers/DirectoryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ namespace KenticoInspector.Core.Helpers
{
public static class DirectoryHelper
{
private const string filePrefix = "file:\\";

/// <summary>
/// Gets the executing directory of the application.
/// </summary>
/// <returns>A string that contains the path of the executing directory, and does not end with a backslash (\).</returns>
public static string GetExecutingDirectory()
{
var assemblyPath = Assembly.GetExecutingAssembly().CodeBase;
var assemblyDirectory = Path.GetDirectoryName(assemblyPath);

return assemblyDirectory.Substring(filePrefix.Length);
var assemblyPath = Assembly.GetExecutingAssembly().Location;
return Path.GetDirectoryName(assemblyPath);
}
}
}
6 changes: 4 additions & 2 deletions KenticoInspector.Core/Helpers/VersionHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KenticoInspector.Core.Helpers
{
Expand All @@ -22,12 +23,13 @@ public static Version GetVersionFromShortString(string version)

public static string ExpandVersionString(string version)
{
var sb = new StringBuilder(version);
for (int i = 0; i < 2; i++)
{
version += ".0";
sb.Append(".0");
}

return version;
return sb.ToString();
}
}
}
5 changes: 3 additions & 2 deletions KenticoInspector.Core/Services/Interfaces/IModuleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ public interface IModuleService : IService
{
IReport GetReport(string codename);

ReportResults GetReportResults(string reportCodename, Guid instanceGuid);
ReportResults GetReportResults(string codename, Guid instanceGuid);

IEnumerable<IReport> GetReports(Guid instanceGuid);

IEnumerable<IAction> GetActions(Guid instanceGuid);

IAction GetAction(string codename);
ActionResults ExecuteAction(string actionCodename, Guid instanceGuid, string optionsJson);

ActionResults ExecuteAction(string codename, Guid instanceGuid, string optionsJson);
}
}
7 changes: 6 additions & 1 deletion KenticoInspector.Infrastructure/Services/CmsFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ public class CmsFileService : ICmsFileService
{
public Dictionary<string, string> GetResourceStringsFromResx(string instanceRoot, string relativeResxFilePath = DefaultKenticoPaths.PrimaryResxFile)
{
var results = new Dictionary<string, string>();
var resourceXml = GetXmlDocument(instanceRoot, relativeResxFilePath);
var resourceStringNodes = resourceXml?.SelectNodes("/root/data");
var results = new Dictionary<string, string>();
if (resourceStringNodes is null)
{
return results;
}

foreach (XmlNode resourceStringNode in resourceStringNodes)
{
var key = resourceStringNode.Attributes["name"].InnerText.ToLowerInvariant();
Expand Down
4 changes: 2 additions & 2 deletions KenticoInspector.Infrastructure/Services/ModuleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public IEnumerable<IAction> GetActions(Guid instanceGuid)

public IReport GetReport(string codename) => reportRepository.GetReport(codename);

public ReportResults GetReportResults(string reportCodename, Guid instanceGuid)
public ReportResults GetReportResults(string codename, Guid instanceGuid)
{
var report = reportRepository.GetReport(reportCodename);
var report = reportRepository.GetReport(codename);
var instance = instanceService.SetCurrentInstance(instanceGuid);

databaseService.Configure(instance.DatabaseSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private List<CmsClassField> GetFieldsFromXml()
foreach (XmlNode field in fieldsXml)
{
var isIdColumnRaw = field.Attributes["isPK"]?.Value;
var isIdColumn = !string.IsNullOrWhiteSpace(isIdColumnRaw) ? bool.Parse(isIdColumnRaw) : false;
var isIdColumn = !string.IsNullOrWhiteSpace(isIdColumnRaw) && bool.Parse(isIdColumnRaw);

fields.Add(new CmsClassField
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Globalization;
using System.Text;

namespace KenticoInspector.Reports.ContentTreeConsistencyAnalysis.Models
{
Expand Down Expand Up @@ -74,13 +75,13 @@ private void ProcessDecimalValues(string versionHistoryXmlValue, object coupledD

var versionHistoryValue = decimal.Parse(versionHistoryXmlValue);

var formatting = "0.";
var formatting = new StringBuilder("0.");
for (int i = 0; i < precision; i++)
{
formatting += "0";
formatting.Append('0');
}

VersionHistoryValue = versionHistoryValue.ToString(formatting);
VersionHistoryValue = versionHistoryValue.ToString(formatting.ToString());
}

private void ProcessDateTimeValues(string versionHistoryXmlValue, object coupledDataColumnValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ public class CmsPageTypeField
public override bool Equals(object obj)
{
var comparingField = obj as CmsPageTypeField;
if (comparingField == null)
{
return base.Equals(obj);
}

var fieldsAreEqual = comparingField.FieldName == FieldName && comparingField.FieldDataType == FieldDataType;

return fieldsAreEqual;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ public Task<IEnumerable<IAction>> Get(Guid instanceGuid)
[HttpPost("{codename}/execute/{instanceGuid}")]
public async Task<ActionResults> Excecute(string codename, Guid instanceGuid)
{
using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
{
var optionsJson = await reader.ReadToEndAsync();
return moduleService.ExecuteAction(codename, instanceGuid, optionsJson);
}
using StreamReader reader = new(Request.Body, Encoding.UTF8);
var optionsJson = await reader.ReadToEndAsync();
return moduleService.ExecuteAction(codename, instanceGuid, optionsJson);
}
}
}

0 comments on commit 1689beb

Please sign in to comment.