ArticleUtil   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 57
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A convertPrice() 0 6 1
A getKeyValueArray() 0 6 1
A convertOrderNumber() 0 4 1
B getMainOrderNumber() 0 13 5
1
<?php
2
3
namespace TEiling\Scd16\Utils;
4
5
class ArticleUtil
6
{
7
    /**
8
     * @param $price
9
     *
10
     * @return float
11
     */
12
    public static function convertPrice($price)
13
    {
14
        $fmt = numfmt_create('de_DE', \NumberFormatter::DECIMAL);
15
16
        return numfmt_parse($fmt, $price);
17
    }
18
19
    /**
20
     * @param $string
21
     *
22
     * @return array
23
     */
24
    public static function getKeyValueArray($string)
25
    {
26
        $chunks = array_chunk(preg_split('/(=|,)/', $string), 2);
27
28
        return array_combine(array_column($chunks, 0), array_column($chunks, 1));
29
    }
30
31
    /**
32
     * @param string $orderNumber
33
     *
34
     * @return string
35
     */
36
    public static function convertOrderNumber($orderNumber)
37
    {
38
        return str_replace(['½', '/'], ['.5', '-'], $orderNumber);
39
    }
40
41
42
    /**
43
     * @param string $orderNumber
44
     * @param mixed $stock
45
     *
46
     * @return bool|string
47
     */
48
    public static function getMainOrderNumber($orderNumber, $stock)
49
    {
50
        $stockArray = self::getKeyValueArray($stock);
51
        foreach ($stockArray as $key => $value) {
52
            if ($value > 0 && $key !== '-') {
53
                return self::convertOrderNumber($orderNumber . '-' . $key);
54
            } elseif ($key === '-') {
55
                return $orderNumber;
56
            }
57
        }
58
59
        return false;
60
    }
61
}
62