Conditions | 11 |
Paths | 38 |
Total Lines | 70 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
48 | public function buildScripts(array $index): array |
||
49 | { |
||
50 | /** @var RangeSet[] $ranges */ |
||
51 | $ranges = []; |
||
52 | $source = new SplFileObject(__DIR__ . '/../../data/Scripts.txt'); |
||
53 | $lastKnownCode = null; |
||
54 | $unknownRanges = []; |
||
55 | |||
56 | echo "Parsing: "; |
||
57 | $rangeCount = 0; |
||
58 | |||
59 | while (!$source->eof()) { |
||
60 | $line = $source->fgets(); |
||
61 | if (false === $line) { |
||
62 | throw new RuntimeException("Error reading line from scripts file"); |
||
63 | } |
||
64 | $dataWithComment = explode('#', $line, 2); |
||
65 | $data = trim($dataWithComment[0] ?? ''); |
||
66 | if ('' == $data) { |
||
67 | continue; |
||
68 | } |
||
69 | $rangeWithProp = explode(';', $data); |
||
70 | $unsplittedRange = trim($rangeWithProp[0] ?? null); |
||
71 | $prop = trim($rangeWithProp[1] ?? null); |
||
72 | if (!isset($unsplittedRange, $prop)) { |
||
73 | throw new RuntimeException("Invalid range or property"); |
||
74 | } |
||
75 | $splittedRange = explode('..', $unsplittedRange); |
||
76 | $start = hexdec($splittedRange[0]); |
||
77 | $finish = isset($splittedRange[1]) |
||
78 | ? hexdec($splittedRange[1]) |
||
79 | : $start; |
||
80 | if (!isset($lastKnownCode)) { |
||
81 | if ($start > 0) { |
||
82 | $unknownRanges[] = new Range(0, $start - 1); |
||
|
|||
83 | } |
||
84 | } elseif ($start - $lastKnownCode > 1) { |
||
85 | $unknownRanges[] = new Range($lastKnownCode + 1, $start - 1); |
||
86 | } |
||
87 | $lastKnownCode = $finish; |
||
88 | |||
89 | if (!isset($ranges[$prop])) { |
||
90 | $ranges[$prop] = []; |
||
91 | } |
||
92 | $range = new Range($start, $finish); |
||
93 | $ranges[$prop][] = $range; |
||
94 | echo "."; |
||
95 | $rangeCount++; |
||
96 | } |
||
97 | $ranges['Unknown'] = $unknownRanges; |
||
98 | echo ". {$rangeCount} ranges\n"; |
||
99 | $source = null; |
||
100 | |||
101 | echo "Building range sets: "; |
||
102 | $rangeSetCount = 0; |
||
103 | $rangeSets = []; |
||
104 | foreach ($ranges as $prop => $rangeList) { |
||
105 | $rangeSets[$prop] = new RangeSet(...$rangeList); |
||
106 | echo "."; |
||
107 | $rangeSetCount++; |
||
108 | } |
||
109 | echo " {$rangeSetCount} range sets\n"; |
||
110 | |||
111 | /*echo "Build Unknown property..."; |
||
112 | $fullRangeSet = new RangeSet(new Range(0x0, 0x10FFFF)); |
||
113 | $knownRangeSet = new RangeSet(...$knownRanges); |
||
114 | $unknownRangeSet = $rangeSetCalc->xor($fullRangeSet, $knownRangeSet); |
||
115 | $ranges['Unknown'] = $unknownRangeSet;*/ |
||
116 | |||
117 | return $this->dumpProps($index, $rangeSets); |
||
118 | } |
||
173 |