ArraysDB   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 83.87%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 52
ccs 26
cts 31
cp 0.8387
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init_db() 0 7 2
B get_array() 0 33 9
1
<?php
2
3
    namespace NokitaKaze\OrthogonalArrays;
4
5
    abstract class ArraysDB {
6
        private static $_db = null;
7
8 54
        private static function init_db() {
9 54
            if (!is_null(self::$_db)) {
10 48
                return;
11
            }
12
13 6
            self::$_db = unserialize(file_get_contents(__DIR__.'/precomputed.dat'));
14 6
        }
15
16
        /**
17
         * @param integer[] $geometry
18
         *
19
         * @return integer[][]|null
20
         * @throws OrthogonalArraysException
21
         */
22 54
        public static function get_array($geometry) {
23 54
            self::init_db();
24 54
            $count = count($geometry);
25 54
            if (!isset(self::$_db[$count])) {
26
                return null;
27
            }
28
29 54
            $hash = implode('-', $geometry);
30 54
            if (!isset(self::$_db[$count][$hash])) {
31
                return null;
32
            }
33
34 54
            $indexes = explode(',', self::$_db[$count][$hash]);
35 54
            $pairs = [];
36 54
            foreach ($indexes as $s) {
37 54
                $value = [];
38 54
                while (!empty($s)) {
39 54
                    $c = substr($s, 0, 1);
40 54
                    $s = substr($s, 1);
41 54
                    $ord = ord($c);
42 54
                    if (($ord >= ord('a')) and ($ord <= ord('z'))) {
43 54
                        $value[] = $ord - ord('a');
44 18
                    } elseif (($ord >= ord('A')) and ($ord <= ord('Z'))) {
45
                        $value[] = $ord - ord('A') + 26;
46
                    } else {
47
                        throw new OrthogonalArraysException();
48
                    }
49 18
                }
50 54
                $pairs[] = $value;
51 18
            }
52
53 54
            return $pairs;
54
        }
55
56
    }
57
58
?>