Passed
Push — main ( 9152fd...203f91 )
by N.
03:37
created

Kod::visa_kodinformation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 60
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 27
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 27
nc 2
nop 7
dl 0
loc 60
ccs 27
cts 27
cp 1
crap 2
rs 9.488
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
/**
4
 * Egenskap Kod.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Egenskaper;
11
12
/**
13
 * Egenskap Kod.
14
 * Information för vissa täckningskoder (BCH-koder för topptipset)
15
 */
16
trait Kod {
17
	use KodMatris;
18
19
	/**
20
	 * Visa generell information om kod.
21
	 * @param array<int, int[]> $generatormatris
22
	 * @param array<int, int[]> $kontrollmatris
23
	 * @param array<int, int[]> $matris
24
	 * @param int[] $bch
25
	 * @param string[] $text
26
	 */
27 1
	private function visa_kodinformation(
28
		array $generatormatris,
29
		array $kontrollmatris,
30
		array $matris,
31
		array $bch, // [n, b, d, F]
32
		int $tab, // indrag
33
		array $text,
34
		string $vektordistribution = ''
35
	): string {
36
37
		/**
38
		 * Exponent och index.
39
		 */
40 1
		$bch_bi = n_index($bch[3]); // 𝔽₃
41 1
		$bch_ke = n_exponent($bch[1]); // 3⁶
42
43
		/**
44
		 * Karakteristik.
45
		 */
46 1
		$redundans = $bch[0] - $bch[1];
47 1
		$volym = number_format($volym_s = pow($bch[3], $bch[1]), 0, ',', ' ');
48 1
		$rymd = number_format($rum = pow($bch[3], $bch[0]), 0, ',', ' ');
49 1
		$reduktion = number_format(fdiv($rum, $volym_s), 0, ',', ' ');
50
51
		/**
52
		 * Sammanställ data.
53
		 */
54 1
		$kodinformation = <<< EOT
55 1
<h2>$text[0]:</h2>
56 1
<p class="större">$text[2]<br>
57 1
	{$text[3]} [{$bch[0]}, {$bch[1]}, {$bch[2]}]$bch_bi{$text[4]} över 𝔽$bch_bi<br>
58 1
	M = {$bch[3]}$bch_ke = $volym; <span class="vinst10">R = {$text[1]}</span><br>
59 1
	n = {$bch[0]}; k = {$bch[1]}; d = {$bch[2]}; redundans = $redundans<br>
60 1
	Rymd: $rymd; reduktion: $reduktion<br>
61 1
	GAP/Guava: <code>{$text[5]}</code></p>
62 1
EOT;
63
64
		/**
65
		 * Indrag med tab
66
		 */
67 1
		$info = '';
68 1
		foreach (explode("\n", $kodinformation) as $t) {
69 1
			$info .= t($tab, $t);
70
		}
71 1
		$info = rtrim($info);
72
73
		/**
74
		 * Viktdistribution.
75
		 */
76 1
		$viktdistribution = rtrim(t($tab, "<p>Viktdistribution: $vektordistribution</p>"));
77
78
		/**
79
		 * Leverera text.
80
		 */
81 1
		return <<< EOT
82 1
$info
83 1
{$this->matris_till_mathml($generatormatris, 'G', $tab)}
84 1
{$this->matris_till_mathml($kontrollmatris, 'H', $tab)}
85 1
{$this->matris_till_mathml($matris, 'K', $tab)}
86 1
$viktdistribution
87 1
EOT;
88
	}
89
}
90