internal/openapi/generator/data/rangedTextGenerator.go   A
last analyzed

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
cc 10
eloc 33
dl 0
loc 55
ccs 27
cts 27
cp 1
crap 10
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C data.*rangedTextGenerator.generateRangedText 0 47 10
1
package data
2
3
import "syreclabs.com/go/faker"
4
5
type rangedTextGenerator struct {
6
	random randomGenerator
7
}
8
9
func (generator *rangedTextGenerator) generateRangedText(minLength int, maxLength int) string {
10 1
	if maxLength < 5 {
11 1
		return faker.RandomString(maxLength)
12
	}
13
14 1
	length := minLength
15 1
	if maxLength-minLength > 0 {
16 1
		length = generator.random.Intn(maxLength-minLength) + minLength
17
	}
18
19 1
	text := ""
20
21 1
	maxWordsCount := length / 10
22 1
	if maxWordsCount < 2 {
23 1
		maxWordsCount = 2
24 1
	} else if maxWordsCount > 9 {
25 1
		maxWordsCount = 9
26
	}
27
28 1
	for {
29 1
		wordsCount := generator.random.Intn(maxWordsCount) + 1
30 1
		sentence := faker.Lorem().Sentence(wordsCount)
31
32 1
		var extendedText string
33 1
		if len(text) == 0 {
34 1
			extendedText = sentence
35
		} else {
36 1
			extendedText = text + " " + sentence
37
		}
38
39 1
		if len(extendedText) >= length {
40 1
			if len(extendedText) >= maxLength {
41 1
				break
42
			}
43
44 1
			text = extendedText
45 1
			break
46
		}
47
48 1
		text = extendedText
49
	}
50
51 1
	if len(text) < minLength {
52 1
		text = faker.RandomString(minLength)
53
	}
54
55 1
	return text
56
}
57