Skip to content

Commit

Permalink
chore: Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
nikcio committed Apr 6, 2024
1 parent 9503de8 commit bf19154
Show file tree
Hide file tree
Showing 22 changed files with 40 additions and 54 deletions.
2 changes: 0 additions & 2 deletions src/Examples/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using HotChocolate.Execution.Configuration;
using Microsoft.AspNetCore.Builder;
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.DependencyInjection;
using Nikcio.UHeadless.Content.Basics.Queries;
using Nikcio.UHeadless.Content.Extensions;
Expand All @@ -9,7 +8,6 @@
using Nikcio.UHeadless.Media.Extensions;
using Nikcio.UHeadless.Members.Basics.Queries;
using Nikcio.UHeadless.Members.Extensions;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Extensions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public BasicContentPicker(CreatePropertyValue createPropertyValue, IDependencyRe
if (objectValue is IPublishedContent content)
{
AddContentPickerItem(dependencyReflectorFactory, content, variationContextAccessor, createPropertyValue.Culture);
} else if (objectValue is IEnumerable<IPublishedContent> contentItems)
}
else if (objectValue is IEnumerable<IPublishedContent> contentItems)
{
foreach (IPublishedContent contentItem in contentItems)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public BasicDateTimePicker(CreatePropertyValue createPropertyValue) : base(creat
if (value == default(DateTime))
{
Value = null;
} else
}
else
{
Value = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ public BasicLabel(CreatePropertyValue createPropertyValue) : base(createProperty
if (dateTimeValue == default)
{
Value = null;
} else
}
else
{
Value = dateTimeValue;
}
} else
}
else
{
Value = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public BasicMediaPicker(CreatePropertyValue createPropertyValue, IDependencyRefl
if (value is IPublishedContent mediaItem)
{
AddMediaPickerItem(dependencyReflectorFactory, mediaItem, createPropertyValue.Culture);
} else if (value is IEnumerable<IPublishedContent> mediaItems && mediaItems.Any())
}
else if (value is IEnumerable<IPublishedContent> mediaItems && mediaItems.Any())
{
foreach (IPublishedContent media in mediaItems)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public BasicMemberPicker(CreatePropertyValue createPropertyValue, IDependencyRef
if (objectValue is IPublishedContent memberItem)
{
AddMemberPickerItem(dependencyReflectorFactory, createPropertyValue, memberItem);
} else if (objectValue is IEnumerable<IPublishedContent> members)
}
else if (objectValue is IEnumerable<IPublishedContent> members)
{
foreach (IPublishedContent member in members)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public BasicMultiUrlPicker(CreatePropertyValue createPropertyValue, IDependencyR
{
AddLinkPickerItem(dependencyReflectorFactory, link);
}
} else if (value is Link link)
}
else if (value is Link link)
{
AddLinkPickerItem(dependencyReflectorFactory, link);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ internal IEnumerable<Type> SortComposers(Dictionary<Type, List<Type>?> requireme
try
{
sortedComposerTypes = graph.GetSortedItems().Select(x => x.Key).Where(x => !x.IsInterface).ToList();
} catch (Exception e)
}
catch (Exception e)
{
// in case of an error, force-dump everything to log
_logger.LogInformation("Composer Report:\r\n{ComposerReport}", GetComposersReport(requirements));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Nikcio.UHeadless.Base.Properties.Commands;
using Nikcio.UHeadless.Base.Properties.Maps;
using Nikcio.UHeadless.Base.Properties.Models;
using Nikcio.UHeadless.Core.Constants;
using Nikcio.UHeadless.Core.Reflection.Factories;

namespace Nikcio.UHeadless.Base.Properties.Factories;
Expand Down
10 changes: 6 additions & 4 deletions src/Nikcio.UHeadless.Base/Base/Properties/Maps/PropertyMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class PropertyMap : DictionaryMap, IPropertyMap
/// <inheritdoc/>
public virtual void AddEditorMapping<TType>(string editorName) where TType : PropertyValue
{
if(AddMapping<TType>(GetEditorMappingKey(editorName), editorPropertyMap))
if (AddMapping<TType>(GetEditorMappingKey(editorName), editorPropertyMap))
{
AddUsedType<TType>();
}
Expand All @@ -34,7 +34,7 @@ public virtual void AddEditorMapping<TType>(string editorName) where TType : Pro
/// <inheritdoc/>
public virtual void AddAliasMapping<TType>(string contentTypeAlias, string propertyTypeAlias) where TType : PropertyValue
{
if(AddMapping<TType>(GetAliasMappingKey(contentTypeAlias, propertyTypeAlias), aliasPropertyMap))
if (AddMapping<TType>(GetAliasMappingKey(contentTypeAlias, propertyTypeAlias), aliasPropertyMap))
{
AddUsedType<TType>();
}
Expand Down Expand Up @@ -94,10 +94,12 @@ public virtual string GetPropertyTypeName(string contentTypeAlias, string proper
if (ContainsAlias(contentTypeAlias, propertyTypeAlias))
{
propertyTypeName = GetAliasValue(contentTypeAlias, propertyTypeAlias);
} else if (ContainsEditor(editorAlias))
}
else if (ContainsEditor(editorAlias))
{
propertyTypeName = GetEditorValue(editorAlias);
} else
}
else
{
propertyTypeName = GetEditorValue(PropertyConstants.DefaultKey);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using HotChocolate.Execution.Configuration;
using HotChocolate.Types;
using HotChocolate.Types.Descriptors;
using HotChocolate.Types.Descriptors.Definitions;
using Nikcio.UHeadless.Base.Basics.Models;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public DependencyReflectorFactory(IServiceProvider serviceProvider, ILogger<Depe
.Select(parameter => _serviceProvider.GetService(parameter.ParameterType))
.OfType<object>()
.ToArray();
} else
}
else
{
injectedParamerters = constructorRequiredParamerters
.Take(parameters.Length)
Expand Down
4 changes: 2 additions & 2 deletions src/Nikcio.UHeadless.Content/Models/Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public abstract class Content<TProperty> : Element<TProperty>, IContent
where TProperty : IProperty
{
/// <inheritdoc/>
protected Content(CreateContent createContent, IPropertyFactory<TProperty> propertyFactory) :
protected Content(CreateContent createContent, IPropertyFactory<TProperty> propertyFactory) :
base(
createContent?.CreateElement ?? throw new ArgumentNullException(nameof(createContent)),
createContent?.CreateElement ?? throw new ArgumentNullException(nameof(createContent)),
propertyFactory
)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Nikcio.UHeadless.Content/Router/ContentRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public ContentRouter(IContentRedirectRepository<TContentRedirect> contentRedirec
if (emptyContent == null)
{
return default;
} else
}
else
{
System.Reflection.PropertyInfo? redirectProperty = emptyContent.GetType().GetProperty(nameof(IContent.Redirect), typeof(TContentRedirect));
if (redirectProperty == null)
Expand Down
12 changes: 1 addition & 11 deletions src/Nikcio.UHeadless.Content/TypeModules/ContentTypeModule.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
using HotChocolate.Execution.Configuration;
using HotChocolate.Types;
using HotChocolate.Types.Descriptors;
using HotChocolate.Types.Descriptors.Definitions;
using Nikcio.UHeadless.Base.Basics.Models;
using Nikcio.UHeadless.Base.Elements.Models;
using Nikcio.UHeadless.Base.Properties.Commands;
using Nikcio.UHeadless.Base.Properties.Factories;
using Nikcio.UHeadless.Base.Properties.Maps;
using Nikcio.UHeadless.Base.Properties.Maps;
using Nikcio.UHeadless.Base.Properties.Models;
using Nikcio.UHeadless.Base.TypeModules;
using Nikcio.UHeadless.Core.Extensions;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Services;

namespace Nikcio.UHeadless.Content.TypeModules;
Expand Down
2 changes: 0 additions & 2 deletions src/Nikcio.UHeadless.IntegrationTests.TestProject/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using HotChocolate.Execution.Configuration;
using Microsoft.Data.Sqlite;
using Nikcio.UHeadless.Content.Basics.Queries;
using Nikcio.UHeadless.Content.Extensions;
using Nikcio.UHeadless.Extensions;
Expand All @@ -8,7 +7,6 @@
using Nikcio.UHeadless.Media.Extensions;
using Nikcio.UHeadless.Members.Basics.Queries;
using Nikcio.UHeadless.Members.Extensions;
using Umbraco.Cms.Core;

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class ApiTests
[InlineData(1146, 10, "en-us")]
[InlineData(1146, 5, "da")]
public async Task ContentDescendantsById_Can_Get_FirstNodes_Async(int id, int firstCount, string? culture)
{
{
var snapshotProvider = new SnapshotProvider($"{_contentAllSnapshotPath}/FirstNodes");
HttpClient client = _factory.CreateClient();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.Configuration;

namespace Nikcio.UHeadless.IntegrationTests.Sqlite;
Expand Down
8 changes: 1 addition & 7 deletions src/Nikcio.UHeadless.IntegrationTests/Sqlite/Fragments.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nikcio.UHeadless.IntegrationTests.Sqlite;
namespace Nikcio.UHeadless.IntegrationTests.Sqlite;

public static class Fragments
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ private async Task<string> GetSnapshotAsync(string snapshotName, string content)
if (File.Exists(snapshotPath))
{
return await File.ReadAllTextAsync(snapshotPath).ConfigureAwait(true);
} else
}
else
{
if (!Directory.Exists(_snapshotFolder))
{
Expand All @@ -59,8 +60,9 @@ private async Task<string> GetContentAsJsonAsync(string content)
await JsonSerializer.SerializeAsync(jsonStream, jsonObject, _options).ConfigureAwait(true);
return FormatDateTimesAsUTCInJson(Encoding.UTF8.GetString(jsonStream.ToArray()));
}

} else

}
else
{
// Anything that is not JSON, we just write as is - This could be an error message or something else
return content;
Expand Down
11 changes: 4 additions & 7 deletions src/Nikcio.UHeadless/Extensions/UHeadlessExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
using Nikcio.UHeadless.Base.Composers;
using Nikcio.UHeadless.Base.Properties.Extensions;
using Nikcio.UHeadless.Content.Basics.Queries;
using Nikcio.UHeadless.Content.Composers;
using Nikcio.UHeadless.Content.Extensions;
using Nikcio.UHeadless.Content.NotificationHandlers;
using Nikcio.UHeadless.Content.TypeModules;
using Nikcio.UHeadless.ContentTypes.Extensions;
using Nikcio.UHeadless.Core.Reflection.Extensions;
using Nikcio.UHeadless.Extensions.Options;
using Nikcio.UHeadless.Media.Extensions;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Notifications;

namespace Nikcio.UHeadless.Extensions;

Expand Down Expand Up @@ -103,7 +98,8 @@ public static IApplicationBuilder UseUHeadlessGraphQLEndpoint(this IApplicationB
if (uHeadlessEndpointOptions.CorsPolicy != null)
{
applicationBuilder.UseCors(uHeadlessEndpointOptions.CorsPolicy);
} else
}
else
{
applicationBuilder.UseCors();
}
Expand Down Expand Up @@ -137,7 +133,8 @@ public static WebApplication MapUHeadlessGraphQLEndpoint(this WebApplication app
if (uHeadlessEndpointOptions.CorsPolicy != null)
{
app.UseCors(uHeadlessEndpointOptions.CorsPolicy);
} else
}
else
{
app.UseCors();
}
Expand Down
2 changes: 0 additions & 2 deletions src/Nikcio.UHeadless/Extensions/UHeadlessGraphQLExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using HotChocolate.Execution.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Nikcio.UHeadless.Base.Properties.Models;
using Nikcio.UHeadless.Content.TypeModules;
using Nikcio.UHeadless.Core.GraphQL.Queries;
using Nikcio.UHeadless.Extensions.Options;
using Nikcio.UHeadless.Media.TypeModules;

namespace Nikcio.UHeadless.Extensions;

Expand Down

0 comments on commit bf19154

Please sign in to comment.