Skip to content

Commit

Permalink
use static where possible (#1360)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Feb 16, 2024
1 parent 5ebb582 commit 65e261f
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/Humanizer/Localisation/Formatters/RussianFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protected override string GetResourceKey(string resourceKey, int number)
return resourceKey + suffix;
}

private string GetSuffix(RussianGrammaticalNumber grammaticalNumber)
private static string GetSuffix(RussianGrammaticalNumber grammaticalNumber)
{
if (grammaticalNumber == RussianGrammaticalNumber.Singular)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ protected override string GetResourceKey(string resourceKey, int number)
return resourceKey + suffix;
}

private string GetSuffix(RussianGrammaticalNumber grammaticalNumber)
private static string GetSuffix(RussianGrammaticalNumber grammaticalNumber)
{
if (grammaticalNumber == RussianGrammaticalNumber.Singular)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal class BulgarianNumberToWordsConverter : GenderedNumberToWordsConverter
public override string Convert(long input, GrammaticalGender gender, bool addAnd = true) =>
Convert(input, gender, false);

private string Convert(long input, GrammaticalGender gender, bool isOrdinal, bool addAnd = true)
private static string Convert(long input, GrammaticalGender gender, bool isOrdinal, bool addAnd = true)
{
if (input is > int.MaxValue or < int.MinValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public override string ConvertToOrdinal(int number)
return $"{word}{(IsVowel(word[word.Length - 1]) ? "یەم" : "ەم")}";
}

private bool IsVowel(char c) =>
private static bool IsVowel(char c) =>
c is 'ا' or 'ێ' or 'ۆ' or 'ە' or 'ی';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public override string Convert(long number) =>
public override string ConvertToOrdinal(int number) =>
Convert(number, true, IsSpecial(number));

private bool IsSpecial(long number) => number > 10 && number < 20;
private static bool IsSpecial(long number) => number > 10 && number < 20;

private string Convert(long number, bool isOrdinal, bool isSpecial)
private static string Convert(long number, bool isOrdinal, bool isSpecial)
{
if (number == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override string Convert(long number, GrammaticalGender gender, bool addAn
public override string ConvertToOrdinal(int number, GrammaticalGender gender) =>
number.ToString(_culture);

private string UnitByGender(long number, GrammaticalGender? gender)
private static string UnitByGender(long number, GrammaticalGender? gender)
{
if (number != 1 && number != 2)
{
Expand All @@ -62,7 +62,7 @@ private string UnitByGender(long number, GrammaticalGender? gender)
};
}

private void CollectLessThanThousand(List<string> parts, long number, GrammaticalGender? gender)
private static void CollectLessThanThousand(List<string> parts, long number, GrammaticalGender? gender)
{
if (number >= 100)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public override string Convert(long input)
return string.Join("", parts).Trim();
}

private string GetOrdinalUnit(int number, bool useExceptions)
private static string GetOrdinalUnit(int number, bool useExceptions)
{
if (useExceptions && OrdinalExceptions.ContainsKey(number))
{
Expand All @@ -95,7 +95,7 @@ private string GetOrdinalUnit(int number, bool useExceptions)
return OrdinalUnitsMap[number];
}

private string ToOrdinal(int number, bool useExceptions)
private static string ToOrdinal(int number, bool useExceptions)
{
if (number == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ private string Part(string pluralFormat, string singular, long number)
return string.Format(pluralFormat, Convert(number));
}

private int NoRestIndex(int number) =>
private static int NoRestIndex(int number) =>
number == 0 ? 0 : 1;

private string GetEndingForGender(GrammaticalGender gender)
private static string GetEndingForGender(GrammaticalGender gender)
{
switch (gender)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,17 @@ public override string ConvertToOrdinal(int number)
return string.Empty;
}

private string GetOneDigitOrdinal(int number)
private static string GetOneDigitOrdinal(int number)
{
if (!ΟrdinalMap.TryGetValue(number, out var output)) return string.Empty;
if (ΟrdinalMap.TryGetValue(number, out var output))
{
return output;
}

return output;
return string.Empty;
}

private string GetTwoDigitOrdinal(int number)
private static string GetTwoDigitOrdinal(int number)
{
if (number == 11) return "ενδέκατος";
if (number == 12) return "δωδέκατος";
Expand All @@ -100,26 +103,26 @@ private string GetTwoDigitOrdinal(int number)
return decadesString;
}

private string GetThreeDigitOrdinal(int number)
private static string GetThreeDigitOrdinal(int number)
{
var hundrends = number / 100;
var hundreds = number / 100;

if (!ΟrdinalMap.TryGetValue(hundrends*100, out var hundrentsString)) return string.Empty;
if (!ΟrdinalMap.TryGetValue(hundreds*100, out var hundredsString)) return string.Empty;

if (number - hundrends*100> 10)
if (number - hundreds*100> 10)
{
return hundrentsString + " " + GetTwoDigitOrdinal(number - hundrends*100);
return hundredsString + " " + GetTwoDigitOrdinal(number - hundreds*100);
}

if(number - hundrends * 100 > 0)
if(number - hundreds * 100 > 0)
{
return hundrentsString + " " + GetOneDigitOrdinal(number - hundrends*100);
return hundredsString + " " + GetOneDigitOrdinal(number - hundreds*100);
}

return hundrentsString;
return hundredsString;
}

private string GetFourDigitOrdinal(int number)
private static string GetFourDigitOrdinal(int number)
{
var thousands = number / 1000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override string ConvertToOrdinal(int number)
return result;
}

public string NumberToText( long number)
public static string NumberToText( long number)
{
if (number < 0)
return "(Negative) " + NumberToText(-number);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override string Convert(long number) =>
public override string ConvertToOrdinal(int number) =>
ConvertImpl(number, true);

private string ConvertImpl(long number, bool isOrdinal)
private static string ConvertImpl(long number, bool isOrdinal)
{
if (number == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override string Convert(long number) =>
public override string ConvertToOrdinal(int number) =>
ConvertImpl(number, true);

private string ConvertImpl(long number, bool isOrdinal)
private static string ConvertImpl(long number, bool isOrdinal)
{
if (isOrdinal && number < 20)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public string Convert(int number, GrammaticalGender gender)
/// </summary>
/// <param name="number">The number to split.</param>
/// <returns>The sequence of three-digit numbers.</returns>
private List<int> SplitEveryThreeDigits(int number)
private static List<int> SplitEveryThreeDigits(int number)
{
var parts = new List<int>();
var rest = number;
Expand Down Expand Up @@ -223,25 +223,25 @@ private string ThreeDigitSetConverter(int number, GrammaticalGender gender, bool
if (tensAndUnits <= 9)
{
// simple case for units, under 10
words += " " + getPartByGender(_units[tensAndUnits], gender);
words += " " + GetPartByGender(_units[tensAndUnits], gender);
}
else if (tensAndUnits <= 19)
{
// special case for 'teens', from 10 to 19
words += " " + getPartByGender(_teensUnder20NumberToText[tensAndUnits - 10], gender);
words += " " + GetPartByGender(_teensUnder20NumberToText[tensAndUnits - 10], gender);
}
else
{
// exception for zero
var unitsText = (units == 0 ? string.Empty : " " + (_joinGroups + " " + getPartByGender(_units[units], gender)));
var unitsText = (units == 0 ? string.Empty : " " + (_joinGroups + " " + GetPartByGender(_units[units], gender)));

words += unitsText;
}

return words;
}

private string getPartByGender(string multiGenderPart, GrammaticalGender gender)
private static string GetPartByGender(string multiGenderPart, GrammaticalGender gender)
{
if (multiGenderPart.Contains("|"))
{
Expand All @@ -266,8 +266,8 @@ private string getPartByGender(string multiGenderPart, GrammaticalGender gender)
}
}

private bool IsAbove20(int number) =>
(number >= 20);
private static bool IsAbove20(int number) =>
number >= 20;

private string HundredsToText(int hundreds)
{
Expand All @@ -281,7 +281,7 @@ private string HundredsToText(int hundreds)
}
else
{
return getPartByGender(_units[hundreds], GrammaticalGender.Feminine) + " sute";
return GetPartByGender(_units[hundreds], GrammaticalGender.Feminine) + " sute";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public string Convert(int number, GrammaticalGender gender)
else if (number == 1)
{
// no prefixes for primul/prima
return this.getPartByGender(_ordinalsUnder10[number], gender);
return GetPartByGender(_ordinalsUnder10[number], gender);
}
else if (number <= 9)
{
// units ordinals, 2 to 9, are totally different than the rest: treat them as a distinct case
return string.Format("{0} {1}",
gender == GrammaticalGender.Feminine ? _femininePrefix : _masculinePrefix,
this.getPartByGender(_ordinalsUnder10[number], gender)
GetPartByGender(_ordinalsUnder10[number], gender)
);
}
else
Expand Down Expand Up @@ -111,7 +111,7 @@ public string Convert(int number, GrammaticalGender gender)
}
}

private string getPartByGender(string multiGenderPart, GrammaticalGender gender)
private static string GetPartByGender(string multiGenderPart, GrammaticalGender gender)
{
if (multiGenderPart.Contains("|"))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public override string Convert(long input)
return Convert(number, true);
}

private string Convert(int number, bool checkForHoundredRule)
private static string Convert(int number, bool checkForHundredRule)
{
if (number == 0)
{
return UnitsMap[0];
}

if (checkForHoundredRule && number == 100)
if (checkForHundredRule && number == 100)
{
return "юз";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public override string Convert(long input)
return Convert(number, true);
}

private string Convert(int number, bool checkForHoundredRule)
private static string Convert(int number, bool checkForHundredRule)
{
if (number == 0)
{
return UnitsMap[0];
}

if (checkForHoundredRule && number == 100)
if (checkForHundredRule && number == 100)
{
return "yuz";
}
Expand Down

0 comments on commit 65e261f

Please sign in to comment.