Passed
Push — master ( a0935b...32dfa0 )
by Vítězslav
02:09
created

Adresar::getAnyPhoneNumber()   C

Complexity

Conditions 12
Paths 33

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 29
rs 6.9666
c 0
b 0
f 0
cc 12
nc 33
nop 0

How to fix   Complexity   

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
 * FlexiPeeHP - Objekt adresáře.
4
 *
5
 * @author     Vítězslav Dvořák <[email protected]>
6
 * @copyright  (C) 2015-2017 Spoje.Net
7
 */
8
9
namespace FlexiPeeHP;
10
11
/**
12
 * Adresář
13
 *
14
 * @link https://demo.flexibee.eu/c/demo/adresar/properties položky evidence
15
 */
16
class Adresar extends FlexiBeeRW
17
{
18
    /**
19
     * Evidence užitá objektem.
20
     *
21
     * @var string
22
     */
23
    public $evidence = 'adresar';
24
25
    /**
26
     * get Email address for Customer with primary contact prefered
27
     * 
28
     * @return string email of primary contact or address email or null
29
     */
30
    public function getNotificationEmailAddress()
31
    {
32
        $email     = null;
33
        $emailsRaw = $this->getFlexiData($this->getApiURL(),
34
            ['detail' => 'custom:id,email,kontakty(primarni,email)', 'relations' => 'kontakty']);
35
        if (is_array($emailsRaw)) {
0 ignored issues
show
introduced by
The condition is_array($emailsRaw) is always true.
Loading history...
36
            $emails = $emailsRaw[0];
37
            if (array_key_exists('email', $emails) && strlen(trim($emails['email']))) {
38
                $email = $emails['email'];
39
            }
40
            if (array_key_exists('kontakty', $emails) && !empty($emails['kontakty'])) {
41
                foreach ($emails['kontakty'] as $kontakt) {
42
                    if (($kontakt['primarni'] == 'true') && strlen(trim($kontakt['email']))) {
43
                        $email = $kontakt['email'];
44
                        break;
45
                    }
46
                }
47
            }
48
        }
49
        return $email;
50
    }
51
52
    /**
53
     * get cell phone Number for Customer with primary contact prefered
54
     * 
55
     * @return string cell phone number of primary contact or address cell number or null
56
     */
57
    public function getCellPhoneNumber()
58
    {
59
        $mobil     = null;
60
        $mobilsRaw = $this->getFlexiData($this->getApiURL(),
61
            ['detail' => 'custom:id,mobil,kontakty(primarni,mobil)', 'relations' => 'kontakty']);
62
        if (is_array($mobilsRaw)) {
0 ignored issues
show
introduced by
The condition is_array($mobilsRaw) is always true.
Loading history...
63
            $mobils = $mobilsRaw[0];
64
            if (array_key_exists('mobil', $mobils) && strlen(trim($mobils['mobil']))) {
65
                $mobil = $mobils['mobil'];
66
            }
67
            if (array_key_exists('kontakty', $mobils) && !empty($mobils['kontakty'])) {
68
                foreach ($mobils['kontakty'] as $kontakt) {
69
                    if (($kontakt['primarni'] == 'true') && strlen(trim($kontakt['mobil']))) {
70
                        $mobil = $kontakt['mobil'];
71
                        break;
72
                    }
73
                }
74
            }
75
        }
76
        return $mobil;
77
    }
78
    
79
    /**
80
     * get any phone Number for Customer with primary contact prefered
81
     * 
82
     * @return string phone number of primary contact or address's phone number or null
83
     */
84
    public function getAnyPhoneNumber()
85
    {
86
        $phoneNo    = null;
87
        $numbersRaw = $this->getFlexiData($this->getApiURL(),
88
            ['detail' => 'custom:id,mobil,tel,kontakty(primarni,mobil,tel)', 'relations' => 'kontakty']);
89
        if (is_array($numbersRaw)) {
0 ignored issues
show
introduced by
The condition is_array($numbersRaw) is always true.
Loading history...
90
            $numbers = $numbersRaw[0];
91
            if (array_key_exists('mobil', $numbers) && strlen(trim($numbers['mobil']))) {
92
                $phoneNo = $numbers['mobil'];
93
            }
94
            if (array_key_exists('tel', $numbers) && strlen(trim($numbers['tel']))) {
95
                $phoneNo = $numbers['tel'];
96
            }
97
            if (array_key_exists('kontakty', $numbers) && !empty($numbers['kontakty'])) {
98
                foreach ($numbers['kontakty'] as $kontakt) {
99
                    if ($kontakt['primarni'] == 'true') {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
100
                        
101
                    }
102
                    if (strlen(trim($kontakt['mobil']))) {
103
                        $phoneNo = $kontakt['mobil'];
104
                        break;
105
                    } elseif (strlen(trim($kontakt['mobil']))) {
106
                        $phoneNo = $kontakt['mobil'];
107
                        break;
108
                    }
109
                }
110
            }
111
        }
112
        return $phoneNo;
113
    }
114
}
115