Skip to content

Commit

Permalink
chore: Code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
nikcio committed Jun 10, 2022
1 parent 692d7bc commit 3058244
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 26 deletions.
5 changes: 1 addition & 4 deletions src/Nikcio.UHeadless.Content/Factories/ContentFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ public ContentFactory(IDependencyReflectorFactory dependencyReflectorFactory) {
var createContentCommand = new CreateContent(content, culture, createElementCommand);

var createdContent = dependencyReflectorFactory.GetReflectedType<IContent<TProperty>>(typeof(TContent), new object[] { createContentCommand });
if (createdContent == null) {
return default;
}
return (TContent) createdContent;
return createdContent == null ? default : (TContent) createdContent;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ public ContentRedirectFactory(IDependencyReflectorFactory dependencyReflectorFac
public virtual TContentRedirect? CreateContentRedirect(CreateContentRedirect createContentRedirect) {

var createdContent = dependencyReflectorFactory.GetReflectedType<IContentRedirect>(typeof(TContentRedirect), new object[] { createContentRedirect });
if (createdContent == null) {
return default;
}
return (TContentRedirect) createdContent;
return createdContent == null ? default : (TContentRedirect) createdContent;
}
}
}
2 changes: 1 addition & 1 deletion src/Nikcio.UHeadless.Content/Queries/ContentQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public class ContentQuery<TContent, TProperty, TContentRedirect>
if (string.IsNullOrWhiteSpace(baseUrl)) {
baseUrl = $"{httpContextAccessor.HttpContext.Request.Scheme}://{httpContextAccessor.HttpContext.Request.Host.Host}";

if (httpContextAccessor.HttpContext.Request.Host.Port != 80 && httpContextAccessor.HttpContext.Request.Host.Port != 443) {
if (httpContextAccessor.HttpContext.Request.Host.Port is not 80 and not 443) {
baseUrl += $":{httpContextAccessor.HttpContext.Request.Host.Port}";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ContentRepository(IPublishedSnapshotAccessor publishedSnapshotAccessor, I
public virtual TContent? GetContent(Func<IPublishedContentCache?, IPublishedContent?> fetch, string? culture) {
if (publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot)) {
var content = fetch(publishedSnapshot?.Content);
if (content != null && culture == null || content != null) {
if ((content != null && culture == null) || content != null) {
return GetConvertedContent(content, culture);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ public ContentTypeFactory(IDependencyReflectorFactory dependencyReflectorFactory

var createdContentType = dependencyReflectorFactory.GetReflectedType<IContentType>(typeof(TContentType), new object[] { createContentTypeCommand });

if (createdContentType == null) {
return default;
}

return (TContentType) createdContentType;
return createdContentType == null ? default : (TContentType) createdContentType;
}
}
}
5 changes: 1 addition & 4 deletions src/Nikcio.UHeadless.Media/Factories/MediaFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ public MediaFactory(IDependencyReflectorFactory dependencyReflectorFactory) {
var createMediaCommand = new CreateMedia(media, culture, createElementCommand);

var createdContent = dependencyReflectorFactory.GetReflectedType<IMedia<TProperty>>(typeof(TMedia), new object[] { createMediaCommand });
if (createdContent == null) {
return default;
}
return (TMedia) createdContent;
return createdContent == null ? default : (TMedia) createdContent;
}
}
}
2 changes: 1 addition & 1 deletion src/Nikcio.UHeadless.Media/Repositories/MediaRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public MediaRepository(IPublishedSnapshotAccessor publishedSnapshotAccessor, IUm
public virtual TMedia? GetMedia(Func<IPublishedMediaCache?, IPublishedContent?> fetch, string? culture) {
if (_publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot)) {
var media = fetch(publishedSnapshot?.Media);
if (media != null && culture == null || media != null) {
if ((media != null && culture == null) || media != null) {
return GetConvertedMedia(media, culture);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Nikcio.UHeadless.Properties.Extensions.Options;
using Nikcio.UHeadless.Properties.Maps;

namespace Nikcio.UHeadless.Properties.Extensions {
/// <summary>
Expand Down
5 changes: 1 addition & 4 deletions src/Nikcio.UHeadless.Properties/Factories/PropertyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ public PropertyFactory(IDependencyReflectorFactory dependencyReflectorFactory) {
var createPropertyCommand = new CreateProperty(property, culture, publishedContent);

var createdProperty = dependencyReflectorFactory.GetReflectedType<IProperty>(typeof(TProperty), new object[] { createPropertyCommand });
if (createdProperty == null) {
return default;
}
return (TProperty) createdProperty;
return createdProperty == null ? default : (TProperty) createdProperty;
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public PropertyRespository(IPropertyFactory<TProperty> propertyFactory, IPublish
public virtual IEnumerable<TProperty?>? GetProperties(Func<IPublishedContentCache?, IPublishedContent?> fetch, string? culture) {
if (publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot)) {
var content = fetch(publishedSnapshot?.Content);
if (content != null && culture == null || content != null) {
if ((content != null && culture == null) || content != null) {
return GetProperties(content, culture);
}
}
Expand Down

0 comments on commit 3058244

Please sign in to comment.